fix(stack): get gradient colors from theme
This commit is contained in:
parent
e7cf8581cc
commit
26400b5fcd
2 changed files with 20 additions and 30 deletions
|
|
@ -225,17 +225,12 @@ impl<Message: TabMessage + 'static> Tab<Message> {
|
||||||
.padding([2, 4])
|
.padding([2, 4])
|
||||||
.center_y()
|
.center_y()
|
||||||
.into(),
|
.into(),
|
||||||
cosmic::Element::<Message>::new(
|
tab_text(self.title)
|
||||||
tab_text(self.title)
|
.font(self.font)
|
||||||
.font(self.font)
|
.font_size(14.0)
|
||||||
.font_size(14.0)
|
.height(Length::Fill)
|
||||||
.background(
|
.width(Length::Fill)
|
||||||
self.background_theme
|
.into(),
|
||||||
.background_color(&cosmic::theme::active()),
|
|
||||||
)
|
|
||||||
.height(Length::Fill)
|
|
||||||
.width(Length::Fill),
|
|
||||||
),
|
|
||||||
close_button
|
close_button
|
||||||
.apply(widget::container)
|
.apply(widget::container)
|
||||||
.height(Length::Fill)
|
.height(Length::Fill)
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ 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) -> TabText {
|
||||||
TabText::new(text, Color::TRANSPARENT)
|
TabText::new(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LocalState {
|
struct LocalState {
|
||||||
|
|
@ -27,7 +27,6 @@ struct LocalState {
|
||||||
/// Text in a stack tab with an overflow gradient.
|
/// Text in a stack tab with an overflow gradient.
|
||||||
pub struct TabText {
|
pub struct TabText {
|
||||||
text: String,
|
text: String,
|
||||||
background: Color,
|
|
||||||
font: cosmic::font::Font,
|
font: cosmic::font::Font,
|
||||||
font_size: f32,
|
font_size: f32,
|
||||||
height: Length,
|
height: Length,
|
||||||
|
|
@ -35,22 +34,16 @@ pub struct TabText {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TabText {
|
impl TabText {
|
||||||
pub fn new(text: String, background: Color) -> Self {
|
pub fn new(text: String) -> Self {
|
||||||
TabText {
|
TabText {
|
||||||
width: Length::Shrink,
|
width: Length::Shrink,
|
||||||
height: Length::Shrink,
|
height: Length::Shrink,
|
||||||
background,
|
|
||||||
font: cosmic::font::DEFAULT,
|
font: cosmic::font::DEFAULT,
|
||||||
font_size: 14.0,
|
font_size: 14.0,
|
||||||
text,
|
text,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn background(mut self, background: Color) -> Self {
|
|
||||||
self.background = background;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn font(mut self, font: cosmic::font::Font) -> Self {
|
pub fn font(mut self, font: cosmic::font::Font) -> Self {
|
||||||
self.font = font;
|
self.font = font;
|
||||||
self
|
self
|
||||||
|
|
@ -138,7 +131,7 @@ impl<Message> Widget<Message, cosmic::Renderer> for TabText {
|
||||||
&self,
|
&self,
|
||||||
tree: &Tree,
|
tree: &Tree,
|
||||||
renderer: &mut cosmic::Renderer,
|
renderer: &mut cosmic::Renderer,
|
||||||
_theme: &cosmic::Theme,
|
theme: &cosmic::Theme,
|
||||||
style: &renderer::Style,
|
style: &renderer::Style,
|
||||||
layout: Layout<'_>,
|
layout: Layout<'_>,
|
||||||
_cursor: Cursor,
|
_cursor: Cursor,
|
||||||
|
|
@ -157,25 +150,27 @@ impl<Message> Widget<Message, cosmic::Renderer> for TabText {
|
||||||
});
|
});
|
||||||
|
|
||||||
if state.overflowed {
|
if state.overflowed {
|
||||||
let gradient_bounds = Rectangle {
|
let background = super::tab::primary_container_color(theme.cosmic());
|
||||||
x: (bounds.x + bounds.width - 24.).max(bounds.x),
|
let transparent = Color {
|
||||||
width: 24.0_f32.min(bounds.width),
|
a: 0.0,
|
||||||
..bounds
|
..background
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut transparent_background = self.background;
|
|
||||||
transparent_background.a = 0.0;
|
|
||||||
renderer.fill_quad(
|
renderer.fill_quad(
|
||||||
renderer::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_radius: 0.0.into(),
|
||||||
border_width: 0.0,
|
border_width: 0.0,
|
||||||
border_color: Color::TRANSPARENT,
|
border_color: Color::TRANSPARENT,
|
||||||
},
|
},
|
||||||
Background::Gradient(Gradient::Linear(
|
Background::Gradient(Gradient::Linear(
|
||||||
gradient::Linear::new(Degrees(90.))
|
gradient::Linear::new(Degrees(90.))
|
||||||
.add_stop(0.0, transparent_background)
|
.add_stop(0.0, transparent)
|
||||||
.add_stop(1.0, self.background),
|
.add_stop(1.0, background),
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue