@@ -14,6 +14,17 @@ use crate::{
1414
1515pub use iced_style:: checkbox:: { Appearance , StyleSheet } ;
1616
17+ /// The icon in a [`Checkbox`].
18+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
19+ pub struct Icon < Font > {
20+ /// Font that will be used to display the `code_point`,
21+ pub font : Font ,
22+ /// The unicode code point that will be used as the icon.
23+ pub code_point : char ,
24+ /// Font size of the content.
25+ pub size : Option < u16 > ,
26+ }
27+
1728/// A box that can be checked.
1829///
1930/// # Example
4556 spacing : u16 ,
4657 text_size : Option < u16 > ,
4758 font : Renderer :: Font ,
59+ icon : Icon < Renderer :: Font > ,
4860 style : <Renderer :: Theme as StyleSheet >:: Style ,
4961}
5062
8092 spacing : Self :: DEFAULT_SPACING ,
8193 text_size : None ,
8294 font : Renderer :: Font :: default ( ) ,
95+ icon : Icon {
96+ font : Renderer :: ICON_FONT ,
97+ code_point : Renderer :: CHECKMARK_ICON ,
98+ size : None ,
99+ } ,
83100 style : Default :: default ( ) ,
84101 }
85102 }
@@ -116,6 +133,12 @@ where
116133 self
117134 }
118135
136+ /// Sets the [`Icon`] of the [`Checkbox`].
137+ pub fn icon ( mut self , icon : Icon < Renderer :: Font > ) -> Self {
138+ self . icon = icon;
139+ self
140+ }
141+
119142 /// Sets the style of the [`Checkbox`].
120143 pub fn style (
121144 mut self ,
@@ -243,17 +266,24 @@ where
243266 custom_style. background ,
244267 ) ;
245268
269+ let Icon {
270+ font,
271+ code_point,
272+ size,
273+ } = & self . icon ;
274+ let size = size. map ( f32:: from) . unwrap_or ( bounds. height * 0.7 ) ;
275+
246276 if self . is_checked {
247277 renderer. fill_text ( text:: Text {
248- content : & Renderer :: CHECKMARK_ICON . to_string ( ) ,
249- font : Renderer :: ICON_FONT ,
250- size : bounds . height * 0.7 ,
278+ content : & code_point . to_string ( ) ,
279+ font : font . clone ( ) ,
280+ size,
251281 bounds : Rectangle {
252282 x : bounds. center_x ( ) ,
253283 y : bounds. center_y ( ) ,
254284 ..bounds
255285 } ,
256- color : custom_style. checkmark_color ,
286+ color : custom_style. icon_color ,
257287 horizontal_alignment : alignment:: Horizontal :: Center ,
258288 vertical_alignment : alignment:: Vertical :: Center ,
259289 } ) ;
0 commit comments