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 2F54B1FF146 for ; Tue, 09 Jun 2026 15:37:46 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 101A114011; Tue, 9 Jun 2026 15:37:46 +0200 (CEST) From: Dominik Csapak To: yew-devel@lists.proxmox.com Subject: [PATCH yew-widget-toolkit 2/2] touch: slidable: improve action interface Date: Tue, 9 Jun 2026 15:37:09 +0200 Message-ID: <20260609133742.3249328-2-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260609133742.3249328-1-d.csapak@proxmox.com> References: <20260609133742.3249328-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.049 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 Message-ID-Hash: V5IJCJCVBGVB3QB67NBQUKQBD7PSFESI X-Message-ID-Hash: V5IJCJCVBGVB3QB67NBQUKQBD7PSFESI 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: usually when a widget has the capability to add children, a `with_child` and `add_child` is provided. Do that here too for the left and right actions. This way a user does not have to wrap their actions in a row manually, but can simply call 'with_left_action' multiple times. Signed-off-by: Dominik Csapak --- src/touch/slidable/mod.rs | 62 ++++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/src/touch/slidable/mod.rs b/src/touch/slidable/mod.rs index 0b0a513..b97a104 100644 --- a/src/touch/slidable/mod.rs +++ b/src/touch/slidable/mod.rs @@ -33,14 +33,24 @@ use pwt_macros::widget; pub struct Slidable { content: VNode, - /// Widget displayed on the left side (below the slider). + /// Widget displayed on the left side (below the slider). Takes precedence over + /// `left_action_list` and `with/add_left_action`. #[prop_or_default] pub left_actions: Option, - /// Widget displayed on the right side (below the slider). + /// Widget displayed on the right side (below the slider). Takes precedence over + /// `right_action_list` and `with/add_right_action`. #[prop_or_default] pub right_actions: Option, + #[prop_or_default] + /// A list of left hand side slidable actions. + pub left_action_list: Vec, + + #[prop_or_default] + /// A list of right hand side slidable actions. + pub right_action_list: Vec, + /// Dismiss callback. /// /// Without a callback, dismiss is disabled on slidables without actions. @@ -100,6 +110,28 @@ impl Slidable { pub fn set_on_tap(&mut self, cb: impl IntoEventCallback) { self.on_tap = cb.into_event_callback(); } + + /// Method to add a left hand side action + pub fn add_left_action(&mut self, action: impl Into) { + self.left_action_list.push(action.into()); + } + + /// Builder style method to add a left hand side action + pub fn with_left_action(mut self, action: impl Into) -> Self { + self.add_left_action(action); + self + } + + /// Method to add a right hand side action + pub fn add_right_action(&mut self, action: impl Into) { + self.right_action_list.push(action.into()); + } + + /// Builder style method to add a right hand side action + pub fn with_right_action(mut self, action: impl Into) -> Self { + self.add_right_action(action); + self + } } #[derive(Copy, Clone, Debug, PartialEq)] @@ -174,16 +206,23 @@ impl PwtSlidable { fn left_container(&self, ctx: &Context) -> Html { let props = ctx.props(); - let actions = props.left_actions.clone(); + let actions = match props.left_actions.clone() { + Some(actions) => vec![actions], + None => props + .left_action_list + .iter() + .map(|action| action.clone().into()) + .collect(), + }; Row::new() .class("pwt-w-100 pwt-h-100") .with_child( - Container::new() + Row::new() .height(CssLength::Fraction(1.0)) .min_width(0) .style("flex", "0 1 auto") - .with_optional_child(actions) + .children(actions) .into_html_with_ref(self.left_action_ref.clone()), ) .with_child(html! {
}) @@ -192,17 +231,24 @@ impl PwtSlidable { fn right_container(&self, ctx: &Context) -> Html { let props = ctx.props(); - let actions = props.right_actions.clone(); + let actions = match props.right_actions.clone() { + Some(action) => vec![action], + None => props + .right_action_list + .iter() + .map(|action| action.clone().into()) + .collect(), + }; Row::new() .class("pwt-w-100 pwt-h-100") .with_child(html! {
}) .with_child( - Container::new() + Row::new() .height(CssLength::Fraction(1.0)) .min_width(0) .style("flex", "0 1 auto") - .with_optional_child(actions) + .children(actions) .into_html_with_ref(self.right_action_ref.clone()), ) .into_html_with_ref(self.right_ref.clone()) -- 2.47.3