From e645dee2f0b399485b756ac7d85b2c557b2a0e21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vuka=C5=A1in=20Vojinovi=C4=87?= Date: Wed, 2 Oct 2024 00:32:08 +0200 Subject: [PATCH] fix(header_bar): increase compact height Increases Compact header height to 40 (from 36), to better accommodate larger widgets (e.g. the search bar). This makes it distinct from the SSD header, which is now addressed by the `_` match case. Also makes the horizontal header padding fixed at 8, so that the app window padding can also be 8. --- cosmic-theme/src/model/density.rs | 4 ++++ res/icons/navbar-closed-symbolic.svg | 10 ++++++++++ res/icons/navbar-open-symbolic.svg | 8 ++++++++ src/app/core.rs | 2 +- src/app/mod.rs | 9 +-------- src/widget/header_bar.rs | 21 +++++++-------------- src/widget/nav_bar_toggle.rs | 4 ++-- src/widget/text_input/input.rs | 8 ++++---- 8 files changed, 37 insertions(+), 29 deletions(-) create mode 100644 res/icons/navbar-closed-symbolic.svg create mode 100644 res/icons/navbar-open-symbolic.svg diff --git a/cosmic-theme/src/model/density.rs b/cosmic-theme/src/model/density.rs index aa1685a..7655361 100644 --- a/cosmic-theme/src/model/density.rs +++ b/cosmic-theme/src/model/density.rs @@ -1,10 +1,14 @@ use crate::Spacing; use serde::{Deserialize, Serialize}; +/// Density options for the Cosmic theme #[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)] pub enum Density { + /// Lower padding/spacing of elements Compact, + /// Higher padding/spacing of elements Spacious, + /// Standard padding/spacing of elements #[default] Standard, } diff --git a/res/icons/navbar-closed-symbolic.svg b/res/icons/navbar-closed-symbolic.svg new file mode 100644 index 0000000..46f35e1 --- /dev/null +++ b/res/icons/navbar-closed-symbolic.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/res/icons/navbar-open-symbolic.svg b/res/icons/navbar-open-symbolic.svg new file mode 100644 index 0000000..c1f3216 --- /dev/null +++ b/res/icons/navbar-open-symbolic.svg @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/app/core.rs b/src/app/core.rs index ad9ca2a..eee5ae5 100644 --- a/src/app/core.rs +++ b/src/app/core.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; -use crate::{config::CosmicTk, widget::nav_bar}; +use crate::widget::nav_bar; use cosmic_config::CosmicConfigEntry; use cosmic_theme::ThemeMode; use iced::window; diff --git a/src/app/mod.rs b/src/app/mod.rs index 815051f..c703b32 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -48,8 +48,6 @@ 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}; @@ -654,11 +652,6 @@ impl 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); @@ -739,7 +732,7 @@ impl ApplicationExt for App { let content: Element<_> = if core.window.content_container { content_row .apply(crate::widget::container) - .padding([0, padding, padding, padding]) + .padding([0, 8, 8, 8]) .width(iced::Length::Fill) .height(iced::Length::Fill) .style(crate::theme::Container::WindowBackground) diff --git a/src/widget/header_bar.rs b/src/widget/header_bar.rs index eabb3cd..1f74510 100644 --- a/src/widget/header_bar.rs +++ b/src/widget/header_bar.rs @@ -277,10 +277,10 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> { end.push(widget::horizontal_space(Length::Fixed(12.0)).into()); end.push(self.window_controls()); - let (height, padding) = match self.density.unwrap_or_else(crate::config::header_size) { - Density::Compact => (36.0, 2.0), - Density::Spacious => (48.0, 8.0), - Density::Standard => (48.0, 8.0), + let height = match self.density.unwrap_or_else(crate::config::header_size) { + Density::Compact => 40.0, + Density::Spacious => 48.0, + Density::Standard => 48.0, }; // Creates the headerbar widget. @@ -316,8 +316,8 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> { ) .align_items(iced::Alignment::Center) .height(Length::Fixed(height)) - .padding(padding) - .spacing(padding) + .padding([0, 8]) + .spacing(8) .apply(widget::container) .style(crate::theme::Container::HeaderBar { focused: self.focused, @@ -387,13 +387,6 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> { }}; } - let density = self.density.unwrap_or_else(crate::config::header_size); - let spacing = if matches!(density, Density::Compact) { - 2 - } else { - 8 - }; - widget::row::with_capacity(3) .push_maybe( self.on_minimize @@ -410,7 +403,7 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> { .take() .map(|m| icon!("window-close-symbolic", 16, m)), ) - .spacing(spacing) + .spacing(8) .apply(widget::container) .height(Length::Fill) .center_y() diff --git a/src/widget/nav_bar_toggle.rs b/src/widget/nav_bar_toggle.rs index 06c7abd..68dd528 100644 --- a/src/widget/nav_bar_toggle.rs +++ b/src/widget/nav_bar_toggle.rs @@ -29,12 +29,12 @@ impl<'a, Message: 'static + Clone> From> for Element<'a, M fn from(nav_bar_toggle: NavBarToggle) -> Self { let icon = if nav_bar_toggle.active { widget::icon::from_svg_bytes( - &include_bytes!("../../res/icons/close-menu-symbolic.svg")[..], + &include_bytes!("../../res/icons/navbar-open-symbolic.svg")[..], ) .symbolic(true) } else { widget::icon::from_svg_bytes( - &include_bytes!("../../res/icons/open-menu-symbolic.svg")[..], + &include_bytes!("../../res/icons/navbar-closed-symbolic.svg")[..], ) .symbolic(true) }; diff --git a/src/widget/text_input/input.rs b/src/widget/text_input/input.rs index 343ae80..90a0f57 100644 --- a/src/widget/text_input/input.rs +++ b/src/widget/text_input/input.rs @@ -101,7 +101,7 @@ where let spacing = THEME.lock().unwrap().cosmic().space_xxs(); TextInput::new(placeholder, value) - .padding([0, spacing, 0, spacing]) + .padding([0, spacing]) .style(crate::theme::TextInput::Search) .leading_icon( crate::widget::icon::from_name("system-search-symbolic") @@ -125,7 +125,7 @@ where { let spacing = THEME.lock().unwrap().cosmic().space_xxs(); let mut input = TextInput::new(placeholder, value) - .padding([0, spacing, 0, spacing]) + .padding([0, spacing]) .style(crate::theme::TextInput::Default) .leading_icon( crate::widget::icon::from_name("system-lock-screen-symbolic") @@ -170,7 +170,7 @@ where TextInput::new(placeholder, value) .style(crate::theme::TextInput::Inline) - .padding([spacing, spacing, spacing, spacing]) + .padding(spacing) } #[cfg(feature = "wayland")] @@ -246,7 +246,7 @@ where select_on_focus: false, font: None, width: Length::Fill, - padding: [spacing, spacing, spacing, spacing].into(), + padding: spacing.into(), size: None, helper_size: 10.0, helper_line_height: text::LineHeight::Absolute(14.0.into()),