diff options
author | 2023-09-09 12:36:00 +0200 | |
---|---|---|
committer | 2023-09-09 12:36:00 +0200 | |
commit | 3cc605b70f543313cb665465ac169d0c85c446ab (patch) | |
tree | 476ac7e6613e1c54fa4d53579be1d44b0246deb1 /widget/src/text_input.rs | |
parent | 3450987355be7fe029db112474d06613929b54c7 (diff) | |
download | iced-3cc605b70f543313cb665465ac169d0c85c446ab.tar.gz iced-3cc605b70f543313cb665465ac169d0c85c446ab.tar.bz2 iced-3cc605b70f543313cb665465ac169d0c85c446ab.zip |
Implement `Icon` support for `TextInput`
Diffstat (limited to 'widget/src/text_input.rs')
-rw-r--r-- | widget/src/text_input.rs | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/widget/src/text_input.rs b/widget/src/text_input.rs index f36b5616..aa35b5e4 100644 --- a/widget/src/text_input.rs +++ b/widget/src/text_input.rs @@ -511,7 +511,20 @@ where ); if let Some(icon) = icon { - let icon_width = 0.0; // TODO + let icon_text = Text { + line_height, + content: &icon.code_point.to_string(), + font: icon.font, + size: icon.size.unwrap_or_else(|| renderer.default_size()), + bounds: Size::new(f32::INFINITY, text_bounds.height), + horizontal_alignment: alignment::Horizontal::Center, + vertical_alignment: alignment::Vertical::Center, + shaping: text::Shaping::Advanced, + }; + + renderer.update_paragraph(&mut state.icon, icon_text); + + let icon_width = state.icon.min_width(); let mut text_node = layout::Node::new( text_bounds - Size::new(icon_width + icon.spacing, 0.0), @@ -1053,10 +1066,14 @@ pub fn draw<Renderer>( appearance.background, ); - if let Some(_icon) = icon { - let _icon_layout = children_layout.next().unwrap(); + if icon.is_some() { + let icon_layout = children_layout.next().unwrap(); - // TODO + renderer.fill_paragraph( + &state.icon, + icon_layout.bounds().center(), + appearance.icon_color, + ); } let text = value.to_string(); @@ -1206,6 +1223,7 @@ pub fn mouse_interaction( pub struct State<P: text::Paragraph> { value: P, placeholder: P, + icon: P, is_focused: Option<Focus>, is_dragging: bool, is_pasting: Option<Value>, @@ -1233,6 +1251,7 @@ impl<P: text::Paragraph> State<P> { Self { value: P::default(), placeholder: P::default(), + icon: P::default(), is_focused: None, is_dragging: false, is_pasting: None, |