fix: move density to cosmic_theme
This commit is contained in:
parent
69e6fb63fb
commit
0a34660a80
6 changed files with 85 additions and 71 deletions
|
|
@ -84,11 +84,14 @@ derive_setters = "0.1.5"
|
|||
fraction = "0.15.3"
|
||||
image = { version = "0.25.1", optional = true }
|
||||
lazy_static = "1.4.0"
|
||||
libc = { version = "0.2.155", optional = true }
|
||||
libc = { version = "0.2.155", optional = true }
|
||||
mime = { version = "0.3.17", optional = true }
|
||||
palette = "0.7.3"
|
||||
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"] }
|
||||
slotmap = "1.0.6"
|
||||
smol = { version = "2.0.0", optional = true }
|
||||
|
|
|
|||
65
cosmic-theme/src/model/density.rs
Normal file
65
cosmic-theme/src/model/density.rs
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
pub use corner::*;
|
||||
pub use cosmic_palette::*;
|
||||
pub use density::*;
|
||||
pub use derivation::*;
|
||||
pub use mode::*;
|
||||
pub use spacing::*;
|
||||
|
|
@ -7,6 +8,7 @@ pub use theme::*;
|
|||
|
||||
mod corner;
|
||||
mod cosmic_palette;
|
||||
mod density;
|
||||
mod derivation;
|
||||
mod mode;
|
||||
mod spacing;
|
||||
|
|
|
|||
|
|
@ -48,6 +48,8 @@ pub mod message {
|
|||
pub use self::command::Command;
|
||||
pub use self::core::Core;
|
||||
pub use self::settings::Settings;
|
||||
use crate::config::interface_density;
|
||||
use crate::cosmic_theme::Density;
|
||||
use crate::prelude::*;
|
||||
use crate::theme::THEME;
|
||||
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()
|
||||
.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 mut widgets = Vec::with_capacity(4);
|
||||
|
||||
|
|
@ -732,7 +739,7 @@ impl<App: Application> ApplicationExt for App {
|
|||
let content: Element<_> = if core.window.content_container {
|
||||
content_row
|
||||
.apply(crate::widget::container)
|
||||
.padding([0, 8, 8, 8])
|
||||
.padding([0, padding, padding, padding])
|
||||
.width(iced::Length::Fill)
|
||||
.height(iced::Length::Fill)
|
||||
.style(crate::theme::Container::WindowBackground)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
//! Configurations available to libcosmic applications.
|
||||
|
||||
use crate::cosmic_theme::Spacing;
|
||||
use crate::cosmic_theme::Density;
|
||||
use cosmic_config::cosmic_config_derive::CosmicConfigEntry;
|
||||
use cosmic_config::{Config, CosmicConfigEntry};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
@ -85,69 +85,6 @@ pub struct CosmicTk {
|
|||
pub interface_density: Density,
|
||||
}
|
||||
|
||||
#[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 - 16) < 1 {
|
||||
Self::Compact
|
||||
} else if (value.space_m - 24) < 1 {
|
||||
Self::Standard
|
||||
} else {
|
||||
Self::Spacious
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for CosmicTk {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright 2022 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use crate::config::Density;
|
||||
use crate::cosmic_theme::Density;
|
||||
use crate::{ext::CollectionWidget, widget, Element};
|
||||
use apply::Apply;
|
||||
use derive_setters::Setters;
|
||||
|
|
@ -278,9 +278,9 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> {
|
|||
end.push(self.window_controls());
|
||||
|
||||
let (height, padding) = match self.density.unwrap_or_else(crate::config::header_size) {
|
||||
crate::config::Density::Compact => (36.0, 2.0),
|
||||
crate::config::Density::Standard => (48.0, 8.0),
|
||||
crate::config::Density::Spacious => (48.0, 8.0),
|
||||
Density::Compact => (36.0, 2.0),
|
||||
Density::Spacious => (48.0, 8.0),
|
||||
Density::Standard => (48.0, 8.0),
|
||||
};
|
||||
|
||||
// Creates the headerbar widget.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue