Customizing the text color of a checkbox

I noticed that Text supports a default appearance, whereas Checkbox doesn’t.

Is there a specific reason for this? What should I do if I want to change the font color of a checkbox to white, but leave everything else as-is?

I believe yes, the text::Appearance is defined as:

pub struct Appearance {
    pub color: Option<Color>,

Here having color set to None means to use inherited color which is
the most common thing to do for some Text.

In comparison checkbox::Appearance is defined as:

pub struct Appearance {
    pub background: Background,
    pub icon_color: Color,
    pub border_radius: BorderRadius,
    pub border_width: f32,
    pub border_color: Color,
    pub text_color: Option<Color>,

Here defining a default for each of those values, seems more a question of taste than a logical one.

I’m not sure if I’m phrasing my question clearly. With container, I can do this:

container(/* ... */)
        .style(move |_: &_| container::Appearance {
            background: Some(Background::Color(Color::new(0.27, 0.02, 0.15, 1.0))),

I tried something similar for checkbox:

checkbox(/* ... */)
        .style(move |_: &_| container::Appearance {

Then I get this error:

the trait From<[closure@src\ 93:36]> is not implemented for iced::theme::Checkbox

I opened the documentation and noticed that the Appearances of text and container implement the Default trait, whereas Checkbox doesn’t.

So is there a simple way to override only the text color for checkbox? So without implementing checkbox::StyleSheet for a custom theme?

Yes you can create your own Style and apply it to your checkbox:

Yes you can use the Custom style for checkbox.

struct MyStyle;

checkbox(/* ... */)

Which requires the implementation of StyleSheet in iced::widget::checkbox - Rust.

use iced::widget::checkbox;

impl checkbox::StyleSheet for MyStyle {
    type Style = iced::Theme;

    fn active(&self, style: &Self::Style, is_checked: bool) -> checkbox::Appearance {...}
    fn hovered(&self, style: &Self::Style, is_checked: bool) -> checkbox::Appearance {...}

Here the “style” you are given to your active and hovered methods are actually.
The current theme, this means you can base your checkbox style on the Theme.
as iced::Theme implements checkbox::StyleSheet.

I hope this answers your question !

Okay, so with Checkbox I unfortunately cannot use Default::default() inline then. Can I load default values within the stylesheet implementation? I.e. override the text color and leave everything else at its system default value?