feat!(widget): rewrite button & icon widget APIs

This commit is contained in:
Michael Aaron Murphy 2023-09-01 07:29:19 +02:00 committed by Michael Murphy
parent 18debe546d
commit 4e4eeaac12
60 changed files with 2191 additions and 1113 deletions

View file

@ -3,13 +3,11 @@
//! A button for toggling the navigation side panel.
use crate::{theme, Element};
use crate::{widget, Element};
use apply::Apply;
use derive_setters::Setters;
use iced::Length;
use super::IconSource;
#[derive(Setters)]
pub struct NavBarToggle<Message> {
active: bool,
@ -27,26 +25,22 @@ pub fn nav_bar_toggle<Message>() -> NavBarToggle<Message> {
impl<'a, Message: 'static + Clone> From<NavBarToggle<Message>> for Element<'a, Message> {
fn from(nav_bar_toggle: NavBarToggle<Message>) -> Self {
let mut widget = super::icon(
if nav_bar_toggle.active {
IconSource::svg_from_memory(&include_bytes!("../../res/sidebar-active.svg")[..])
} else {
IconSource::from("open-menu-symbolic")
},
16,
)
.style(theme::Svg::SymbolicActive)
.apply(iced::widget::container)
.apply(iced::widget::button)
.padding([8, 16, 8, 16])
.style(theme::Button::Text);
let icon = if nav_bar_toggle.active {
widget::icon::handle::from_svg_bytes(
&include_bytes!("../../res/sidebar-active.svg")[..],
)
.symbolic(true)
} else {
widget::icon::handle::from_name("open-menu-symbolic")
.size(16)
.handle()
};
if let Some(message) = nav_bar_toggle.on_toggle {
widget = widget.on_press(message);
}
widget
.apply(iced::widget::container)
widget::button::text("")
.leading_icon(icon)
.padding([8, 16, 8, 16])
.on_press_maybe(nav_bar_toggle.on_toggle)
.apply(widget::container)
.center_y()
.height(Length::Fill)
.into()