From c63ae8dd7ff0b8fefe3c938084f38115b85891bf Mon Sep 17 00:00:00 2001 From: Earthgames Date: Thu, 19 Mar 2026 16:50:46 +0100 Subject: [PATCH] Remove unchecked option and made it more rusty --- wgui/src/components/checkbox.rs | 31 +++++---------------------- wgui/src/parser/component_checkbox.rs | 1 - 2 files changed, 5 insertions(+), 27 deletions(-) diff --git a/wgui/src/components/checkbox.rs b/wgui/src/components/checkbox.rs index 5cef8f1c..552e7ed6 100644 --- a/wgui/src/components/checkbox.rs +++ b/wgui/src/components/checkbox.rs @@ -32,7 +32,6 @@ pub struct Params { pub text: Translation, pub style: taffy::Style, pub color_checked: Option, - pub color_unchecked: Option, pub box_size: f32, pub checked: bool, pub radio_group: Option>, @@ -46,7 +45,6 @@ impl Default for Params { text: Translation::from_raw_text(""), style: Default::default(), color_checked: None, - color_unchecked: None, box_size: 24.0, checked: false, radio_group: None, @@ -90,7 +88,6 @@ struct Data { radio_group: Option>, color_checked: Color, - color_unchecked: Color, } pub struct ComponentCheckbox { @@ -99,6 +96,8 @@ pub struct ComponentCheckbox { state: Rc>, } +const COLOR_UNCHECKED: Color = Color::new(0.0, 0.0, 0.0, 0.0); + impl ComponentTrait for ComponentCheckbox { fn base(&self) -> &ComponentBase { &self.base @@ -115,11 +114,7 @@ impl ComponentTrait for ComponentCheckbox { fn set_box_checked(widgets: &layout::WidgetMap, data: &Data, checked: bool) { widgets.call(data.id_inner_box, |rect: &mut WidgetRectangle| { - rect.params.color = if checked { - data.color_checked - } else { - data.color_unchecked - } + rect.params.color = if checked { data.color_checked } else { COLOR_UNCHECKED } }); } @@ -352,22 +347,7 @@ pub fn construct(ess: &mut ConstructEssentials, params: Params) -> anyhow::Resul (WLength::Units(5.0), WLength::Units(8.0)) }; - let color_checked = if let Some(color) = params.color_checked { - color - } else { - theme.accent_color - }; - - let color_unchecked = if let Some(color) = params.color_unchecked { - color - } else { - Color { - r: color_checked.r, - g: color_checked.g, - b: color_checked.b, - a: 0.0, - } - }; + let color_checked = params.color_checked.unwrap_or(theme.accent_color); let (root, _) = ess.layout.add_child( ess.parent, @@ -409,7 +389,7 @@ pub fn construct(ess: &mut ConstructEssentials, params: Params) -> anyhow::Resul outer_box.id, WidgetRectangle::create(WidgetRectangleParams { round: round_5, - color: if params.checked { color_checked } else { color_unchecked }, + color: if params.checked { color_checked } else { COLOR_UNCHECKED }, ..Default::default() }), taffy::Style { @@ -440,7 +420,6 @@ pub fn construct(ess: &mut ConstructEssentials, params: Params) -> anyhow::Resul value: params.value, radio_group: params.radio_group.as_ref().map(Rc::downgrade), color_checked, - color_unchecked, }); let state = Rc::new(RefCell::new(State { diff --git a/wgui/src/parser/component_checkbox.rs b/wgui/src/parser/component_checkbox.rs index 38d71733..3f011422 100644 --- a/wgui/src/parser/component_checkbox.rs +++ b/wgui/src/parser/component_checkbox.rs @@ -92,7 +92,6 @@ pub fn parse_component_checkbox( value: component_value, tooltip: tooltip.get_info(), color_checked: None, - color_unchecked: None, }, )?;