♻️ Rename types for Mixed and Typed components

This commit is contained in:
Manuel Cillero 2024-03-07 21:27:36 +01:00
parent 57e71a9399
commit c65ac74a6f
20 changed files with 151 additions and 154 deletions

View file

@ -8,7 +8,7 @@ pub struct Block {
renderable: Renderable,
classes : OptionClasses,
title : OptionTranslated,
stuff : MixedComponents,
mixed : MixedComponents,
}
impl ComponentTrait for Block {
@ -78,13 +78,13 @@ impl Block {
#[rustfmt::skip]
pub fn add_component(mut self, component: impl ComponentTrait) -> Self {
self.stuff.alter_value(OneOp::Add(OneComponent::with(component)));
self.mixed.alter_value(MixedOp::Add(AnyComponent::with(component)));
self
}
#[fn_builder]
pub fn alter_components(&mut self, op: OneOp) -> &mut Self {
self.stuff.alter_value(op);
pub fn alter_components(&mut self, op: MixedOp) -> &mut Self {
self.mixed.alter_value(op);
self
}
@ -95,6 +95,6 @@ impl Block {
}
pub fn components(&self) -> &MixedComponents {
&self.stuff
&self.mixed
}
}

View file

@ -7,7 +7,7 @@ pub struct Container {
weight : Weight,
renderable : Renderable,
classes : OptionClasses,
items : VectorComponents<flex::Item>,
items : TypedComponents<flex::Item>,
direction : flex::Direction,
wrap_align : flex::WrapAlign,
content_justify: flex::ContentJustify,
@ -84,7 +84,7 @@ impl Container {
#[rustfmt::skip]
pub fn add_item(mut self, item: flex::Item) -> Self {
self.items.alter_value(TypedOp::Add(TypedComponent::with(item)));
self.items.alter_value(TypedOp::Add(OneComponent::with(item)));
self
}
@ -126,7 +126,7 @@ impl Container {
// Container GETTERS.
pub fn items(&self) -> &VectorComponents<flex::Item> {
pub fn items(&self) -> &TypedComponents<flex::Item> {
&self.items
}

View file

@ -12,7 +12,7 @@ pub struct Item {
item_size : flex::ItemSize,
item_offset : flex::ItemOffset,
item_align : flex::ItemAlign,
stuff : MixedComponents,
mixed : MixedComponents,
}
impl ComponentTrait for Item {
@ -63,6 +63,10 @@ impl ComponentTrait for Item {
}
impl Item {
pub fn with(component: impl ComponentTrait) -> Self {
Item::default().add_component(component)
}
// Item BUILDER.
#[fn_builder]
@ -115,13 +119,13 @@ impl Item {
#[rustfmt::skip]
pub fn add_component(mut self, component: impl ComponentTrait) -> Self {
self.stuff.alter_value(OneOp::Add(OneComponent::with(component)));
self.mixed.alter_value(MixedOp::Add(AnyComponent::with(component)));
self
}
#[fn_builder]
pub fn alter_components(&mut self, op: OneOp) -> &mut Self {
self.stuff.alter_value(op);
pub fn alter_components(&mut self, op: MixedOp) -> &mut Self {
self.mixed.alter_value(op);
self
}
@ -148,6 +152,6 @@ impl Item {
}
pub fn components(&self) -> &MixedComponents {
&self.stuff
&self.mixed
}
}

View file

@ -17,7 +17,7 @@ pub struct Form {
action : OptionString,
charset : OptionString,
method : FormMethod,
stuff : MixedComponents,
mixed : MixedComponents,
}
impl ComponentTrait for Form {
@ -99,13 +99,13 @@ impl Form {
#[rustfmt::skip]
pub fn add_element(mut self, element: impl ComponentTrait) -> Self {
self.stuff.alter_value(OneOp::Add(OneComponent::with(element)));
self.mixed.alter_value(MixedOp::Add(AnyComponent::with(element)));
self
}
#[fn_builder]
pub fn alter_elements(&mut self, op: OneOp) -> &mut Self {
self.stuff.alter_value(op);
pub fn alter_elements(&mut self, op: MixedOp) -> &mut Self {
self.mixed.alter_value(op);
self
}
@ -124,6 +124,6 @@ impl Form {
}
pub fn elements(&self) -> &MixedComponents {
&self.stuff
&self.mixed
}
}

View file

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

View file

@ -8,7 +8,7 @@ pub struct Group {
id : OptionId,
weight : Weight,
renderable: Renderable,
elements : VectorComponents<Element>,
elements : TypedComponents<Element>,
}
impl ComponentTrait for Group {
@ -60,7 +60,7 @@ impl Group {
#[rustfmt::skip]
pub fn add_element(mut self, element: Element) -> Self {
self.elements.alter_value(TypedOp::Add(TypedComponent::with(element)));
self.elements.alter_value(TypedOp::Add(OneComponent::with(element)));
self
}
@ -72,7 +72,7 @@ impl Group {
// Group GETTERS.
pub fn elements(&self) -> &VectorComponents<Element> {
pub fn elements(&self) -> &TypedComponents<Element> {
&self.elements
}
}

View file

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

View file

@ -8,7 +8,7 @@ pub struct Megamenu {
id : OptionId,
weight : Weight,
renderable: Renderable,
groups : VectorComponents<Group>,
groups : TypedComponents<Group>,
}
impl ComponentTrait for Megamenu {
@ -60,7 +60,7 @@ impl Megamenu {
#[rustfmt::skip]
pub fn add_group(mut self, group: Group) -> Self {
self.groups.alter_value(TypedOp::Add(TypedComponent::with(group)));
self.groups.alter_value(TypedOp::Add(OneComponent::with(group)));
self
}
@ -72,7 +72,7 @@ impl Megamenu {
// Megamenu GETTERS.
pub fn groups(&self) -> &VectorComponents<Group> {
pub fn groups(&self) -> &TypedComponents<Group> {
&self.groups
}
}

View file

@ -8,7 +8,7 @@ pub struct Menu {
id : OptionId,
weight : Weight,
renderable: Renderable,
items : VectorComponents<Item>,
items : TypedComponents<Item>,
}
impl ComponentTrait for Menu {
@ -88,7 +88,7 @@ impl Menu {
#[rustfmt::skip]
pub fn add_item(mut self, item: Item) -> Self {
self.items.alter_value(TypedOp::Add(TypedComponent::with(item)));
self.items.alter_value(TypedOp::Add(OneComponent::with(item)));
self
}
@ -100,7 +100,7 @@ impl Menu {
// Menu GETTERS.
pub fn items(&self) -> &VectorComponents<Item> {
pub fn items(&self) -> &TypedComponents<Item> {
&self.items
}
}

View file

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

View file

@ -8,7 +8,7 @@ pub struct Paragraph {
renderable: Renderable,
classes : OptionClasses,
font_size : FontSize,
stuff : MixedComponents,
mixed : MixedComponents,
}
impl ComponentTrait for Paragraph {
@ -49,8 +49,8 @@ impl Paragraph {
Paragraph::default().add_component(component)
}
pub fn translated(l10n: L10n) -> Self {
Paragraph::default().add_translated(l10n)
pub fn fluent(l10n: L10n) -> Self {
Paragraph::default().add_component(Fluent::with(l10n))
}
// Paragraph BUILDER.
@ -81,19 +81,13 @@ impl Paragraph {
#[rustfmt::skip]
pub fn add_component(mut self, component: impl ComponentTrait) -> Self {
self.stuff.alter_value(OneOp::Add(OneComponent::with(component)));
self
}
#[rustfmt::skip]
pub fn add_translated(mut self, l10n: L10n) -> Self {
self.stuff.alter_value(OneOp::Add(OneComponent::with(Translate::with(l10n))));
self.mixed.alter_value(MixedOp::Add(AnyComponent::with(component)));
self
}
#[fn_builder]
pub fn alter_components(&mut self, op: OneOp) -> &mut Self {
self.stuff.alter_value(op);
pub fn alter_components(&mut self, op: MixedOp) -> &mut Self {
self.mixed.alter_value(op);
self
}
@ -104,6 +98,6 @@ impl Paragraph {
}
pub fn components(&self) -> &MixedComponents {
&self.stuff
&self.mixed
}
}

View file

@ -13,12 +13,12 @@ pub enum WrapperType {
#[rustfmt::skip]
#[derive(AutoDefault, ComponentClasses)]
pub struct Wrapper {
id : OptionId,
weight : Weight,
renderable : Renderable,
classes : OptionClasses,
wrapper_type : WrapperType,
stuff : MixedComponents,
id : OptionId,
weight : Weight,
renderable : Renderable,
classes : OptionClasses,
wrapper_type: WrapperType,
mixed : MixedComponents,
}
impl ComponentTrait for Wrapper {
@ -126,13 +126,13 @@ impl Wrapper {
#[rustfmt::skip]
pub fn add_component(mut self, component: impl ComponentTrait) -> Self {
self.stuff.alter_value(OneOp::Add(OneComponent::with(component)));
self.mixed.alter_value(MixedOp::Add(AnyComponent::with(component)));
self
}
#[fn_builder]
pub fn alter_components(&mut self, op: OneOp) -> &mut Self {
self.stuff.alter_value(op);
pub fn alter_components(&mut self, op: MixedOp) -> &mut Self {
self.mixed.alter_value(op);
self
}
@ -143,6 +143,6 @@ impl Wrapper {
}
pub fn components(&self) -> &MixedComponents {
&self.stuff
&self.mixed
}
}