cosmic/widget/
nav_bar_toggle.rsuse crate::{widget, Element};
use derive_setters::Setters;
#[derive(Setters)]
pub struct NavBarToggle<Message> {
active: bool,
#[setters(strip_option)]
on_toggle: Option<Message>,
class: crate::theme::Button,
selected: bool,
}
#[must_use]
pub fn nav_bar_toggle<Message>() -> NavBarToggle<Message> {
NavBarToggle {
active: false,
on_toggle: None,
class: crate::theme::Button::NavToggle,
selected: false,
}
}
impl<'a, Message: 'static + Clone> From<NavBarToggle<Message>> for Element<'a, Message> {
fn from(nav_bar_toggle: NavBarToggle<Message>) -> Self {
let icon = if nav_bar_toggle.active {
widget::icon::from_svg_bytes(
&include_bytes!("../../res/icons/navbar-open-symbolic.svg")[..],
)
.symbolic(true)
} else {
widget::icon::from_svg_bytes(
&include_bytes!("../../res/icons/navbar-closed-symbolic.svg")[..],
)
.symbolic(true)
};
widget::button::icon(icon)
.padding([8, 16])
.on_press_maybe(nav_bar_toggle.on_toggle)
.selected(nav_bar_toggle.selected)
.class(nav_bar_toggle.class)
.into()
}
}