wip: Various refactorings and improvements
This commit is contained in:
parent
702ea033af
commit
37f978d1b3
33 changed files with 744 additions and 1229 deletions
26
src/widget/settings/item.rs
Normal file
26
src/widget/settings/item.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright 2022 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use crate::{Element, Renderer};
|
||||
|
||||
/// A setting within a settings view section.
|
||||
#[must_use]
|
||||
#[allow(clippy::module_name_repetitions)]
|
||||
pub fn item<'a, Message: 'static>(title: &'a str, widget: impl Into<Element<'a, Message>>) -> iced::widget::Row<'a, Message, Renderer> {
|
||||
item_row(vec![
|
||||
iced::widget::text(title).into(),
|
||||
iced::widget::horizontal_space(iced::Length::Fill).into(),
|
||||
widget.into()
|
||||
])
|
||||
}
|
||||
|
||||
/// A settings item aligned in a row
|
||||
#[must_use]
|
||||
#[allow(clippy::module_name_repetitions)]
|
||||
pub fn item_row<Message>(children: Vec<Element<Message>>) -> iced::widget::Row<Message, Renderer> {
|
||||
iced::widget::row(children)
|
||||
.align_items(iced::Alignment::Center)
|
||||
.padding([0, 8])
|
||||
.spacing(12)
|
||||
}
|
||||
|
||||
17
src/widget/settings/mod.rs
Normal file
17
src/widget/settings/mod.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright 2022 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
mod item;
|
||||
mod section;
|
||||
|
||||
pub use self::item::{item, item_row};
|
||||
pub use self::section::{Section, view_section};
|
||||
|
||||
use crate::{Element, Renderer};
|
||||
use iced::widget::{Column, column};
|
||||
|
||||
/// A column with a predefined style for creating a settings panel
|
||||
#[must_use]
|
||||
pub fn view_column<Message: 'static>(children: Vec<Element<Message>>) -> Column<Message, Renderer> {
|
||||
column(children).spacing(24).padding(24).max_width(600)
|
||||
}
|
||||
39
src/widget/settings/section.rs
Normal file
39
src/widget/settings/section.rs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
// Copyright 2022 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use crate::{Element};
|
||||
use crate::widget::{ListColumn};
|
||||
use iced::widget::{column, text};
|
||||
|
||||
/// A section within a settings view column.
|
||||
#[must_use]
|
||||
pub fn view_section<Message: 'static>(
|
||||
title: &str,
|
||||
) -> Section<Message> {
|
||||
Section { title, children: ListColumn::default() }
|
||||
}
|
||||
|
||||
pub struct Section<'a, Message> {
|
||||
title: &'a str,
|
||||
children: ListColumn<'a, Message>
|
||||
}
|
||||
|
||||
impl<'a, Message: 'static> Section<'a, Message> {
|
||||
#[must_use]
|
||||
pub fn add(mut self, item: impl Into<Element<'a, Message>>) -> Self {
|
||||
self.children = self.children.add(item.into());
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Message: 'static> From<Section<'a, Message>> for Element<'a, Message> {
|
||||
fn from(data: Section<'a, Message>) -> Self {
|
||||
let title = text(data.title)
|
||||
.font(crate::font::FONT_SEMIBOLD)
|
||||
.into();
|
||||
|
||||
column(vec![title, data.children.into_element()])
|
||||
.spacing(8)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue