🧑‍💻 Simplify component vector handling

This commit is contained in:
Manuel Cillero 2024-03-16 21:41:04 +01:00
parent 400a492311
commit d7acf0c3d1
17 changed files with 154 additions and 221 deletions

View file

@ -90,14 +90,14 @@ impl Block {
}
#[fn_builder]
pub fn alter_components(&mut self, op: MixedOp) -> &mut Self {
pub fn alter_components(&mut self, op: AnyOp) -> &mut Self {
self.mixed.alter_value(op);
self
}
#[rustfmt::skip]
pub fn add_component(mut self, component: impl ComponentTrait) -> Self {
self.mixed.alter_value(MixedOp::Add(AnyComponent::with(component)));
self.mixed.alter_value(AnyOp::Add(AnyComponent::with(component)));
self
}

View file

@ -139,14 +139,14 @@ impl Item {
}
#[fn_builder]
pub fn alter_components(&mut self, op: MixedOp) -> &mut Self {
pub fn alter_components(&mut self, op: AnyOp) -> &mut Self {
self.mixed.alter_value(op);
self
}
#[rustfmt::skip]
pub fn add_component(mut self, component: impl ComponentTrait) -> Self {
self.mixed.alter_value(MixedOp::Add(AnyComponent::with(component)));
self.mixed.alter_value(AnyOp::Add(AnyComponent::with(component)));
self
}

View file

@ -97,15 +97,15 @@ impl Form {
self
}
#[rustfmt::skip]
pub fn add_element(mut self, element: impl ComponentTrait) -> Self {
self.mixed.alter_value(MixedOp::Add(AnyComponent::with(element)));
#[fn_builder]
pub fn alter_elements(&mut self, op: AnyOp) -> &mut Self {
self.mixed.alter_value(op);
self
}
#[fn_builder]
pub fn alter_elements(&mut self, op: MixedOp) -> &mut Self {
self.mixed.alter_value(op);
#[rustfmt::skip]
pub fn add_element(mut self, element: impl ComponentTrait) -> Self {
self.mixed.alter_value(AnyOp::Add(AnyComponent::with(element)));
self
}

View file

@ -2,8 +2,8 @@ use crate::prelude::*;
use super::Submenu;
type Content = OneComponent<Html>;
type SubmenuItems = OneComponent<Submenu>;
type Content = TypedComponent<Html>;
type SubmenuItems = TypedComponent<Submenu>;
#[derive(AutoDefault)]
pub enum ElementType {

View file

@ -8,7 +8,7 @@ pub struct Group {
id : OptionId,
weight : Weight,
renderable: Renderable,
elements : TypedComponents<Element>,
elements : MixedComponents,
}
impl ComponentTrait for Group {
@ -58,21 +58,21 @@ impl Group {
self
}
#[rustfmt::skip]
pub fn add_element(mut self, element: Element) -> Self {
self.elements.alter_value(TypedOp::Add(OneComponent::with(element)));
#[fn_builder]
pub fn alter_elements(&mut self, op: TypedOp<Element>) -> &mut Self {
self.elements.alter_typed(op);
self
}
#[fn_builder]
pub fn alter_elements(&mut self, op: TypedOp<Element>) -> &mut Self {
self.elements.alter_value(op);
#[rustfmt::skip]
pub fn add_element(mut self, element: Element) -> Self {
self.elements.alter_value(AnyOp::Add(AnyComponent::with(element)));
self
}
// Group GETTERS.
pub fn elements(&self) -> &TypedComponents<Element> {
pub fn elements(&self) -> &MixedComponents {
&self.elements
}
}

View file

@ -3,9 +3,9 @@ use crate::prelude::*;
use super::{Megamenu, Submenu};
type Label = L10n;
type Content = OneComponent<Html>;
type SubmenuItems = OneComponent<Submenu>;
type MegamenuGroups = OneComponent<Megamenu>;
type Content = TypedComponent<Html>;
type SubmenuItems = TypedComponent<Submenu>;
type MegamenuGroups = TypedComponent<Megamenu>;
#[derive(AutoDefault)]
pub enum ItemType {

View file

@ -8,7 +8,7 @@ pub struct Megamenu {
id : OptionId,
weight : Weight,
renderable: Renderable,
groups : TypedComponents<Group>,
groups : MixedComponents,
}
impl ComponentTrait for Megamenu {
@ -58,21 +58,21 @@ impl Megamenu {
self
}
#[rustfmt::skip]
pub fn add_group(mut self, group: Group) -> Self {
self.groups.alter_value(TypedOp::Add(OneComponent::with(group)));
#[fn_builder]
pub fn alter_groups(&mut self, op: TypedOp<Group>) -> &mut Self {
self.groups.alter_typed(op);
self
}
#[fn_builder]
pub fn alter_groups(&mut self, op: TypedOp<Group>) -> &mut Self {
self.groups.alter_value(op);
#[rustfmt::skip]
pub fn add_group(mut self, group: Group) -> Self {
self.groups.alter_value(AnyOp::Add(AnyComponent::with(group)));
self
}
// Megamenu GETTERS.
pub fn groups(&self) -> &TypedComponents<Group> {
pub fn groups(&self) -> &MixedComponents {
&self.groups
}
}

View file

@ -8,7 +8,7 @@ pub struct Menu {
id : OptionId,
weight : Weight,
renderable: Renderable,
items : TypedComponents<Item>,
items : MixedComponents,
}
impl ComponentTrait for Menu {
@ -86,21 +86,21 @@ impl Menu {
self
}
#[rustfmt::skip]
pub fn add_item(mut self, item: Item) -> Self {
self.items.alter_value(TypedOp::Add(OneComponent::with(item)));
#[fn_builder]
pub fn alter_items(&mut self, op: TypedOp<Item>) -> &mut Self {
self.items.alter_typed(op);
self
}
#[fn_builder]
pub fn alter_items(&mut self, op: TypedOp<Item>) -> &mut Self {
self.items.alter_value(op);
#[rustfmt::skip]
pub fn add_item(mut self, item: Item) -> Self {
self.items.alter_value(AnyOp::Add(AnyComponent::with(item)));
self
}
// Menu GETTERS.
pub fn items(&self) -> &TypedComponents<Item> {
pub fn items(&self) -> &MixedComponents {
&self.items
}
}

View file

@ -9,7 +9,7 @@ pub struct Submenu {
weight : Weight,
renderable: Renderable,
title : OptionTranslated,
items : TypedComponents<Item>,
items : MixedComponents,
}
impl ComponentTrait for Submenu {
@ -70,15 +70,15 @@ impl Submenu {
self
}
#[rustfmt::skip]
pub fn add_item(mut self, item: Item) -> Self {
self.items.alter_value(TypedOp::Add(OneComponent::with(item)));
#[fn_builder]
pub fn alter_items(&mut self, op: TypedOp<Item>) -> &mut Self {
self.items.alter_typed(op);
self
}
#[fn_builder]
pub fn alter_items(&mut self, op: TypedOp<Item>) -> &mut Self {
self.items.alter_value(op);
#[rustfmt::skip]
pub fn add_item(mut self, item: Item) -> Self {
self.items.alter_value(AnyOp::Add(AnyComponent::with(item)));
self
}
@ -88,7 +88,7 @@ impl Submenu {
&self.title
}
pub fn items(&self) -> &TypedComponents<Item> {
pub fn items(&self) -> &MixedComponents {
&self.items
}
}

View file

@ -80,14 +80,14 @@ impl Paragraph {
}
#[fn_builder]
pub fn alter_components(&mut self, op: MixedOp) -> &mut Self {
pub fn alter_components(&mut self, op: AnyOp) -> &mut Self {
self.mixed.alter_value(op);
self
}
#[rustfmt::skip]
pub fn add_component(mut self, component: impl ComponentTrait) -> Self {
self.mixed.alter_value(MixedOp::Add(AnyComponent::with(component)));
self.mixed.alter_value(AnyOp::Add(AnyComponent::with(component)));
self
}