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 36A751FF13C for ; Thu, 02 Apr 2026 15:44:49 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id C747C1B7BA; Thu, 2 Apr 2026 15:45:18 +0200 (CEST) Message-ID: Date: Thu, 2 Apr 2026 15:44:44 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta Subject: superseded: [PATCH yew-widget-toolkit] widget: add 'div' macro From: Dominik Csapak To: yew-devel@lists.proxmox.com References: <20260402132315.3276517-1-d.csapak@proxmox.com> Content-Language: en-US In-Reply-To: <20260402132315.3276517-1-d.csapak@proxmox.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1775137426043 X-SPAM-LEVEL: Spam detection results: 0 AWL -2.451 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 SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_DBL_SPAM 5 Contains a spam URL listed in the Spamhaus DBL blocklist [macros.rs] Message-ID-Hash: REHYUHNLCUDMOBKZB3QNPQVLGFQTRSOA X-Message-ID-Hash: REHYUHNLCUDMOBKZB3QNPQVLGFQTRSOA 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: superseded by v2: https://lore.proxmox.com/yew-devel/20260402134337.3433085-1-d.csapak@proxmox.com/ On 4/2/26 3:22 PM, Dominik Csapak wrote: > this is 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. > > Signed-off-by: Dominik Csapak > --- > src/lib.rs | 1 + > src/widget/macros.rs | 34 ++++++++++++++++++++++++++++++++++ > src/widget/mod.rs | 2 ++ > 3 files changed, 37 insertions(+) > create mode 100644 src/widget/macros.rs > > diff --git a/src/lib.rs b/src/lib.rs > index d3ac6ea..198b987 100644 > --- a/src/lib.rs > +++ b/src/lib.rs > @@ -370,6 +370,7 @@ pub mod prelude { > pub use crate::props::WidgetBuilder; > pub use crate::props::WidgetStyleBuilder; > pub use crate::tr; > + pub use crate::widget::macros; > pub use crate::{gettext, gettext_noop, ngettext, npgettext, pgettext}; > } > > diff --git a/src/widget/macros.rs b/src/widget/macros.rs > new file mode 100644 > index 0000000..fc4e05f > --- /dev/null > +++ b/src/widget/macros.rs > @@ -0,0 +1,34 @@ > +//! Helper and utility macros to make some often used patterns more ergonomic > + > +/// A macro to wrap some elements or strings in a `
`. > +/// > +/// Expands to `Container::new().with_child(param1).with_child(param2)...` > +/// > +/// Examples: > +/// ``` > +/// # use pwt::widget::Container; > +/// # use pwt::div; > +/// // must be used, either directly or via pwt::prelude::* > +/// use pwt::props::ContainerBuilder; > +/// > +/// # fn main() { > +/// let div = div!("Some Text"); > +/// # drop(div); > +/// > +/// // is the same as > +/// let div = Container::new().with_child("Some Text"); > +/// # drop(div); > +/// > +/// // you can also specify multiple elements > +/// div!("Text1", "Text2"); > +/// > +/// // or components > +/// div!(Container::new()); > +/// # } > +/// ``` > +#[macro_export] > +macro_rules! div { > + ($($arg:expr),* $(,)?) => { > + $crate::widget::Container::new()$(.with_child($arg))* > + }; > +} > diff --git a/src/widget/mod.rs b/src/widget/mod.rs > index 0df2cbf..1998332 100644 > --- a/src/widget/mod.rs > +++ b/src/widget/mod.rs > @@ -85,6 +85,8 @@ pub use list::{List, ListTile, ListTileObserver}; > #[doc(hidden)] > pub use list::{PwtList, PwtListTileObserver}; > > +pub mod macros; > + > mod mask; > pub use mask::Mask; > #[doc(hidden)]