💥 Standarize with() as constructor with arguments

This commit is contained in:
Manuel Cillero 2023-08-01 20:08:29 +02:00
parent baf683a278
commit dd93cfb9c8
6 changed files with 12 additions and 12 deletions

View file

@ -81,35 +81,35 @@ impl ComponentTrait for MegaItem {
impl MegaItem { impl MegaItem {
pub fn label(label: L10n) -> Self { pub fn label(label: L10n) -> Self {
MegaItem { MegaItem {
item_type: MegaItemType::Label(OneComponent::new_with(label)), item_type: MegaItemType::Label(Label::with(label)),
..Default::default() ..Default::default()
} }
} }
pub fn link(label: L10n, path: MegaItemPath) -> Self { pub fn link(label: L10n, path: MegaItemPath) -> Self {
MegaItem { MegaItem {
item_type: MegaItemType::Link(OneComponent::new_with(label), path), item_type: MegaItemType::Link(Label::with(label), path),
..Default::default() ..Default::default()
} }
} }
pub fn link_blank(label: L10n, path: MegaItemPath) -> Self { pub fn link_blank(label: L10n, path: MegaItemPath) -> Self {
MegaItem { MegaItem {
item_type: MegaItemType::LinkBlank(OneComponent::new_with(label), path), item_type: MegaItemType::LinkBlank(Label::with(label), path),
..Default::default() ..Default::default()
} }
} }
pub fn html(content: Html) -> Self { pub fn html(content: Html) -> Self {
MegaItem { MegaItem {
item_type: MegaItemType::Html(OneComponent::new_with(content)), item_type: MegaItemType::Html(Content::with(content)),
..Default::default() ..Default::default()
} }
} }
pub fn submenu(label: L10n, menu: MegaMenu) -> Self { pub fn submenu(label: L10n, menu: MegaMenu) -> Self {
MegaItem { MegaItem {
item_type: MegaItemType::Submenu(OneComponent::new_with(label), menu), item_type: MegaItemType::Submenu(Label::with(label), menu),
..Default::default() ..Default::default()
} }
} }

View file

@ -14,7 +14,7 @@ pub fn add_action(action: Action) {
if let Some(list) = actions.get_mut(&action_handle) { if let Some(list) = actions.get_mut(&action_handle) {
list.add(action); list.add(action);
} else { } else {
actions.insert(action_handle, ActionsList::new_with(action)); actions.insert(action_handle, ActionsList::with(action));
} }
} }

View file

@ -18,7 +18,7 @@ impl ActionsList {
ActionsList(Arc::new(RwLock::new(Vec::new()))) ActionsList(Arc::new(RwLock::new(Vec::new())))
} }
pub fn new_with(action: Action) -> Self { pub fn with(action: Action) -> Self {
let mut list = ActionsList::new(); let mut list = ActionsList::new();
list.add(action); list.add(action);
list list

View file

@ -11,7 +11,7 @@ impl<T: ComponentTrait + Default> OneComponent<T> {
OneComponent::<T>::default() OneComponent::<T>::default()
} }
pub fn new_with(component: T) -> Self { pub fn with(component: T) -> Self {
OneComponent(Some(Arc::new(RwLock::new(component)))) OneComponent(Some(Arc::new(RwLock::new(component))))
} }

View file

@ -47,7 +47,7 @@ impl PackComponents {
PackComponents::default() PackComponents::default()
} }
pub fn new_with(cref: ComponentRef) -> Self { pub fn with(cref: ComponentRef) -> Self {
let mut pack = PackComponents::new(); let mut pack = PackComponents::new();
pack.alter(PackOp::Add, cref); pack.alter(PackOp::Add, cref);
pack pack

View file

@ -19,7 +19,7 @@ impl ComponentsRegions {
ComponentsRegions::default() ComponentsRegions::default()
} }
pub fn new_with(region: &'static str, cref: ComponentRef) -> Self { pub fn with(region: &'static str, cref: ComponentRef) -> Self {
let mut regions = ComponentsRegions::new(); let mut regions = ComponentsRegions::new();
regions.add_in(region, cref); regions.add_in(region, cref);
regions regions
@ -29,7 +29,7 @@ impl ComponentsRegions {
if let Some(region) = self.0.get_mut(region) { if let Some(region) = self.0.get_mut(region) {
region.alter(PackOp::Add, cref); region.alter(PackOp::Add, cref);
} else { } else {
self.0.insert(region, PackComponents::new_with(cref)); self.0.insert(region, PackComponents::with(cref));
} }
} }
@ -58,7 +58,7 @@ pub fn add_component_in(region: Region, cref: ComponentRef) {
if let Some(hm) = regions.get_mut(&theme.handle()) { if let Some(hm) = regions.get_mut(&theme.handle()) {
hm.add_in(region, cref); hm.add_in(region, cref);
} else { } else {
regions.insert(theme.handle(), ComponentsRegions::new_with(region, cref)); regions.insert(theme.handle(), ComponentsRegions::with(region, cref));
} }
} }
} }