From 26400b5fcd9e628169a770b3e33180b573de19cd Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Tue, 27 Feb 2024 19:10:14 +0100 Subject: [PATCH] fix(stack): get gradient colors from theme --- src/shell/element/stack/tab.rs | 17 ++++++--------- src/shell/element/stack/tab_text.rs | 33 ++++++++++++----------------- 2 files changed, 20 insertions(+), 30 deletions(-) diff --git a/src/shell/element/stack/tab.rs b/src/shell/element/stack/tab.rs index 2ea045f0..0fd522be 100644 --- a/src/shell/element/stack/tab.rs +++ b/src/shell/element/stack/tab.rs @@ -225,17 +225,12 @@ impl Tab { .padding([2, 4]) .center_y() .into(), - cosmic::Element::::new( - tab_text(self.title) - .font(self.font) - .font_size(14.0) - .background( - self.background_theme - .background_color(&cosmic::theme::active()), - ) - .height(Length::Fill) - .width(Length::Fill), - ), + tab_text(self.title) + .font(self.font) + .font_size(14.0) + .height(Length::Fill) + .width(Length::Fill) + .into(), close_button .apply(widget::container) .height(Length::Fill) diff --git a/src/shell/element/stack/tab_text.rs b/src/shell/element/stack/tab_text.rs index a94e9ac9..d2132831 100644 --- a/src/shell/element/stack/tab_text.rs +++ b/src/shell/element/stack/tab_text.rs @@ -15,7 +15,7 @@ use cosmic::{ /// Text in a stack tab with an overflow gradient. pub fn tab_text(text: String) -> TabText { - TabText::new(text, Color::TRANSPARENT) + TabText::new(text) } struct LocalState { @@ -27,7 +27,6 @@ struct LocalState { /// Text in a stack tab with an overflow gradient. pub struct TabText { text: String, - background: Color, font: cosmic::font::Font, font_size: f32, height: Length, @@ -35,22 +34,16 @@ pub struct TabText { } impl TabText { - pub fn new(text: String, background: Color) -> Self { + pub fn new(text: String) -> Self { TabText { width: Length::Shrink, height: Length::Shrink, - background, font: cosmic::font::DEFAULT, font_size: 14.0, text, } } - pub fn background(mut self, background: Color) -> Self { - self.background = background; - self - } - pub fn font(mut self, font: cosmic::font::Font) -> Self { self.font = font; self @@ -138,7 +131,7 @@ impl Widget for TabText { &self, tree: &Tree, renderer: &mut cosmic::Renderer, - _theme: &cosmic::Theme, + theme: &cosmic::Theme, style: &renderer::Style, layout: Layout<'_>, _cursor: Cursor, @@ -157,25 +150,27 @@ impl Widget for TabText { }); if state.overflowed { - let gradient_bounds = Rectangle { - x: (bounds.x + bounds.width - 24.).max(bounds.x), - width: 24.0_f32.min(bounds.width), - ..bounds + let background = super::tab::primary_container_color(theme.cosmic()); + let transparent = Color { + a: 0.0, + ..background }; - let mut transparent_background = self.background; - transparent_background.a = 0.0; renderer.fill_quad( renderer::Quad { - bounds: gradient_bounds, + bounds: Rectangle { + x: (bounds.x + bounds.width - 24.).max(bounds.x), + width: 24.0_f32.min(bounds.width), + ..bounds + }, border_radius: 0.0.into(), border_width: 0.0, border_color: Color::TRANSPARENT, }, Background::Gradient(Gradient::Linear( gradient::Linear::new(Degrees(90.)) - .add_stop(0.0, transparent_background) - .add_stop(1.0, self.background), + .add_stop(0.0, transparent) + .add_stop(1.0, background), )), ); }