From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 79C011FF13B for ; Wed, 08 Apr 2026 12:04:12 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 261557637; Wed, 8 Apr 2026 12:04:48 +0200 (CEST) From: Dominik Csapak To: yew-devel@lists.proxmox.com Subject: [PATCH yew-widget-toolkit v4] widget: add 'div' and 'span' helper functions Date: Wed, 8 Apr 2026 12:02:50 +0200 Message-ID: <20260408100408.1274308-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.048 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [mod.rs,container.rs] Message-ID-Hash: JETT2G4IWFMNEBO5AS7RNQ6D6RK7N5W3 X-Message-ID-Hash: JETT2G4IWFMNEBO5AS7RNQ6D6RK7N5W3 X-MailFrom: d.csapak@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Yew framework devel list at Proxmox List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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 `
` element with a single child. +/// +/// It's the same as `Container::new().with_child(comp)` +pub fn div(comp: impl Into) -> Container { + Container::new().with_child(comp) +} + +/// Helper function to create a `` element with a single child. +/// +/// It's the same as `Container::from_tag("span").with_child(comp)` +pub fn span(comp: impl Into) -> 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