@@ -31,6 +31,7 @@ use crate::{
3131pub struct Params {
3232 pub text : Translation ,
3333 pub style : taffy:: Style ,
34+ pub color_checked : Option < Color > ,
3435 pub box_size : f32 ,
3536 pub checked : bool ,
3637 pub radio_group : Option < Rc < ComponentRadioGroup > > ,
@@ -43,6 +44,7 @@ impl Default for Params {
4344 Self {
4445 text : Translation :: from_raw_text ( "" ) ,
4546 style : Default :: default ( ) ,
47+ color_checked : None ,
4648 box_size : 24.0 ,
4749 checked : false ,
4850 radio_group : None ,
@@ -84,6 +86,8 @@ struct Data {
8486 id_label : WidgetID , // Label, parent of container
8587 value : Option < Rc < str > > , // arbitrary value assigned to the element
8688 radio_group : Option < Weak < ComponentRadioGroup > > ,
89+
90+ color_checked : Color ,
8791}
8892
8993pub struct ComponentCheckbox {
@@ -92,6 +96,8 @@ pub struct ComponentCheckbox {
9296 state : Rc < RefCell < State > > ,
9397}
9498
99+ const COLOR_UNCHECKED : Color = Color :: new ( 0.0 , 0.0 , 0.0 , 0.0 ) ;
100+
95101impl ComponentTrait for ComponentCheckbox {
96102 fn base ( & self ) -> & ComponentBase {
97103 & self . base
@@ -106,12 +112,9 @@ impl ComponentTrait for ComponentCheckbox {
106112 }
107113}
108114
109- const COLOR_CHECKED : Color = Color :: new ( 0.1 , 0.5 , 1.0 , 1.0 ) ;
110- const COLOR_UNCHECKED : Color = Color :: new ( 0.1 , 0.5 , 1.0 , 0.0 ) ;
111-
112115fn set_box_checked ( widgets : & layout:: WidgetMap , data : & Data , checked : bool ) {
113116 widgets. call ( data. id_inner_box , |rect : & mut WidgetRectangle | {
114- rect. params . color = if checked { COLOR_CHECKED } else { COLOR_UNCHECKED }
117+ rect. params . color = if checked { data . color_checked } else { COLOR_UNCHECKED }
115118 } ) ;
116119}
117120
@@ -315,6 +318,7 @@ fn register_event_mouse_release(
315318
316319pub fn construct ( ess : & mut ConstructEssentials , params : Params ) -> anyhow:: Result < ( WidgetPair , Rc < ComponentCheckbox > ) > {
317320 let mut style = params. style ;
321+ let theme = & ess. layout . state . theme ;
318322
319323 // force-override style
320324 style. flex_wrap = taffy:: FlexWrap :: NoWrap ;
@@ -343,6 +347,8 @@ pub fn construct(ess: &mut ConstructEssentials, params: Params) -> anyhow::Resul
343347 ( WLength :: Units ( 5.0 ) , WLength :: Units ( 8.0 ) )
344348 } ;
345349
350+ let color_checked = params. color_checked . unwrap_or ( theme. accent_color ) ;
351+
346352 let ( root, _) = ess. layout . add_child (
347353 ess. parent ,
348354 WidgetRectangle :: create ( WidgetRectangleParams {
@@ -383,7 +389,7 @@ pub fn construct(ess: &mut ConstructEssentials, params: Params) -> anyhow::Resul
383389 outer_box. id ,
384390 WidgetRectangle :: create ( WidgetRectangleParams {
385391 round : round_5,
386- color : if params. checked { COLOR_CHECKED } else { COLOR_UNCHECKED } ,
392+ color : if params. checked { color_checked } else { COLOR_UNCHECKED } ,
387393 ..Default :: default ( )
388394 } ) ,
389395 taffy:: Style {
@@ -413,6 +419,7 @@ pub fn construct(ess: &mut ConstructEssentials, params: Params) -> anyhow::Resul
413419 id_label : label. id ,
414420 value : params. value ,
415421 radio_group : params. radio_group . as_ref ( ) . map ( Rc :: downgrade) ,
422+ color_checked,
416423 } ) ;
417424
418425 let state = Rc :: new ( RefCell :: new ( State {
0 commit comments