improv: use spacing variables in more places

This commit is contained in:
Vukašin Vojinović 2024-09-14 03:09:03 +02:00 • committed by Ashley Wulber
parent c312a86c83
commit 13ed47782d
No known key found for this signature in database
GPG key ID: 5216D4F46A90A820
3 changed files with 18 additions and 8 deletions

View file

@ -4,7 +4,7 @@
use iced_core::Padding; use iced_core::Padding;
use iced_style::container::StyleSheet; use iced_style::container::StyleSheet;
use crate::{widget::divider, Apply, Element}; use crate::{theme, widget::divider, Apply, Element};
pub fn list_column<'a, Message: 'static>() -> ListColumn<'a, Message> { pub fn list_column<'a, Message: 'static>() -> ListColumn<'a, Message> {
ListColumn::default() ListColumn::default()
@ -21,7 +21,7 @@ pub struct ListColumn<'a, Message> {
impl<'a, Message: 'static> Default for ListColumn<'a, Message> { impl<'a, Message: 'static> Default for ListColumn<'a, Message> {
fn default() -> Self { fn default() -> Self {
Self { Self {
spacing: 8, spacing: theme::THEME.lock().unwrap().cosmic().spacing.space_xxs,
padding: Padding::from(0), padding: Padding::from(0),
style: <crate::Theme as StyleSheet>::Style::List, style: <crate::Theme as StyleSheet>::Style::List,
children: Vec::with_capacity(4), children: Vec::with_capacity(4),

View file

@ -4,6 +4,7 @@
use std::borrow::Cow; use std::borrow::Cow;
use crate::{ use crate::{
theme,
widget::{column, container, flex_row, horizontal_space, row, text, FlexRow, Row}, widget::{column, container, flex_row, horizontal_space, row, text, FlexRow, Row},
Element, Element,
}; };
@ -29,10 +30,13 @@ pub fn item<'a, Message: 'static>(
#[must_use] #[must_use]
#[allow(clippy::module_name_repetitions)] #[allow(clippy::module_name_repetitions)]
pub fn item_row<Message>(children: Vec<Element<Message>>) -> Row<Message> { pub fn item_row<Message>(children: Vec<Element<Message>>) -> Row<Message> {
let cosmic_theme::Spacing {
space_s, space_xs, ..
} = theme::THEME.lock().unwrap().cosmic().spacing;
row::with_children(children) row::with_children(children)
.spacing(12) .spacing(space_xs)
.align_items(iced::Alignment::Center) .align_items(iced::Alignment::Center)
.padding([0, 16]) .padding([0, space_s])
} }
/// A settings item aligned in a flex row /// A settings item aligned in a flex row
@ -50,9 +54,12 @@ pub fn flex_item<'a, Message: 'static>(
/// A settings item aligned in a flex row /// A settings item aligned in a flex row
#[allow(clippy::module_name_repetitions)] #[allow(clippy::module_name_repetitions)]
pub fn flex_item_row<Message>(children: Vec<Element<Message>>) -> FlexRow<Message> { pub fn flex_item_row<Message>(children: Vec<Element<Message>>) -> FlexRow<Message> {
let cosmic_theme::Spacing {
space_s, space_xs, ..
} = theme::THEME.lock().unwrap().cosmic().spacing;
flex_row(children) flex_row(children)
.padding([0, 16]) .padding([0, space_s])
.spacing(12) .spacing(space_xs)
.min_item_width(200.0) .min_item_width(200.0)
.justify_items(iced::Alignment::Center) .justify_items(iced::Alignment::Center)
.justify_content(AlignContent::SpaceBetween) .justify_content(AlignContent::SpaceBetween)

View file

@ -8,10 +8,13 @@ pub use self::item::{flex_item, flex_item_row, item, item_row};
pub use self::section::{section, view_section, Section}; pub use self::section::{section, view_section, Section};
use crate::widget::{column, Column}; use crate::widget::{column, Column};
use crate::Element; use crate::{theme, Element};
/// A column with a predefined style for creating a settings panel /// A column with a predefined style for creating a settings panel
#[must_use] #[must_use]
pub fn view_column<Message: 'static>(children: Vec<Element<Message>>) -> Column<Message> { pub fn view_column<Message: 'static>(children: Vec<Element<Message>>) -> Column<Message> {
column::with_children(children).spacing(24).padding([0, 24]) let spacing = theme::THEME.lock().unwrap().cosmic().spacing;
column::with_children(children)
.spacing(spacing.space_m)
.padding([0, spacing.space_m])
} }