use iced::widget::{button, container, row, text}; use iced::{Alignment, Element, Length}; /// Floating Action Button component #[derive(Debug, Clone)] pub struct FloatingAction { pub icon: String, pub label: String, pub on_press: Option, } impl FloatingAction { /// Create a new floating action button pub fn new(icon: &str, label: &str) -> Self { Self { icon: icon.to_string(), label: label.to_string(), on_press: None, } } /// Create a floating action button with a message pub fn with_on_press(mut self, message: crate::messages::Message) -> Self { self.on_press = Some(message); self } /// View the floating action button pub fn view(&self) -> Element { let button = button( row(vec![text(&self.icon).into(), text(&self.label).into()]) .spacing(8) .align_items(Alignment::Center) .width(Length::Fill), ) .padding(16); let button = button.on_press_maybe(self.on_press.clone()); container(button) .width(Length::Fill) .padding(8) .align_x(iced::alignment::Horizontal::Center) .into() } } impl Default for FloatingAction { fn default() -> Self { Self::new("➕", "Add") } }