all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: yew-devel@lists.proxmox.com
Subject: [yew-devel] [PATCH yew-widget-toolkit 11/11] touch: fab menu: rework fab menu
Date: Fri, 27 Jun 2025 14:08:59 +0200	[thread overview]
Message-ID: <20250627120859.3723554-18-d.csapak@proxmox.com> (raw)
In-Reply-To: <20250627120859.3723554-1-d.csapak@proxmox.com>

This changes the way the fab menu is structured:
* use the new FabMenuEntry for entries instead of full Fab's
  this way we have better control over the layout and functions
* use a different markup so we can use flex-layout
  (see the necessary and corresponding pwt-assets patch)
* remove the left/right direction and center alignment since they're
  almost never useful, and can be reimplemented if necessary
  (removal makes the css part easier)
* introduce size and color options to better apply the material3 design

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/touch/fab_menu.rs | 140 +++++++++++++++++++++++++++++++-----------
 src/touch/mod.rs      |   4 +-
 2 files changed, 106 insertions(+), 38 deletions(-)

diff --git a/src/touch/fab_menu.rs b/src/touch/fab_menu.rs
index 92f2331..6a4f3f7 100644
--- a/src/touch/fab_menu.rs
+++ b/src/touch/fab_menu.rs
@@ -1,10 +1,12 @@
 use yew::prelude::*;
 
+use crate::css::ColorScheme;
 use crate::props::{ContainerBuilder, EventSubscriber, WidgetBuilder};
-use crate::widget::Container;
+use crate::widget::{Button, Container};
 
 use pwt_macros::{builder, widget};
 
+use super::fab::FabSize;
 use super::Fab;
 
 /// [FabMenu] direction.
@@ -12,23 +14,63 @@ use super::Fab;
 pub enum FabMenuDirection {
     Up,
     Down,
-    Left,
-    Right,
 }
 
 /// [FabMenu] alignment.
 #[derive(Copy, Clone, PartialEq)]
 pub enum FabMenuAlign {
     Start,
-    Center,
     End,
 }
 
