improv: alignment of sub page header button

This commit is contained in:
Michael Aaron Murphy 2024-01-18 03:59:03 +01:00 committed by Michael Murphy
parent 3787bf8cbc
commit 42fbf92d2f
2 changed files with 57 additions and 5 deletions

View file

@ -651,7 +651,7 @@ impl SettingsApp {
let mut column_widgets = Vec::with_capacity(1);
if let Some(parent) = page.parent {
column_widgets.push(navigation::sub_page_header(
column_widgets.push(crate::widget::sub_page_header(
page.title.as_str(),
self.pages.info[parent].title.as_str(),
Message::Page(parent),
@ -736,7 +736,7 @@ impl SettingsApp {
for entity in sub_pages.iter().copied() {
let sub_page = &self.pages.info[entity];
page_list = page_list.push(navigation::page_list_item(
page_list = page_list.push(crate::widget::page_list_item(
sub_page.title.as_str(),
sub_page.description.as_str(),
&sub_page.icon_name,

View file

@ -1,12 +1,11 @@
// Copyright 2023 System76 <info@system76.com>
// SPDX-License-Identifier: GPL-3.0-only
use apply::Apply;
use cosmic::iced::Length;
use cosmic::widget::{
button, column, container, divider, horizontal_space, row, settings, text, vertical_space,
button, column, container, divider, horizontal_space, icon, list, row, settings, text, vertical_space,
};
use cosmic::Element;
use cosmic::{theme, Apply, Element};
use cosmic_settings_page as page;
#[must_use]
@ -76,3 +75,56 @@ pub fn display_container<'a, Message: 'a>(widget: Element<'a, Message>) -> Eleme
.padding([0, 0, 8, 0])
.into()
}
#[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(),
]);
cosmic::widget::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()
.padding(0)
.label(parent_page)
.spacing(4)
.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()
}