From 9ceda6d70451e01de50c79a63b106b586c300095 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Tue, 19 Sep 2023 16:38:04 +0200 Subject: [PATCH] feat(widget): add `navigation` with `page_list_item` and `sub_page_header` --- src/widget/mod.rs | 2 ++ src/widget/navigation.rs | 56 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 src/widget/navigation.rs diff --git a/src/widget/mod.rs b/src/widget/mod.rs index 467a9213..6bb9d4cb 100644 --- a/src/widget/mod.rs +++ b/src/widget/mod.rs @@ -121,6 +121,8 @@ pub use nav_bar::nav_bar; pub mod nav_bar_toggle; pub use nav_bar_toggle::{nav_bar_toggle, NavBarToggle}; +pub mod navigation; + pub mod popover; pub use popover::{popover, Popover}; diff --git a/src/widget/navigation.rs b/src/widget/navigation.rs new file mode 100644 index 00000000..19b63a89 --- /dev/null +++ b/src/widget/navigation.rs @@ -0,0 +1,56 @@ +// Copyright 2023 System76 +// SPDX-License-Identifier: MPL-2.0 + +use crate::widget::{button, column, container, horizontal_space, icon, list, row, text, Column}; +use crate::{theme, Apply, Element}; +use iced::Length; + +#[must_use] +pub fn page_list_item<'a, Message: 'static + Clone>( + title: &'a str, + description: &'a str, + icon: &'a str, + message: Message, +) -> Element<'a, Message> { + let control = row::with_children(vec![ + horizontal_space(Length::Fill).into(), + icon::from_name("go-next-symbolic").size(16).into(), + ]); + + super::settings::item::builder(title) + .description(description) + .icon(icon::from_name(icon).size(16)) + .control(control) + .spacing(16) + .apply(container) + .padding([20, 24]) + .style(theme::Container::custom(list::style)) + .apply(button) + .style(theme::Button::Transparent) + .on_press(message) + .into() +} + +#[must_use] +pub fn sub_page_header<'a, Message: 'static + Clone>( + sub_page: &'a str, + parent_page: &'a str, + on_press: Message, +) -> Element<'a, Message> { + let previous_button = button::icon(icon::from_name("go-previous-symbolic")) + .extra_small() + .label(parent_page) + .spacing(16) + .style(button::Style::Link) + .on_press(on_press); + + let sub_page_header = row::with_capacity(2) + .push(text::title3(sub_page)) + .push(horizontal_space(Length::Fill)); + + column::with_capacity(2) + .push(previous_button) + .push(sub_page_header) + .spacing(6) + .into() +}