feat: interface density

This commit is contained in:
Vukašin Vojinović 2024-09-10 15:33:31 +02:00 committed by Ashley Wulber
parent 10f02d9d6b
commit 3c88edb217
2 changed files with 58 additions and 0 deletions

View file

@ -3,6 +3,7 @@
//! Configurations available to libcosmic applications.
use crate::cosmic_theme::Spacing;
use cosmic_config::cosmic_config_derive::CosmicConfigEntry;
use cosmic_config::{Config, CosmicConfigEntry};
use serde::{Deserialize, Serialize};
@ -87,10 +88,66 @@ pub struct CosmicTk {
#[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: 2,
space_xxs: 4,
space_xs: 8,
space_s: 12,
space_m: 16,
space_l: 24,
space_xl: 32,
space_xxl: 48,
space_xxxl: 72,
},
Density::Spacious => Spacing {
space_none: 0,
space_xxxs: 4,
space_xxs: 8,
space_xs: 16,
space_s: 20,
space_m: 32,
space_l: 40,
space_xl: 56,
space_xxl: 72,
space_xxxl: 144,
},
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 {

View file

@ -280,6 +280,7 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> {
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),
};
// Creates the headerbar widget.