🚚 Rename HeadingDisplay to HeadingSize

This commit is contained in:
Manuel Cillero 2023-11-23 20:29:29 +01:00
parent 3fd05643b3
commit 9f25695298
5 changed files with 36 additions and 36 deletions

View file

@ -136,21 +136,21 @@ impl ThemeTrait for Bootsier {
} }
h if Heading::matches_handle(h) => { h if Heading::matches_handle(h) => {
if let Some(h) = component_as_mut::<Heading>(component) { if let Some(h) = component_as_mut::<Heading>(component) {
match h.display() { match h.size() {
HeadingDisplay::ExtraLarge => { HeadingSize::ExtraLarge => {
h.replace_classes(h.display().to_string(), "display-1"); h.replace_classes(h.size().to_string(), "display-1");
} }
HeadingDisplay::XxLarge => { HeadingSize::XxLarge => {
h.replace_classes(h.display().to_string(), "display-2"); h.replace_classes(h.size().to_string(), "display-2");
} }
HeadingDisplay::XLarge => { HeadingSize::XLarge => {
h.replace_classes(h.display().to_string(), "display-3"); h.replace_classes(h.size().to_string(), "display-3");
} }
HeadingDisplay::Large => { HeadingSize::Large => {
h.replace_classes(h.display().to_string(), "display-4"); h.replace_classes(h.size().to_string(), "display-4");
} }
HeadingDisplay::Medium => { HeadingSize::Medium => {
h.replace_classes(h.display().to_string(), "display-5"); h.replace_classes(h.size().to_string(), "display-5");
} }
_ => {} _ => {}
}; };

View file

@ -85,9 +85,9 @@ impl ThemeTrait for Bulmix {
} }
h if Heading::matches_handle(h) => { h if Heading::matches_handle(h) => {
if let Some(h) = component_as_mut::<Heading>(component) { if let Some(h) = component_as_mut::<Heading>(component) {
match h.display() { match h.size() {
HeadingDisplay::Subtitle => { HeadingSize::Subtitle => {
h.replace_classes(h.display().to_string(), "subtitle") h.replace_classes(h.size().to_string(), "subtitle")
} }
_ => h.add_classes("title"), _ => h.add_classes("title"),
}; };

View file

@ -47,7 +47,7 @@ fn hello_world() -> Wrapper {
.with_size(flex::ItemSize::Percent40) .with_size(flex::ItemSize::Percent40)
.add_component( .add_component(
Heading::h1(L10n::t("page_title", &LOCALES_HOMEDEMO)) Heading::h1(L10n::t("page_title", &LOCALES_HOMEDEMO))
.with_display(HeadingDisplay::Medium), .with_size(HeadingSize::Medium),
) )
.add_component( .add_component(
Paragraph::translated(L10n::t("hello_intro", &LOCALES_HOMEDEMO).with_arg( Paragraph::translated(L10n::t("hello_intro", &LOCALES_HOMEDEMO).with_arg(
@ -107,7 +107,7 @@ fn welcome() -> Wrapper {
&config::SETTINGS.app.name &config::SETTINGS.app.name
), ),
)) ))
.with_display(HeadingDisplay::Subtitle), .with_size(HeadingSize::Subtitle),
) )
.add_component( .add_component(
Paragraph::translated(L10n::t("welcome_text1", &LOCALES_HOMEDEMO)) Paragraph::translated(L10n::t("welcome_text1", &LOCALES_HOMEDEMO))

View file

@ -138,7 +138,7 @@ mod icon;
pub use icon::Icon; pub use icon::Icon;
mod heading; mod heading;
pub use heading::{Heading, HeadingDisplay, HeadingType}; pub use heading::{Heading, HeadingSize, HeadingType};
mod paragraph; mod paragraph;
pub use paragraph::Paragraph; pub use paragraph::Paragraph;

View file

@ -13,7 +13,7 @@ pub enum HeadingType {
} }
#[derive(SmartDefault)] #[derive(SmartDefault)]
pub enum HeadingDisplay { pub enum HeadingSize {
ExtraLarge, ExtraLarge,
XxLarge, XxLarge,
XLarge, XLarge,
@ -25,16 +25,16 @@ pub enum HeadingDisplay {
} }
#[rustfmt::skip] #[rustfmt::skip]
impl ToString for HeadingDisplay { impl ToString for HeadingSize {
fn to_string(&self) -> String { fn to_string(&self) -> String {
String::from(match self { String::from(match self {
HeadingDisplay::ExtraLarge => "pt-heading__title-x3l", HeadingSize::ExtraLarge => "pt-heading__title-x3l",
HeadingDisplay::XxLarge => "pt-heading__title-x2l", HeadingSize::XxLarge => "pt-heading__title-x2l",
HeadingDisplay::XLarge => "pt-heading__title-xl", HeadingSize::XLarge => "pt-heading__title-xl",
HeadingDisplay::Large => "pt-heading__title-l", HeadingSize::Large => "pt-heading__title-l",
HeadingDisplay::Medium => "pt-heading__title-m", HeadingSize::Medium => "pt-heading__title-m",
HeadingDisplay::Normal => "", HeadingSize::Normal => "",
HeadingDisplay::Subtitle => "pt-heading__subtitle", HeadingSize::Subtitle => "pt-heading__subtitle",
}) })
} }
} }
@ -47,8 +47,8 @@ pub struct Heading {
renderable : Renderable, renderable : Renderable,
classes : OptionClasses, classes : OptionClasses,
heading_type: HeadingType, heading_type: HeadingType,
size : HeadingSize,
text : OptionTranslated, text : OptionTranslated,
display : HeadingDisplay,
} }
impl ComponentTrait for Heading { impl ComponentTrait for Heading {
@ -69,7 +69,7 @@ impl ComponentTrait for Heading {
} }
fn setup_before_prepare(&mut self, _cx: &mut Context) { fn setup_before_prepare(&mut self, _cx: &mut Context) {
self.add_classes(self.display().to_string()); self.add_classes(self.size().to_string());
} }
fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup { fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup {
@ -151,14 +151,14 @@ impl Heading {
} }
#[fn_builder] #[fn_builder]
pub fn alter_text(&mut self, text: L10n) -> &mut Self { pub fn alter_size(&mut self, size: HeadingSize) -> &mut Self {
self.text.alter_value(text); self.size = size;
self self
} }
#[fn_builder] #[fn_builder]
pub fn alter_display(&mut self, display: HeadingDisplay) -> &mut Self { pub fn alter_text(&mut self, text: L10n) -> &mut Self {
self.display = display; self.text.alter_value(text);
self self
} }
@ -168,11 +168,11 @@ impl Heading {
&self.heading_type &self.heading_type
} }
pub fn size(&self) -> &HeadingSize {
&self.size
}
pub fn text(&self) -> &OptionTranslated { pub fn text(&self) -> &OptionTranslated {
&self.text &self.text
} }
pub fn display(&self) -> &HeadingDisplay {
&self.display
}
} }