element/stack: Style fixes

This commit is contained in:
Victoria Brekenfeld 2024-07-26 14:59:11 +02:00
parent 04b5c18a03
commit 61f11d1363
5 changed files with 27 additions and 15 deletions

View file

@ -21,7 +21,7 @@ use cosmic::{
iced_core::{border::Radius, Background, Border, Color, Length}, iced_core::{border::Radius, Background, Border, Color, Length},
iced_runtime::Command, iced_runtime::Command,
iced_widget::scrollable::AbsoluteOffset, 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 cosmic_settings_config::shortcuts;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
@ -969,6 +969,7 @@ impl Program for CosmicStackInternal {
pixels: &mut tiny_skia::PixmapMut<'_>, pixels: &mut tiny_skia::PixmapMut<'_>,
damage: &[Rectangle<i32, Buffer>], damage: &[Rectangle<i32, Buffer>],
scale: f32, scale: f32,
theme: &Theme,
) { ) {
if self.group_focused.load(Ordering::SeqCst) { if self.group_focused.load(Ordering::SeqCst) {
let border = Rectangle::from_loc_and_size( let border = Rectangle::from_loc_and_size(
@ -977,7 +978,7 @@ impl Program for CosmicStackInternal {
); );
let mut paint = tiny_skia::Paint::default(); 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()); paint.set_color(tiny_skia::Color::from_rgba(r, g, b, a).unwrap());
for rect in damage { for rect in damage {

View file

@ -34,8 +34,8 @@ pub(super) fn primary_container_color(theme: &cosmic::cosmic_theme::Theme) -> Co
/// The background color for the selected stack tab. /// The background color for the selected stack tab.
pub(super) fn selected_state_color(theme: &cosmic::cosmic_theme::Theme) -> Color { 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_DARK: Color = Color::from_rgba(0.195, 0.195, 0.195, 1.0);
const SELECTED_STATE_LIGHT: Color = Color::from_rgba(0.596, 0.596, 0.596, 0.2); const SELECTED_STATE_LIGHT: Color = Color::from_rgba(0.8344, 0.8344, 0.8344, 1.0);
if theme.is_dark { if theme.is_dark {
SELECTED_STATE_DARK SELECTED_STATE_DARK
@ -231,7 +231,7 @@ impl<Message: TabMessage + 'static> Tab<Message> {
.padding([2, 4]) .padding([2, 4])
.center_y() .center_y()
.into(), .into(),
tab_text(self.title) tab_text(self.title, self.active)
.font(self.font) .font(self.font)
.font_size(14.0) .font_size(14.0)
.height(Length::Fill) .height(Length::Fill)

View file

@ -14,8 +14,8 @@ use cosmic::{
}; };
/// Text in a stack tab with an overflow gradient. /// Text in a stack tab with an overflow gradient.
pub fn tab_text(text: String) -> TabText { pub fn tab_text(text: String, selected: bool) -> TabText {
TabText::new(text) TabText::new(text, selected)
} }
struct LocalState { struct LocalState {
@ -29,17 +29,19 @@ pub struct TabText {
text: String, text: String,
font: cosmic::font::Font, font: cosmic::font::Font,
font_size: f32, font_size: f32,
selected: bool,
height: Length, height: Length,
width: Length, width: Length,
} }
impl TabText { impl TabText {
pub fn new(text: String) -> Self { pub fn new(text: String, selected: bool) -> Self {
TabText { TabText {
width: Length::Shrink, width: Length::Shrink,
height: Length::Shrink, height: Length::Shrink,
font: cosmic::font::DEFAULT, font: cosmic::font::DEFAULT,
font_size: 14.0, font_size: 14.0,
selected,
text, text,
} }
} }
@ -146,7 +148,11 @@ impl<Message> Widget<Message, cosmic::Theme, cosmic::Renderer> for TabText {
}); });
if state.overflowed { 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 { let transparent = Color {
a: 0.0, a: 0.0,
..background ..background

View file

@ -14,7 +14,7 @@ use crate::{
}, },
}; };
use calloop::LoopHandle; 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::{ use smithay::{
backend::{ backend::{
input::KeyState, input::KeyState,
@ -496,6 +496,7 @@ impl Program for CosmicWindowInternal {
pixels: &mut tiny_skia::PixmapMut<'_>, pixels: &mut tiny_skia::PixmapMut<'_>,
_damage: &[Rectangle<i32, BufferCoords>], _damage: &[Rectangle<i32, BufferCoords>],
scale: f32, scale: f32,
_theme: &Theme,
) { ) {
let mut mask = self.mask.lock().unwrap(); let mut mask = self.mask.lock().unwrap();
if self.window.is_maximized(false) { if self.window.is_maximized(false) {

View file

@ -119,8 +119,9 @@ pub trait Program {
pixels: &mut tiny_skia::PixmapMut<'_>, pixels: &mut tiny_skia::PixmapMut<'_>,
damage: &[Rectangle<i32, BufferCoords>], damage: &[Rectangle<i32, BufferCoords>],
scale: f32, 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 state_ref = &internal_ref.state;
let mut clip_mask = tiny_skia::Mask::new(size.w as u32, size.h as u32).unwrap(); let mut clip_mask = tiny_skia::Mask::new(size.w as u32, size.h as u32).unwrap();
let overlay = internal_ref.debug.overlay(); let overlay = internal_ref.debug.overlay();
let theme = &internal_ref.theme;
buffer buffer
.render() .render()
@ -930,10 +932,12 @@ where
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
state_ref state_ref.program().0.foreground(
.program() &mut pixels,
.0 &damage,
.foreground(&mut pixels, &damage, scale.x as f32); scale.x as f32,
theme,
);
Result::<_, ()>::Ok(damage) Result::<_, ()>::Ok(damage)
}) })