From 038063f781c5cc532ea739b8da2ca07d390b77ad Mon Sep 17 00:00:00 2001 From: "Osma S. Rautila" <44613540+xosxos@users.noreply.github.com> Date: Fri, 27 Dec 2024 19:09:24 +0200 Subject: [PATCH] Add `text_color` to `toggler::Style` --- widget/src/toggler.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/widget/src/toggler.rs b/widget/src/toggler.rs index 7910c210..8eaf3372 100644 --- a/widget/src/toggler.rs +++ b/widget/src/toggler.rs @@ -388,7 +388,7 @@ where tree: &Tree, renderer: &mut Renderer, theme: &Theme, - style: &renderer::Style, + defaults: &renderer::Style, layout: Layout<'_>, _cursor: mouse::Cursor, viewport: &Rectangle, @@ -400,6 +400,9 @@ where let mut children = layout.children(); let toggler_layout = children.next().unwrap(); + let style = theme + .style(&self.class, self.last_status.unwrap_or(Status::Disabled)); + if self.label.is_some() { let label_layout = children.next().unwrap(); let state: &widget::text::State = @@ -407,17 +410,17 @@ where crate::text::draw( renderer, - style, + defaults, label_layout.bounds(), state.raw(), - crate::text::Style::default(), + crate::text::Style { + color: style.text_color, + }, viewport, ); } let bounds = toggler_layout.bounds(); - let style = theme - .style(&self.class, self.last_status.unwrap_or(Status::Disabled)); let border_radius = bounds.height / 2.0; let space = (SPACE_RATIO * bounds.height).round(); @@ -515,6 +518,8 @@ pub struct Style { pub foreground_border_width: f32, /// The [`Color`] of the foreground border of the toggler. pub foreground_border_color: Color, + /// The text [`Color`] of the toggler. + pub text_color: Option, } /// The theme catalog of a [`Toggler`]. @@ -589,5 +594,6 @@ pub fn default(theme: &Theme, status: Status) -> Style { foreground_border_color: Color::TRANSPARENT, background_border_width: 0.0, background_border_color: Color::TRANSPARENT, + text_color: None, } }