@@ -5,8 +5,14 @@ use iced::widget::{
55 scrollable, slider, text, text_input, toggler, vertical_space,
66} ;
77use iced:: widget:: { Button , Column , Container , Slider } ;
8+ use iced:: Font ;
89use iced:: { Color , Element , Length , Renderer , Sandbox , Settings } ;
910
11+ const ICON_FONT : Font = Font :: External {
12+ name : "Icons" ,
13+ bytes : include_bytes ! ( "../fonts/icons.ttf" ) ,
14+ } ;
15+
1016pub fn main ( ) -> iced:: Result {
1117 env_logger:: init ( ) ;
1218
@@ -127,6 +133,7 @@ impl Steps {
127133 Step :: TextInput {
128134 value: String :: new( ) ,
129135 is_secure: false ,
136+ is_showing_icon: false ,
130137 } ,
131138 Step :: Debugger ,
132139 Step :: End ,
@@ -171,14 +178,32 @@ impl Steps {
171178
172179enum Step {
173180 Welcome ,
174- Slider { value : u8 } ,
175- RowsAndColumns { layout : Layout , spacing : u16 } ,
176- Text { size : u16 , color : Color } ,
177- Radio { selection : Option < Language > } ,
178- Toggler { can_continue : bool } ,
179- Image { width : u16 } ,
181+ Slider {
182+ value : u8 ,
183+ } ,
184+ RowsAndColumns {
185+ layout : Layout ,
186+ spacing : u16 ,
187+ } ,
188+ Text {
189+ size : u16 ,
190+ color : Color ,
191+ } ,
192+ Radio {
193+ selection : Option < Language > ,
194+ } ,
195+ Toggler {
196+ can_continue : bool ,
197+ } ,
198+ Image {
199+ width : u16 ,
200+ } ,
180201 Scrollable ,
181- TextInput { value : String , is_secure : bool } ,
202+ TextInput {
203+ value : String ,
204+ is_secure : bool ,
205+ is_showing_icon : bool ,
206+ } ,
182207 Debugger ,
183208 End ,
184209}
@@ -194,6 +219,7 @@ pub enum StepMessage {
194219 ImageWidthChanged ( u16 ) ,
195220 InputChanged ( String ) ,
196221 ToggleSecureInput ( bool ) ,
222+ ToggleTextInputIcon ( bool ) ,
197223 DebugToggled ( bool ) ,
198224 TogglerChanged ( bool ) ,
199225}
@@ -256,6 +282,14 @@ impl<'a> Step {
256282 * can_continue = value;
257283 }
258284 }
285+ StepMessage :: ToggleTextInputIcon ( toggle) => {
286+ if let Step :: TextInput {
287+ is_showing_icon, ..
288+ } = self
289+ {
290+ * is_showing_icon = toggle
291+ }
292+ }
259293 } ;
260294 }
261295
@@ -303,9 +337,11 @@ impl<'a> Step {
303337 Self :: rows_and_columns ( * layout, * spacing)
304338 }
305339 Step :: Scrollable => Self :: scrollable ( ) ,
306- Step :: TextInput { value, is_secure } => {
307- Self :: text_input ( value, * is_secure)
308- }
340+ Step :: TextInput {
341+ value,
342+ is_secure,
343+ is_showing_icon,
344+ } => Self :: text_input ( value, * is_secure, * is_showing_icon) ,
309345 Step :: Debugger => Self :: debugger ( debug) ,
310346 Step :: End => Self :: end ( ) ,
311347 }
@@ -530,15 +566,28 @@ impl<'a> Step {
530566 )
531567 }
532568
533- fn text_input ( value : & str , is_secure : bool ) -> Column < ' a , StepMessage > {
534- let text_input = text_input (
569+ fn text_input (
570+ value : & str ,
571+ is_secure : bool ,
572+ is_showing_icon : bool ,
573+ ) -> Column < ' a , StepMessage > {
574+ let mut text_input = text_input (
535575 "Type something to continue..." ,
536576 value,
537577 StepMessage :: InputChanged ,
538578 )
539579 . padding ( 10 )
540580 . size ( 30 ) ;
541581
582+ if is_showing_icon {
583+ text_input = text_input. icon ( text_input:: Icon {
584+ font : ICON_FONT ,
585+ code_point : '\u{e900}' ,
586+ size : Some ( 35 ) ,
587+ position : text_input:: IconPosition :: Right ,
588+ } ) ;
589+ }
590+
542591 Self :: container ( "Text input" )
543592 . push ( "Use a text input to ask for different kinds of information." )
544593 . push ( if is_secure {
@@ -551,6 +600,11 @@ impl<'a> Step {
551600 is_secure,
552601 StepMessage :: ToggleSecureInput ,
553602 ) )
603+ . push ( checkbox (
604+ "Show icon" ,
605+ is_showing_icon,
606+ StepMessage :: ToggleTextInputIcon ,
607+ ) )
554608 . push (
555609 "A text input produces a message every time it changes. It is \
556610 very easy to keep track of its contents:",
0 commit comments