From a687c646f21a13d78217baae063dbe4704f7da53 Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Wed, 16 Nov 2022 00:32:41 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Refina=20algunos=20constructores?= =?UTF-8?q?=20de=20componentes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/base/component/form_element/button.rs | 2 +- pagetop/src/base/component/image.rs | 2 +- pagetop/src/base/component/menu.rs | 36 +++++++------------ pagetop/src/base/module/homepage.rs | 12 +++---- 4 files changed, 20 insertions(+), 32 deletions(-) diff --git a/pagetop/src/base/component/form_element/button.rs b/pagetop/src/base/component/form_element/button.rs index e20c920e..32f7c9f7 100644 --- a/pagetop/src/base/component/form_element/button.rs +++ b/pagetop/src/base/component/form_element/button.rs @@ -75,7 +75,7 @@ impl ComponentTrait for Button { } impl Button { - pub fn new_with_value(value: &str) -> Self { + pub fn with(value: &str) -> Self { Button::new().with_value(value) } diff --git a/pagetop/src/base/component/image.rs b/pagetop/src/base/component/image.rs index cb59442f..eb0b79f8 100644 --- a/pagetop/src/base/component/image.rs +++ b/pagetop/src/base/component/image.rs @@ -49,7 +49,7 @@ impl ComponentTrait for Image { } impl Image { - pub fn new_with_source(source: &str) -> Self { + pub fn with(source: &str) -> Self { Image::new().with_source(source) } diff --git a/pagetop/src/base/component/menu.rs b/pagetop/src/base/component/menu.rs index a95ade58..81a0c348 100644 --- a/pagetop/src/base/component/menu.rs +++ b/pagetop/src/base/component/menu.rs @@ -83,57 +83,45 @@ impl ComponentTrait for MenuItem { } impl MenuItem { - #[rustfmt::skip] pub fn label(label: &str) -> Self { MenuItem { - weight : 0, - renderable: Renderable::default(), - item_type : MenuItemType::Label(label.to_owned()), + item_type: MenuItemType::Label(label.to_owned()), + ..Default::default() } } - #[rustfmt::skip] pub fn link(label: &str, path: &str) -> Self { MenuItem { - weight : 0, - renderable: Renderable::default(), - item_type : MenuItemType::Link(label.to_owned(), path.to_owned()), + item_type: MenuItemType::Link(label.to_owned(), path.to_owned()), + ..Default::default() } } - #[rustfmt::skip] pub fn link_blank(label: &str, path: &str) -> Self { MenuItem { - weight : 0, - renderable: Renderable::default(), - item_type : MenuItemType::LinkBlank(label.to_owned(), path.to_owned()), + item_type: MenuItemType::LinkBlank(label.to_owned(), path.to_owned()), + ..Default::default() } } - #[rustfmt::skip] pub fn html(html: Markup) -> Self { MenuItem { - weight : 0, - renderable: Renderable::default(), - item_type : MenuItemType::Html(html), + item_type: MenuItemType::Html(html), + ..Default::default() } } - #[rustfmt::skip] pub fn submenu(label: &str, menu: Menu) -> Self { MenuItem { - weight : 0, - renderable: Renderable::default(), - item_type : MenuItemType::Submenu(label.to_owned(), menu), + item_type: MenuItemType::Submenu(label.to_owned(), menu), + ..Default::default() } } - #[rustfmt::skip] pub fn separator() -> Self { MenuItem { - weight : 0, - renderable: Renderable::default(), - item_type : MenuItemType::Separator, + item_type: MenuItemType::Separator, + ..Default::default() } } diff --git a/pagetop/src/base/module/homepage.rs b/pagetop/src/base/module/homepage.rs index bf282187..5fb37d63 100644 --- a/pagetop/src/base/module/homepage.rs +++ b/pagetop/src/base/module/homepage.rs @@ -35,7 +35,7 @@ async fn demo() -> ResultPage { .add_to("region-content", welcome()) .add_to("region-content", about_pagetop()) .add_to("region-content", promo_pagetop()) - .add_to("region-content", reporting_problems()) + .add_to("region-content", reporting_issues()) .render() } @@ -90,7 +90,7 @@ fn hello_world() -> Container { .with_column( grid::Column::new() .with_classes(ClassesOp::Add, "hello-col-image") - .with_component(Image::new_with_source("/theme/images/homepage-header.svg")), + .with_component(Image::with("/theme/images/homepage-header.svg")), ), ) } @@ -129,7 +129,7 @@ fn about_pagetop() -> Container { grid::Column::new() .with_classes(ClassesOp::Add, "pagetop-col-image") .with_size(grid::ColumnSize::Is5of12) - .with_component(Image::new_with_source("/theme/images/homepage-about.svg")), + .with_component(Image::with("/theme/images/homepage-about.svg")), ) .with_column( grid::Column::new() @@ -185,18 +185,18 @@ fn promo_pagetop() -> Container { grid::Column::new() .with_classes(ClassesOp::Add, "promo-col-image") .with_size(grid::ColumnSize::Is6of12) - .with_component(Image::new_with_source("/theme/images/homepage-pagetop.png")), + .with_component(Image::with("/theme/images/homepage-pagetop.png")), ), ) } -fn reporting_problems() -> Container { +fn reporting_issues() -> Container { Container::new().with_id("reporting").with_component( grid::Row::new() .with_column( grid::Column::new() .with_classes(ClassesOp::Add, "reporting-col-image") - .with_component(Image::new_with_source("/theme/images/homepage-support.jpg")), + .with_component(Image::with("/theme/images/homepage-support.jpg")), ) .with_column( grid::Column::new()