+/// An entry for a [FabMenu]
+#[derive(PartialEq, Clone)]
+pub struct FabMenuEntry {
+    pub text: AttrValue,
+    pub icon: AttrValue,
+    pub on_activate: Callback<MouseEvent>,
+}
+
+impl FabMenuEntry {
+    pub fn new(
+        text: impl Into<AttrValue>,
+        icon: impl Into<AttrValue>,
+        on_activate: impl Into<Callback<MouseEvent>>,
+    ) -> Self {
+        Self {
+            text: text.into(),
+            icon: icon.into(),
+            on_activate: on_activate.into(),
+        }
+    }
+}
+
+/// [FabMenu] Color
+///
+/// Determines the color of the [Fab] and the [FabMenuEntry].
+#[derive(Clone, Copy, PartialEq, Eq, Default)]
+pub enum FabMenuColor {
+    #[default]
+    Primary,
+    Secondary,
+    Tertiary,
+}
+
 /// Favorite actions button Menu.
 #[widget(pwt=crate, comp=PwtFabMenu, @element)]
 #[derive(Properties, Clone, PartialEq)]
 #[builder]
 pub struct FabMenu {
+    /// The size of the [Fab]
+    #[prop_or_default]
+    #[builder]
+    pub size: FabSize,
+
+    /// The color scheme to apply on the [Fab] and the [FabMenuEntry]
+    #[prop_or_default]
+    #[builder]
+    pub color: FabMenuColor,
+
     /// Main button Icon (CSS class).
     #[prop_or_default]
     pub main_icon_class: Option<Classes>,
@@ -44,7 +86,7 @@ pub struct FabMenu {
 
     /// Menu alignment
     ///
-    #[prop_or(FabMenuAlign::Center)]
+    #[prop_or(FabMenuAlign::End)]
     #[builder]
     pub align: FabMenuAlign,
 
@@ -52,7 +94,7 @@ pub struct FabMenu {
     ///
     /// We currently support up to 5 children.
     #[prop_or_default]
-    pub children: Vec<Fab>,
+    pub children: Vec<FabMenuEntry>,
 }
 
 impl Default for FabMenu {
@@ -94,13 +136,13 @@ impl FabMenu {
     }
 
     /// Builder style method to add a child button
-    pub fn with_child(mut self, child: impl Into<Fab>) -> Self {
+    pub fn with_child(mut self, child: impl Into<FabMenuEntry>) -> Self {
         self.add_child(child);
         self
     }
 
     /// Method to add a child button
-    pub fn add_child(&mut self, child: impl Into<Fab>) {
+    pub fn add_child(&mut self, child: impl Into<FabMenuEntry>) {
         self.children.push(child.into());
     }
 }
@@ -139,26 +181,33 @@ impl Component for PwtFabMenu {
     fn view(&self, ctx: &Context<Self>) -> Html {
         let props = ctx.props();
 
-        let main_icon_class = match &props.main_icon_class {
-            Some(class) => class.clone(),
-            None => classes!("fa", "fa-plus"),
+        let main_icon_class = match (self.show_items, &props.main_icon_class) {
+            (false, Some(class)) => class.clone(),
+            (false, None) => classes!("fa", "fa-plus"),
+            (true, _) => classes!("fa", "fa-times"),
+        };
+
+        let (close_color, color) = match props.color {
+            FabMenuColor::Primary => (ColorScheme::Primary, ColorScheme::PrimaryContainer),
+            FabMenuColor::Secondary => (ColorScheme::Secondary, ColorScheme::SecondaryContainer),
+            FabMenuColor::Tertiary => (ColorScheme::Tertiary, ColorScheme::TertiaryContainer),
         };
 
+        let main_button = Fab::new(main_icon_class)
+            .size(if self.show_items {
+                FabSize::Small
+            } else {
+                props.size
+            })
+            .class(props.main_button_class.clone())
+            .class(if self.show_items { close_color } else { color })
+            .class(self.show_items.then_some("rounded"))
+            .on_activate(ctx.link().callback(|_| Msg::Toggle));
+
         let mut container = Container::new()
             .with_std_props(&props.std_props)
             .listeners(&props.listeners)
             .class("pwt-fab-menu-container")
-            .class(match props.align {
-                FabMenuAlign::Start => Some("pwt-fab-align-start"),
-                FabMenuAlign::End => Some("pwt-fab-align-end"),
-                FabMenuAlign::Center => None,
-            })
-            .class(match props.direction {
-                FabMenuDirection::Up => "pwt-fab-direction-up",
-                FabMenuDirection::Down => "pwt-fab-direction-down",
-                FabMenuDirection::Left => "pwt-fab-direction-left",
-                FabMenuDirection::Right => "pwt-fab-direction-right",
-            })
             .class(self.show_items.then_some("active"))
             .onkeydown({
                 let link = ctx.link().clone();
@@ -169,33 +218,50 @@ impl Component for PwtFabMenu {
                 }
             });
 
-        let main_button = Fab::new(main_icon_class)
-            .class(props.main_button_class.clone())
-            .on_activate(ctx.link().callback(|_| Msg::Toggle));
-
-        container.add_child(main_button);
-
         for (i, child) in props.children.iter().enumerate() {
             if i >= 5 {
                 log::error!("FabMenu only supports 5 child buttons.");
                 break;
             }
-            let orig_on_activate = child.on_activate.clone();
+
+            let on_activate = child.on_activate.clone();
             let link = ctx.link().clone();
 
-            let child_button = child
-                .clone()
-                .small()
+            let child = Button::new(child.text.clone())
+                .icon_class(child.icon.clone())
+                .class("medium")
+                .class(color)
                 .class("pwt-fab-menu-item")
                 .on_activate(move |event| {
                     link.send_message(Msg::Toggle);
-                    if let Some(on_activate) = &orig_on_activate {
-                        on_activate.emit(event);
-                    }
+                    on_activate.emit(event);
                 });
-            container.add_child(child_button);
+            container.add_child(child);
         }
 
-        container.into()
+        Container::new()
+            .with_std_props(&props.std_props)
+            .listeners(&props.listeners)
+            .class("pwt-fab-menu-outer")
+            .class(match props.align {
+                FabMenuAlign::Start => Some("pwt-fab-align-start"),
+                FabMenuAlign::End => Some("pwt-fab-align-end"),
+            })
+            .class(match props.direction {
+                FabMenuDirection::Up => "pwt-fab-direction-up",
+                FabMenuDirection::Down => "pwt-fab-direction-down",
+            })
+            .with_child(
+                Container::new()
+                    .class("pwt-fab-menu-main")
+                    .class(match props.size {
+                        FabSize::Small => "small",
+                        FabSize::Standard => "",
+                        FabSize::Large => "large",
+                    })
+                    .with_child(main_button),
+            )
+            .with_child(container)
+            .into()
     }
 }
diff --git a/src/touch/mod.rs b/src/touch/mod.rs
index f559689..acb27ae 100644
--- a/src/touch/mod.rs
+++ b/src/touch/mod.rs
@@ -11,7 +11,9 @@ mod fab;
 pub use fab::{Fab, FabSize, PwtFab};
 
 mod fab_menu;
-pub use fab_menu::{FabMenu, FabMenuAlign, FabMenuDirection, PwtFabMenu};
+pub use fab_menu::{
+    FabMenu, FabMenuAlign, FabMenuColor, FabMenuDirection, FabMenuEntry, PwtFabMenu,
+};
 
 mod material_app;
 pub use material_app::PageController;
-- 
2.39.5



_______________________________________________
yew-devel mailing list
yew-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel


  parent reply	other threads:[~2025-06-27 12:09 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-27 12:08 [yew-devel] [PATCH yew-widget-toolkit/yew-widget-toolkit-assets 00/17] various touch improvements Dominik Csapak
2025-06-27 12:08 ` [yew-devel] [PATCH yew-widget-toolkit-assets 1/6] reset: remove the tap highlight color for chrome Dominik Csapak
2025-06-27 12:08 ` [yew-devel] [PATCH yew-widget-toolkit-assets 2/6] page: add more page animation styles Dominik Csapak
2025-06-27 12:08 ` [yew-devel] [PATCH yew-widget-toolkit-assets 3/6] page: animations: reverse the direction on X axis for RTL mode Dominik Csapak
2025-06-27 12:08 ` [yew-devel] [PATCH yew-widget-toolkit-assets 4/6] application bar: reduce horizontal padding Dominik Csapak
2025-06-27 12:08 ` [yew-devel] [PATCH yew-widget-toolkit-assets 5/6] application bar: reverse back arrow for rtl Dominik Csapak
2025-06-27 12:54   ` Shannon Sterz
2025-06-27 13:38     ` Dominik Csapak
2025-06-27 12:08 ` [yew-devel] [PATCH yew-widget-toolkit-assets 6/6] buttons: rework fab menu Dominik Csapak
2025-06-27 12:08 ` [yew-devel] [PATCH yew-widget-toolkit 01/11] widget: implement Image widget Dominik Csapak
2025-06-27 12:08 ` [yew-devel] [PATCH yew-widget-toolkit 02/11] widget: button: don't hardcode icons font size Dominik Csapak
2025-06-27 12:08 ` [yew-devel] [PATCH yew-widget-toolkit 03/11] touch: page stack: add more animations Dominik Csapak
2025-06-27 12:08 ` [yew-devel] [PATCH yew-widget-toolkit 04/11] touch: application bar: set custom class on back button Dominik Csapak
2025-06-27 12:08 ` [yew-devel] [PATCH yew-widget-toolkit 05/11] touch: material app: allow pass through of page animation style Dominik Csapak
2025-06-27 13:37   ` Shannon Sterz
2025-06-27 13:38     ` Dominik Csapak
2025-06-27 14:32     ` Dietmar Maurer
2025-06-27 14:40       ` Shannon Sterz
2025-06-27 12:08 ` [yew-devel] [PATCH yew-widget-toolkit 06/11] touch: scaffold: fix overflow setting for body Dominik Csapak
2025-06-27 12:08 ` [yew-devel] [PATCH yew-widget-toolkit 07/11] touch: scaffold: use direction independent positioning for the FAB Dominik Csapak
2025-06-27 12:08 ` [yew-devel] [PATCH yew-widget-toolkit 08/11] touch: fab: add size option Dominik Csapak
2025-06-27 12:08 ` [yew-devel] [PATCH yew-widget-toolkit 09/11] touch: fab: convert to widget macro Dominik Csapak
2025-06-27 12:08 ` [yew-devel] [PATCH yew-widget-toolkit 10/11] touch: fab menu: " Dominik Csapak
2025-06-27 12:08 ` Dominik Csapak [this message]
2025-06-30  8:25 ` [yew-devel] [PATCH yew-widget-toolkit/yew-widget-toolkit-assets 00/17] various touch improvements Dominik Csapak

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=20250627120859.3723554-18-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 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