feat(widget): add navigation with page_list_item and sub_page_header

This commit is contained in:
Michael Aaron Murphy 2023-09-19 16:38:04 +02:00 committed by Michael Murphy
parent 586a5debe7
commit 9ceda6d704
2 changed files with 58 additions and 0 deletions

View file

@ -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};

56
src/widget/navigation.rs Normal file
View file

@ -0,0 +1,56 @@
// Copyright 2023 System76 <info@system76.com>
// 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()
}