From 743e32b0f6fb1ff0677a4d7407e1f1e5d334a1ee Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Thu, 7 Jul 2022 15:50:36 +0200 Subject: [PATCH] =?UTF-8?q?Mejora=20la=20asignaci=C3=B3n=20de=20m=C3=A1rge?= =?UTF-8?q?nes/espacios=20en=20comp.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pagetop/src/base/component/anchor.rs | 18 +- pagetop/src/base/component/grid/column.rs | 2 +- pagetop/src/base/component/grid/row.rs | 18 +- pagetop/src/base/component/icon.rs | 18 +- pagetop/src/base/module/demopage.rs | 3 +- pagetop/src/base/theme/bulmix.rs | 2 +- pagetop/src/html.rs | 4 +- pagetop/src/html/layout.rs | 124 ------------ pagetop/src/html/spacing.rs | 177 ++++++++++++++++++ .../images/demo-header.svg | 0 10 files changed, 218 insertions(+), 148 deletions(-) delete mode 100644 pagetop/src/html/layout.rs create mode 100644 pagetop/src/html/spacing.rs rename pagetop/static/{bootsier => theme}/images/demo-header.svg (100%) diff --git a/pagetop/src/base/component/anchor.rs b/pagetop/src/base/component/anchor.rs index f6553096..e63f6432 100644 --- a/pagetop/src/base/component/anchor.rs +++ b/pagetop/src/base/component/anchor.rs @@ -29,7 +29,7 @@ pub struct Anchor { target : AnchorTarget, id : IdentifierValue, classes : Classes, - layout : Layout, + spaces : Spaces, template : String, } @@ -46,7 +46,7 @@ impl ComponentTrait for Anchor { target : AnchorTarget::Default, id : IdentifierValue::new(), classes : Classes::new(), - layout : Layout::new(), + spaces : Spaces::new(), template : "default".to_owned(), } } @@ -75,7 +75,7 @@ impl ComponentTrait for Anchor { a id=[self.id().get()] class=[self.classes().get()] - style=[self.layout().get()] + style=[self.spaces().get()] href=[self.href().get()] target=[target] { @@ -160,8 +160,8 @@ impl Anchor { self } - pub fn with_layout(mut self, property: LayoutProperty, value: LayoutUnit) -> Self { - self.alter_layout(property, value); + pub fn with_spaces(mut self, spaces: &[SpaceSet]) -> Self { + self.alter_spaces(spaces); self } @@ -228,8 +228,8 @@ impl Anchor { self } - pub fn alter_layout(&mut self, property: LayoutProperty, value: LayoutUnit) -> &mut Self { - self.layout.add(property, value); + pub fn alter_spaces(&mut self, spaces: &[SpaceSet]) -> &mut Self { + self.spaces.add(spaces); self } @@ -272,8 +272,8 @@ impl Anchor { &self.classes } - pub fn layout(&self) -> &Layout { - &self.layout + pub fn spaces(&self) -> &Spaces { + &self.spaces } pub fn template(&self) -> &str { diff --git a/pagetop/src/base/component/grid/column.rs b/pagetop/src/base/component/grid/column.rs index 9ff5912f..b8cb9419 100644 --- a/pagetop/src/base/component/grid/column.rs +++ b/pagetop/src/base/component/grid/column.rs @@ -18,7 +18,7 @@ impl ComponentTrait for Column { weight : 0, components: ComponentsBundle::new(), id : IdentifierValue::new(), - classes : Classes::new_with_default("col"), + classes : Classes::new_with_default("col-md"), template : "default".to_owned(), } } diff --git a/pagetop/src/base/component/grid/row.rs b/pagetop/src/base/component/grid/row.rs index 2ec9139f..efd544a7 100644 --- a/pagetop/src/base/component/grid/row.rs +++ b/pagetop/src/base/component/grid/row.rs @@ -8,6 +8,7 @@ pub struct Row { columns : ComponentsBundle, id : IdentifierValue, classes : Classes, + spaces : Spaces, template : String, } @@ -19,6 +20,7 @@ impl ComponentTrait for Row { columns : ComponentsBundle::new(), id : IdentifierValue::new(), classes : Classes::new_with_default("row"), + spaces : Spaces::new(), template : "default".to_owned(), } } @@ -37,7 +39,7 @@ impl ComponentTrait for Row { fn default_render(&self, context: &mut InContext) -> Markup { html! { - div id=[self.id().get()] class=[self.classes().get()] { + div id=[self.id().get()] class=[self.classes().get()] style=[self.spaces().get()] { (self.columns().render(context)) } } @@ -87,6 +89,11 @@ impl Row { self } + pub fn with_spaces(mut self, spaces: &[SpaceSet]) -> Self { + self.alter_spaces(spaces); + self + } + pub fn using_template(mut self, template: &str) -> Self { self.alter_template(template); self @@ -114,6 +121,11 @@ impl Row { self } + pub fn alter_spaces(&mut self, spaces: &[SpaceSet]) -> &mut Self { + self.spaces.add(spaces); + self + } + pub fn alter_template(&mut self, template: &str) -> &mut Self { self.template = template.to_owned(); self @@ -129,6 +141,10 @@ impl Row { &self.classes } + pub fn spaces(&self) -> &Spaces { + &self.spaces + } + pub fn template(&self) -> &str { self.template.as_str() } diff --git a/pagetop/src/base/component/icon.rs b/pagetop/src/base/component/icon.rs index 238c71e7..770d0a9d 100644 --- a/pagetop/src/base/component/icon.rs +++ b/pagetop/src/base/component/icon.rs @@ -6,7 +6,7 @@ pub struct Icon { renderable: fn() -> bool, weight : isize, classes : Classes, - layout : Layout, + spaces : Spaces, } impl ComponentTrait for Icon { @@ -15,7 +15,7 @@ impl ComponentTrait for Icon { renderable: render_always, weight : 0, classes : Classes::new_with_default("bi-question-circle-fill"), - layout : Layout::new(), + spaces : Spaces::new(), } } @@ -37,7 +37,7 @@ impl ComponentTrait for Icon { "/theme/icons/bootstrap-icons.css?ver=1.8.2" )); - html! { i class=[self.classes().get()] style=[self.layout().get()] {}; } + html! { i class=[self.classes().get()] style=[self.spaces().get()] {}; } } fn as_ref_any(&self) -> &dyn AnyComponent { @@ -76,8 +76,8 @@ impl Icon { self } - pub fn with_layout(mut self, property: LayoutProperty, value: LayoutUnit) -> Self { - self.alter_layout(property, value); + pub fn with_spaces(mut self, spaces: &[SpaceSet]) -> Self { + self.alter_spaces(spaces); self } @@ -103,8 +103,8 @@ impl Icon { self } - pub fn alter_layout(&mut self, property: LayoutProperty, value: LayoutUnit) -> &mut Self { - self.layout.add(property, value); + pub fn alter_spaces(&mut self, spaces: &[SpaceSet]) -> &mut Self { + self.spaces.add(spaces); self } @@ -114,7 +114,7 @@ impl Icon { &self.classes } - pub fn layout(&self) -> &Layout { - &self.layout + pub fn spaces(&self) -> &Spaces { + &self.spaces } } diff --git a/pagetop/src/base/module/demopage.rs b/pagetop/src/base/module/demopage.rs index 0e35420b..95a069d2 100644 --- a/pagetop/src/base/module/demopage.rs +++ b/pagetop/src/base/module/demopage.rs @@ -73,8 +73,9 @@ fn hello_world() -> Container { ) ) .add_column(grid::Column::new() - .add(Image::image("/bootsier/images/demo-header.svg")) + .add(Image::image("/theme/images/demo-header.svg")) ) + .with_spaces(&[SpaceSet::PaddingBoth(SpaceValue::RelEm(2.0), SpaceValue::RelPct(5.0))]) ) } diff --git a/pagetop/src/base/theme/bulmix.rs b/pagetop/src/base/theme/bulmix.rs index f586ea07..ff2f29bc 100644 --- a/pagetop/src/base/theme/bulmix.rs +++ b/pagetop/src/base/theme/bulmix.rs @@ -90,7 +90,7 @@ impl ThemeTrait for Bulmix { )); Some(html! { span class="icon" { - i class=[icon.classes().get()] style=[icon.layout().get()] {}; + i class=[icon.classes().get()] style=[icon.spaces().get()] {}; } }) }, diff --git a/pagetop/src/html.rs b/pagetop/src/html.rs index 6d586449..eb720c41 100644 --- a/pagetop/src/html.rs +++ b/pagetop/src/html.rs @@ -17,5 +17,5 @@ pub use identifier::IdentifierValue; mod classes; pub use classes::{Classes, ClassesOp}; -mod layout; -pub use layout::{Layout, LayoutProperty, LayoutUnit}; +mod spacing; +pub use spacing::{Spaces, SpaceSet, SpaceValue}; diff --git a/pagetop/src/html/layout.rs b/pagetop/src/html/layout.rs deleted file mode 100644 index ddd4a893..00000000 --- a/pagetop/src/html/layout.rs +++ /dev/null @@ -1,124 +0,0 @@ -use crate::concat_string; - -#[derive(Clone, Copy, PartialEq)] -pub enum LayoutProperty { - MarginBottom, - MarginLeft, - MarginRight, - MarginTop, - PaddingBottom, - PaddingLeft, - PaddingRight, - PaddingTop, -} - -impl std::convert::AsRef for LayoutProperty { - fn as_ref(&self) -> &str { - match *self { - LayoutProperty::MarginBottom => "margin-bottom", - LayoutProperty::MarginLeft => "margin-left", - LayoutProperty::MarginRight => "margin-right", - LayoutProperty::MarginTop => "margin-top", - LayoutProperty::PaddingBottom => "padding-bottom", - LayoutProperty::PaddingLeft => "padding-left", - LayoutProperty::PaddingRight => "padding-right", - LayoutProperty::PaddingTop => "padding-top", - } - } -} - -// About pixels: Pixels (px) are relative to the viewing device. For low-dpi -// devices, 1px is one device pixel (dot) of the display. For printers and high -// resolution screens 1px implies multiple device pixels. - -// About em: 2em means 2 times the size of the current font. The em and rem -// units are practical in creating perfectly scalable layout! - -// About viewport: If the browser window size is 50cm wide, 1vw = 0.5cm. - -#[derive(PartialEq)] -pub enum LayoutUnit { - Auto, - - Cm(isize), // Centimeters. - In(isize), // Inches (1in = 96px = 2.54cm). - Mm(isize), // Millimeters. - Pc(isize), // Picas (1pc = 12pt). - Pt(isize), // Points (1pt = 1/72 of 1in). - Px(isize), // Pixels (1px = 1/96th of 1in). - - RelEm(f32), // Relative to the font-size of the element. - RelPct(f32), // Percentage relative to the parent element. - RelRem(f32), // Relative to font-size of the root element. - RelVh(f32), // Relative to 1% of the height of the viewport. - RelVw(f32), // Relative to 1% of the width of the viewport. - - UnSet, -} - -impl LayoutUnit { - fn to_inline(&self, property: LayoutProperty) -> String { - match self { - LayoutUnit::Auto => concat_string!(property, ":auto;"), - - LayoutUnit::Cm(value) => concat_string!(property, ":", value.to_string(), "cm;"), - LayoutUnit::In(value) => concat_string!(property, ":", value.to_string(), "in;"), - LayoutUnit::Mm(value) => concat_string!(property, ":", value.to_string(), "mm;"), - LayoutUnit::Pc(value) => concat_string!(property, ":", value.to_string(), "pc;"), - LayoutUnit::Pt(value) => concat_string!(property, ":", value.to_string(), "pt;"), - LayoutUnit::Px(value) => concat_string!(property, ":", value.to_string(), "px;"), - - LayoutUnit::RelEm(value) => concat_string!(property, ":", value.to_string(), "em;"), - LayoutUnit::RelPct(value) => concat_string!(property, ":", value.to_string(), "%;"), - LayoutUnit::RelRem(value) => concat_string!(property, ":", value.to_string(), "rem;"), - LayoutUnit::RelVh(value) => concat_string!(property, ":", value.to_string(), "vh;"), - LayoutUnit::RelVw(value) => concat_string!(property, ":", value.to_string(), "vw;"), - - _ => "".to_owned(), - } - } -} - -struct Style { - property: LayoutProperty, - inline : String, -} - -pub struct Layout(Vec