From: Dominik Csapak <d.csapak@proxmox.com>
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 [thread overview]
Message-ID: <20260609133742.3249328-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20260609133742.3249328-1-d.csapak@proxmox.com>
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 <d.csapak@proxmox.com>
---
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<VNode>,
- /// 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<VNode>,
+ #[prop_or_default]
+ /// A list of left hand side slidable actions.
+ pub left_action_list: Vec<SlidableAction>,
+
+ #[prop_or_default]
+ /// A list of right hand side slidable actions.
+ pub right_action_list: Vec<SlidableAction>,
+
/// 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<InputEvent>) {
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<SlidableAction>) {
+ 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<SlidableAction>) -> 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<SlidableAction>) {
+ 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<SlidableAction>) -> Self {
+ self.add_right_action(action);
+ self
+ }
}
#[derive(Copy, Clone, Debug, PartialEq)]
@@ -174,16 +206,23 @@ impl PwtSlidable {
fn left_container(&self, ctx: &Context<Self>) -> 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! {<div style="flex: 1 1 auto;"></div>})
@@ -192,17 +231,24 @@ impl PwtSlidable {
fn right_container(&self, ctx: &Context<Self>) -> 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! {<div style="flex: 1 1 auto;"></div>})
.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
next prev parent reply other threads:[~2026-06-09 13:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-09 13:37 [PATCH yew-widget-toolkit 1/2] touch: slidable: properly use builder methods for style/css Dominik Csapak
2026-06-09 13:37 ` Dominik Csapak [this message]
2026-06-09 16:50 ` applied: " Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260609133742.3249328-2-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=yew-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox