Merge pull request #1 from pop-os/git-f0x-rebase

Rebase
This commit is contained in:
Vukašin Vojinović 2024-09-23 18:02:06 +02:00 • committed by GitHub
commit 52a30bac63
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 113 additions and 30 deletions

View file

@ -88,7 +88,10 @@ libc = { version = "0.2.155", optional = true }
mime = { version = "0.3.17", optional = true } mime = { version = "0.3.17", optional = true }
palette = "0.7.3" palette = "0.7.3"
rfd = { version = "0.14.0", optional = true } rfd = { version = "0.14.0", optional = true }
rustix = { version = "0.38.34", features = ["pipe", "process"], optional = true } rustix = { version = "0.38.34", features = [
"pipe",
"process",
], optional = true }
serde = { version = "1.0.180", features = ["derive"] } serde = { version = "1.0.180", features = ["derive"] }
slotmap = "1.0.6" slotmap = "1.0.6"
smol = { version = "2.0.0", optional = true } smol = { version = "2.0.0", optional = true }

View file

@ -0,0 +1,65 @@
use crate::Spacing;
use serde::{Deserialize, Serialize};
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
pub enum Density {
Compact,
Spacious,
#[default]
Standard,
}
impl From<Density> for Spacing {
fn from(value: Density) -> Self {
match value {
Density::Compact => Spacing {
space_none: 0,
space_xxxs: 4,
space_xxs: 4,
space_xs: 8,
space_s: 8,
space_m: 16,
space_l: 24,
space_xl: 32,
space_xxl: 48,
space_xxxl: 64,
},
Density::Spacious => Spacing {
space_none: 4,
space_xxxs: 8,
space_xxs: 12,
space_xs: 16,
space_s: 24,
space_m: 32,
space_l: 48,
space_xl: 64,
space_xxl: 128,
space_xxxl: 160,
},
Density::Standard => Spacing {
space_none: 0,
space_xxxs: 4,
space_xxs: 8,
space_xs: 12,
space_s: 16,
space_m: 24,
space_l: 32,
space_xl: 48,
space_xxl: 64,
space_xxxl: 128,
},
}
}
}
impl From<Spacing> for Density {
fn from(value: Spacing) -> Self {
if value.space_m.saturating_sub(16) == 0 {
Self::Compact
} else if value.space_m.saturating_sub(24) == 0 {
Self::Standard
} else {
Self::Spacious
}
}
}

View file

@ -1,5 +1,6 @@
pub use corner::*; pub use corner::*;
pub use cosmic_palette::*; pub use cosmic_palette::*;
pub use density::*;
pub use derivation::*; pub use derivation::*;
pub use mode::*; pub use mode::*;
pub use spacing::*; pub use spacing::*;
@ -7,6 +8,7 @@ pub use theme::*;
mod corner; mod corner;
mod cosmic_palette; mod cosmic_palette;
mod density;
mod derivation; mod derivation;
mod mode; mod mode;
mod spacing; mod spacing;

View file

@ -48,6 +48,8 @@ pub mod message {
pub use self::command::Command; pub use self::command::Command;
pub use self::core::Core; pub use self::core::Core;
pub use self::settings::Settings; pub use self::settings::Settings;
use crate::config::interface_density;
use crate::cosmic_theme::Density;
use crate::prelude::*; use crate::prelude::*;
use crate::theme::THEME; use crate::theme::THEME;
use crate::widget::{context_drawer, horizontal_space, id_container, menu, nav_bar, popover}; use crate::widget::{context_drawer, horizontal_space, id_container, menu, nav_bar, popover};
@ -652,6 +654,11 @@ impl<App: Application> ApplicationExt for App {
.focused_window() .focused_window()
.is_some_and(|i| i == self.main_window_id()); .is_some_and(|i| i == self.main_window_id());
let padding = match interface_density() {
Density::Compact => 2,
_ => 8,
};
let content_row = crate::widget::row::with_children({ let content_row = crate::widget::row::with_children({
let mut widgets = Vec::with_capacity(4); let mut widgets = Vec::with_capacity(4);
@ -725,7 +732,7 @@ impl<App: Application> ApplicationExt for App {
let content: Element<_> = if core.window.content_container { let content: Element<_> = if core.window.content_container {
content_row content_row
.apply(crate::widget::container) .apply(crate::widget::container)
.padding([0, 8, 8, 8]) .padding([0, padding, padding, padding])
.width(iced::Length::Fill) .width(iced::Length::Fill)
.height(iced::Length::Fill) .height(iced::Length::Fill)
.style(crate::theme::Container::WindowBackground) .style(crate::theme::Container::WindowBackground)

View file

@ -3,6 +3,7 @@
//! Configurations available to libcosmic applications. //! Configurations available to libcosmic applications.
use crate::cosmic_theme::Density;
use cosmic_config::cosmic_config_derive::CosmicConfigEntry; use cosmic_config::cosmic_config_derive::CosmicConfigEntry;
use cosmic_config::{Config, CosmicConfigEntry}; use cosmic_config::{Config, CosmicConfigEntry};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -84,13 +85,6 @@ pub struct CosmicTk {
pub interface_density: Density, pub interface_density: Density,
} }
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
pub enum Density {
Compact,
#[default]
Standard,
}
impl Default for CosmicTk { impl Default for CosmicTk {
fn default() -> Self { fn default() -> Self {
Self { Self {

View file

@ -1,7 +1,7 @@
// Copyright 2022 System76 <info@system76.com> // Copyright 2022 System76 <info@system76.com>
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use crate::config::Density; use crate::cosmic_theme::Density;
use crate::{ext::CollectionWidget, widget, Element}; use crate::{ext::CollectionWidget, widget, Element};
use apply::Apply; use apply::Apply;
use derive_setters::Setters; use derive_setters::Setters;
@ -278,8 +278,9 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> {
end.push(self.window_controls()); end.push(self.window_controls());
let (height, padding) = match self.density.unwrap_or_else(crate::config::header_size) { let (height, padding) = match self.density.unwrap_or_else(crate::config::header_size) {
crate::config::Density::Compact => (36.0, 2.0), Density::Compact => (36.0, 2.0),
crate::config::Density::Standard => (48.0, 8.0), Density::Spacious => (48.0, 8.0),
Density::Standard => (48.0, 8.0),
}; };
// Creates the headerbar widget. // Creates the headerbar widget.
@ -361,7 +362,11 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> {
macro_rules! icon { macro_rules! icon {
($name:expr, $size:expr, $on_press:expr) => {{ ($name:expr, $size:expr, $on_press:expr) => {{
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
let icon = { widget::icon::from_name($name).apply(widget::button::icon) }; let icon = {
widget::icon::from_name($name)
.apply(widget::button::icon)
.padding(8)
};
#[cfg(not(target_os = "linux"))] #[cfg(not(target_os = "linux"))]
let icon = { let icon = {
@ -372,6 +377,7 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> {
))) )))
.symbolic(true) .symbolic(true)
.apply(widget::button::icon) .apply(widget::button::icon)
.padding(8)
}; };
icon.style(crate::theme::Button::HeaderBar) icon.style(crate::theme::Button::HeaderBar)

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])
} }

View file

@ -107,7 +107,7 @@ where
crate::widget::icon::from_name("system-search-symbolic") crate::widget::icon::from_name("system-search-symbolic")
.size(16) .size(16)
.apply(crate::widget::container) .apply(crate::widget::container)
.padding([spacing, spacing, spacing, spacing]) .padding(8)
.into(), .into(),
) )
} }
@ -131,7 +131,7 @@ where
crate::widget::icon::from_name("system-lock-screen-symbolic") crate::widget::icon::from_name("system-lock-screen-symbolic")
.size(16) .size(16)
.apply(crate::widget::container) .apply(crate::widget::container)
.padding([spacing, spacing, spacing, spacing]) .padding(8)
.into(), .into(),
); );
if hidden { if hidden {
@ -148,7 +148,7 @@ where
.apply(crate::widget::button::custom) .apply(crate::widget::button::custom)
.style(crate::theme::Button::Icon) .style(crate::theme::Button::Icon)
.on_press(msg) .on_press(msg)
.padding([spacing, spacing, spacing, spacing]) .padding(8)
.into(), .into(),
) )
} else { } else {
@ -496,17 +496,13 @@ where
} }
pub fn on_clear(self, on_clear: Message) -> Self { pub fn on_clear(self, on_clear: Message) -> Self {
let spacing = THEME.lock().unwrap().cosmic().space_xxs();
self.trailing_icon( self.trailing_icon(
crate::widget::icon::from_name("edit-clear-symbolic") crate::widget::icon::from_name("edit-clear-symbolic")
.size(16) .size(16)
.apply(crate::widget::button::custom) .apply(crate::widget::button::custom)
.style(crate::theme::Button::Icon) .style(crate::theme::Button::Icon)
.width(32)
.height(32)
.on_press(on_clear) .on_press(on_clear)
.padding([spacing, spacing, spacing, spacing]) .padding(8)
.into(), .into(),
) )
} }