improv: use current design for nav bar toggle button

This commit is contained in:
Michael Aaron Murphy 2023-01-09 22:59:39 +01:00 committed by Michael Murphy
parent c4bd0fa3d8
commit 352bf8e401
7 changed files with 81 additions and 79 deletions

View file

@ -0,0 +1,54 @@
// Copyright 2022 System76 <info@system76.com>
// SPDX-License-Identifier: MPL-2.0
use crate::{theme, Element};
use apply::Apply;
use derive_setters::Setters;
use iced::Length;
use super::IconSource;
#[derive(Setters)]
pub struct NavBarToggle<Message> {
nav_bar_active: bool,
#[setters(strip_option)]
on_nav_bar_toggled: Option<Message>,
}
#[must_use]
pub fn nav_bar_toggle<Message>() -> NavBarToggle<Message> {
NavBarToggle {
nav_bar_active: false,
on_nav_bar_toggled: None,
}
}
impl<Message: 'static + Clone> From<NavBarToggle<Message>> for Element<'static, Message> {
fn from(nav_bar_toggle: NavBarToggle<Message>) -> Self {
let mut widget = super::icon(
if nav_bar_toggle.nav_bar_active {
IconSource::EmbeddedSvg(iced::widget::svg::Handle::from_memory(
&include_bytes!("../../res/sidebar-active.svg")[..],
))
} else {
IconSource::Name("open-menu-symbolic".into())
},
16,
)
.style(theme::Svg::SymbolicActive)
.apply(iced::widget::container)
.apply(iced::widget::button)
.padding([8, 16, 8, 16])
.style(theme::Button::Text);
if let Some(message) = nav_bar_toggle.on_nav_bar_toggled {
widget = widget.on_press(message);
}
widget
.apply(iced::widget::container)
.center_y()
.height(Length::Fill)
.into()
}
}