all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [PATCH yew-widget-toolkit v4] widget: add 'div' and 'span' helper functions
@ 2026-04-08 10:02 Dominik Csapak
  2026-04-10  6:39 ` applied: " Dietmar Maurer
  0 siblings, 1 reply; 2+ messages in thread
From: Dominik Csapak @ 2026-04-08 10:02 UTC (permalink / raw)
  To: yew-devel

these are just a simple wrapper around the `Container` widget, but it's
very useful in situations where bare strings are used in a flex layout,
since e.g. a `Row` with multiple children that are all strings won't get
a proper flex layout (since they're not elements)

So instead of writing
```
Row::new()
    .with_child(Container::new().with_child("Text1"))
    .with_child(Container::new().with_child("Text2"))
```

one can now write
```
Row::new()
    .with_child(div("Text1"))
    .with_child(div("Text2"))
```

which is much shorter and more readable.

In addition to the `div` helper also add a `span` helper,

Import the `ContainerBuilder` trait with a different name, otherwise
it conflicts with the Properties macro generated types.

To expose these functions, simply make the 'container' module public.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
changes from v3:
* drop 'italic' function, we can decide later if we want that/how we
  want to name it
* make the trait import global with different name, and give a better
  explanation why it's necessary.

 src/widget/container.rs | 17 +++++++++++++++++
 src/widget/mod.rs       |  2 +-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/widget/container.rs b/src/widget/container.rs
index 23d637b..6d51662 100644
--- a/src/widget/container.rs
+++ b/src/widget/container.rs
@@ -3,6 +3,9 @@ use std::borrow::Cow;
 use yew::prelude::*;
 use yew::virtual_dom::VTag;
 
+// include with different name, since Properties macro generates a `StructNameBuilder`
+// already, which results here in `ContainerBuilder``
+use crate::props::ContainerBuilder as PwtContainerBuilder;
 use crate::props::{IntoVTag, ListenersWrapper, WidgetStdProps};
 
 use pwt_macros::widget;
@@ -57,3 +60,17 @@ impl IntoVTag for Container {
         )
     }
 }
+
+/// Helper function to create a `<div>` element with a single child.
+///
+/// It's the same as `Container::new().with_child(comp)`
+pub fn div(comp: impl Into<Html>) -> Container {
+    Container::new().with_child(comp)
+}
+
+/// Helper function to create a `<span>` element with a single child.
+///
+/// It's the same as `Container::from_tag("span").with_child(comp)`
+pub fn span(comp: impl Into<Html>) -> Container {
+    Container::from_tag("span").with_child(comp)
+}
diff --git a/src/widget/mod.rs b/src/widget/mod.rs
index 0df2cbf..ff3234a 100644
--- a/src/widget/mod.rs
+++ b/src/widget/mod.rs
@@ -31,7 +31,7 @@ pub use catalog_loader::PwtCatalogLoader;
 mod column;
 pub use column::Column;
 
-mod container;
+pub mod container;
 pub use container::Container;
 
 mod confirm_dialog;
-- 
2.47.3





^ permalink raw reply	[flat|nested] 2+ messages in thread

* applied: [PATCH yew-widget-toolkit v4] widget: add 'div' and 'span' helper functions
  2026-04-08 10:02 [PATCH yew-widget-toolkit v4] widget: add 'div' and 'span' helper functions Dominik Csapak
@ 2026-04-10  6:39 ` Dietmar Maurer
  0 siblings, 0 replies; 2+ messages in thread
From: Dietmar Maurer @ 2026-04-10  6:39 UTC (permalink / raw)
  To: Dominik Csapak, yew-devel

applied




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-04-10  6:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-08 10:02 [PATCH yew-widget-toolkit v4] widget: add 'div' and 'span' helper functions Dominik Csapak
2026-04-10  6:39 ` applied: " Dietmar Maurer

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal