From 61f11d13632fa42b402190fd741f0f683ba748ba Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Fri, 26 Jul 2024 14:59:11 +0200 Subject: [PATCH] element/stack: Style fixes --- src/shell/element/stack.rs | 5 +++-- src/shell/element/stack/tab.rs | 6 +++--- src/shell/element/stack/tab_text.rs | 14 ++++++++++---- src/shell/element/window.rs | 3 ++- src/utils/iced.rs | 14 +++++++++----- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/shell/element/stack.rs b/src/shell/element/stack.rs index 8489365b..26a592de 100644 --- a/src/shell/element/stack.rs +++ b/src/shell/element/stack.rs @@ -21,7 +21,7 @@ use cosmic::{ iced_core::{border::Radius, Background, Border, Color, Length}, iced_runtime::Command, iced_widget::scrollable::AbsoluteOffset, - theme, widget as cosmic_widget, Apply, Element as CosmicElement, + theme, widget as cosmic_widget, Apply, Element as CosmicElement, Theme, }; use cosmic_settings_config::shortcuts; use once_cell::sync::Lazy; @@ -969,6 +969,7 @@ impl Program for CosmicStackInternal { pixels: &mut tiny_skia::PixmapMut<'_>, damage: &[Rectangle], scale: f32, + theme: &Theme, ) { if self.group_focused.load(Ordering::SeqCst) { let border = Rectangle::from_loc_and_size( @@ -977,7 +978,7 @@ impl Program for CosmicStackInternal { ); let mut paint = tiny_skia::Paint::default(); - let (b, g, r, a) = theme::COSMIC_DARK.accent_color().into_components(); + let (b, g, r, a) = theme.cosmic().accent_color().into_components(); paint.set_color(tiny_skia::Color::from_rgba(r, g, b, a).unwrap()); for rect in damage { diff --git a/src/shell/element/stack/tab.rs b/src/shell/element/stack/tab.rs index c787d5e0..28dd49e4 100644 --- a/src/shell/element/stack/tab.rs +++ b/src/shell/element/stack/tab.rs @@ -34,8 +34,8 @@ pub(super) fn primary_container_color(theme: &cosmic::cosmic_theme::Theme) -> Co /// The background color for the selected stack tab. pub(super) fn selected_state_color(theme: &cosmic::cosmic_theme::Theme) -> Color { - const SELECTED_STATE_DARK: Color = Color::from_rgba(0.302, 0.302, 0.302, 0.3); - const SELECTED_STATE_LIGHT: Color = Color::from_rgba(0.596, 0.596, 0.596, 0.2); + const SELECTED_STATE_DARK: Color = Color::from_rgba(0.195, 0.195, 0.195, 1.0); + const SELECTED_STATE_LIGHT: Color = Color::from_rgba(0.8344, 0.8344, 0.8344, 1.0); if theme.is_dark { SELECTED_STATE_DARK @@ -231,7 +231,7 @@ impl Tab { .padding([2, 4]) .center_y() .into(), - tab_text(self.title) + tab_text(self.title, self.active) .font(self.font) .font_size(14.0) .height(Length::Fill) diff --git a/src/shell/element/stack/tab_text.rs b/src/shell/element/stack/tab_text.rs index dc6ab81b..6b6da581 100644 --- a/src/shell/element/stack/tab_text.rs +++ b/src/shell/element/stack/tab_text.rs @@ -14,8 +14,8 @@ use cosmic::{ }; /// Text in a stack tab with an overflow gradient. -pub fn tab_text(text: String) -> TabText { - TabText::new(text) +pub fn tab_text(text: String, selected: bool) -> TabText { + TabText::new(text, selected) } struct LocalState { @@ -29,17 +29,19 @@ pub struct TabText { text: String, font: cosmic::font::Font, font_size: f32, + selected: bool, height: Length, width: Length, } impl TabText { - pub fn new(text: String) -> Self { + pub fn new(text: String, selected: bool) -> Self { TabText { width: Length::Shrink, height: Length::Shrink, font: cosmic::font::DEFAULT, font_size: 14.0, + selected, text, } } @@ -146,7 +148,11 @@ impl Widget for TabText { }); if state.overflowed { - let background = super::tab::primary_container_color(theme.cosmic()); + let background = if self.selected { + super::tab::selected_state_color(theme.cosmic()) + } else { + super::tab::primary_container_color(theme.cosmic()) + }; let transparent = Color { a: 0.0, ..background diff --git a/src/shell/element/window.rs b/src/shell/element/window.rs index e1fd4f9e..f85f8f48 100644 --- a/src/shell/element/window.rs +++ b/src/shell/element/window.rs @@ -14,7 +14,7 @@ use crate::{ }, }; use calloop::LoopHandle; -use cosmic::{config::Density, iced::Command, widget::mouse_area, Apply}; +use cosmic::{config::Density, iced::Command, widget::mouse_area, Apply, Theme}; use smithay::{ backend::{ input::KeyState, @@ -496,6 +496,7 @@ impl Program for CosmicWindowInternal { pixels: &mut tiny_skia::PixmapMut<'_>, _damage: &[Rectangle], scale: f32, + _theme: &Theme, ) { let mut mask = self.mask.lock().unwrap(); if self.window.is_maximized(false) { diff --git a/src/utils/iced.rs b/src/utils/iced.rs index 5b74e873..81f28902 100644 --- a/src/utils/iced.rs +++ b/src/utils/iced.rs @@ -119,8 +119,9 @@ pub trait Program { pixels: &mut tiny_skia::PixmapMut<'_>, damage: &[Rectangle], scale: f32, + theme: &cosmic::Theme, ) { - let _ = (pixels, damage, scale); + let _ = (pixels, damage, scale, theme); } } @@ -881,6 +882,7 @@ where let state_ref = &internal_ref.state; let mut clip_mask = tiny_skia::Mask::new(size.w as u32, size.h as u32).unwrap(); let overlay = internal_ref.debug.overlay(); + let theme = &internal_ref.theme; buffer .render() @@ -930,10 +932,12 @@ where }) .collect::>(); - state_ref - .program() - .0 - .foreground(&mut pixels, &damage, scale.x as f32); + state_ref.program().0.foreground( + &mut pixels, + &damage, + scale.x as f32, + theme, + ); Result::<_, ()>::Ok(damage) })