🚧 Working on theming: anchor and icon font sizes

This commit is contained in:
Manuel Cillero 2023-11-01 21:16:29 +01:00
parent a6b6130f4f
commit 556a160c16
6 changed files with 216 additions and 111 deletions

View file

@ -10,6 +10,16 @@ pub enum AnchorType {
Location,
}
#[rustfmt::skip]
impl ToString for AnchorType {
fn to_string(&self) -> String {
match self {
AnchorType::Button => "btn btn-primary".to_string(),
_ => "".to_string(),
}
}
}
#[derive(Default)]
pub enum AnchorTarget {
#[default]
@ -29,13 +39,13 @@ pub struct Anchor {
renderable : Renderable,
id : OptionId,
classes : OptionClasses,
font_size : FontSize,
anchor_type: AnchorType,
href : OptionString,
html : OptionTranslated,
left_icon : AnchorIcon,
right_icon : AnchorIcon,
target : AnchorTarget,
template : String,
}
impl ComponentTrait for Anchor {
@ -125,14 +135,21 @@ impl Anchor {
self
}
#[fn_builder]
pub fn alter_font_size(&mut self, font_size: FontSize) -> &mut Self {
self.classes.alter_value(
ClassesOp::Replace(self.font_size.to_string()),
font_size.to_string(),
);
self.font_size = font_size;
self
}
#[fn_builder]
pub fn alter_type(&mut self, anchor_type: AnchorType) -> &mut Self {
self.alter_classes(
ClassesOp::SetDefault,
match anchor_type {
AnchorType::Button => "btn btn-primary",
_ => "",
},
self.classes.alter_value(
ClassesOp::Replace(self.anchor_type.to_string()),
anchor_type.to_string(),
);
self.anchor_type = anchor_type;
self
@ -168,18 +185,16 @@ impl Anchor {
self
}
#[fn_builder]
pub fn alter_template(&mut self, template: &str) -> &mut Self {
self.template = template.to_owned();
self
}
// Anchor GETTERS.
pub fn classes(&self) -> &OptionClasses {
&self.classes
}
pub fn font_size(&self) -> &FontSize {
&self.font_size
}
pub fn anchor_type(&self) -> &AnchorType {
&self.anchor_type
}
@ -203,8 +218,4 @@ impl Anchor {
pub fn target(&self) -> &AnchorTarget {
&self.target
}
pub fn template(&self) -> &str {
self.template.as_str()
}
}

View file

@ -7,8 +7,9 @@ new_handle!(COMPONENT_BASE_ICON);
pub struct Icon {
weight : Weight,
renderable: Renderable,
icon_name : String,
classes : OptionClasses,
font_size : FontSize,
icon_name : String,
}
impl ComponentTrait for Icon {
@ -30,7 +31,7 @@ impl ComponentTrait for Icon {
fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup {
if self.icon_name().is_empty() {
return PrepareMarkup::None
return PrepareMarkup::None;
}
cx.set_param::<bool>(PARAM_BASE_INCLUDE_ICONS, true);
PrepareMarkup::With(html! { i class=[self.classes().get()] {} })
@ -56,6 +57,22 @@ impl Icon {
self
}
#[fn_builder]
pub fn alter_classes(&mut self, op: ClassesOp, classes: impl Into<String>) -> &mut Self {
self.classes.alter_value(op, classes);
self
}
#[fn_builder]
pub fn alter_font_size(&mut self, font_size: FontSize) -> &mut Self {
self.classes.alter_value(
ClassesOp::Replace(self.font_size.to_string()),
font_size.to_string(),
);
self.font_size = font_size;
self
}
#[fn_builder]
pub fn alter_icon_name(&mut self, name: &str) -> &mut Self {
self.alter_classes(ClassesOp::SetDefault, concat_string!("bi-", name));
@ -63,19 +80,17 @@ impl Icon {
self
}
#[fn_builder]
pub fn alter_classes(&mut self, op: ClassesOp, classes: impl Into<String>) -> &mut Self {
self.classes.alter_value(op, classes);
self
}
// Icon GETTERS.
pub fn icon_name(&self) -> &str {
self.icon_name.as_str()
}
pub fn classes(&self) -> &OptionClasses {
&self.classes
}
pub fn font_size(&self) -> &FontSize {
&self.font_size
}
pub fn icon_name(&self) -> &str {
self.icon_name.as_str()
}
}

View file

@ -9,8 +9,8 @@ pub struct Paragraph {
renderable: Renderable,
id : OptionId,
classes : OptionClasses,
stuff : ArcComponents,
font_size : FontSize,
stuff : ArcComponents,
}
impl ComponentTrait for Paragraph {
@ -81,6 +81,16 @@ impl Paragraph {
self
}
#[fn_builder]
pub fn alter_font_size(&mut self, font_size: FontSize) -> &mut Self {
self.classes.alter_value(
ClassesOp::Replace(self.font_size.to_string()),
font_size.to_string(),
);
self.font_size = font_size;
self
}
pub fn add_component(mut self, component: impl ComponentTrait) -> Self {
self.stuff.alter(ArcOp::Add(ArcComponent::with(component)));
self
@ -98,28 +108,17 @@ impl Paragraph {
self
}
#[rustfmt::skip]
#[fn_builder]
pub fn alter_font_size(&mut self, font_size: FontSize) -> &mut Self {
self.classes.alter_value(
ClassesOp::Replace(self.font_size.to_string()),
font_size.to_string(),
);
self.font_size = font_size;
self
}
// Paragraph GETTERS.
pub fn classes(&self) -> &OptionClasses {
&self.classes
}
pub fn components(&self) -> &ArcComponents {
&self.stuff
}
pub fn font_size(&self) -> &FontSize {
&self.font_size
}
pub fn components(&self) -> &ArcComponents {
&self.stuff
}
}