Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add text_color to toggler Style #2707

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions widget/src/toggler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ where
tree: &Tree,
renderer: &mut Renderer,
theme: &Theme,
style: &renderer::Style,
defaults: &renderer::Style,
layout: Layout<'_>,
_cursor: mouse::Cursor,
viewport: &Rectangle,
Expand All @@ -395,24 +395,27 @@ 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<Renderer::Paragraph> =
tree.state.downcast_ref();

crate::text::draw(
renderer,
style,
defaults,
label_layout,
state.0.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 / BORDER_RADIUS_RATIO;
let space = SPACE_RATIO * bounds.height;
Expand Down Expand Up @@ -510,6 +513,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<Color>,
}

/// The theme catalog of a [`Toggler`].
Expand Down Expand Up @@ -584,5 +589,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,
}
}
Loading