Draw a line edit with a button for clearing it.
(ui: &mut Ui, hint: &str, input: &mut String)
| 24 | |
| 25 | /// Draw a line edit with a button for clearing it. |
| 26 | pub fn clearable_line_edit(ui: &mut Ui, hint: &str, input: &mut String) { |
| 27 | let elem = TextEdit::singleline(input).hint_text(hint); |
| 28 | let edit_rect = ui.add(elem).rect; |
| 29 | |
| 30 | if !input.is_empty() { |
| 31 | let mut clear_origin = edit_rect.right_center(); |
| 32 | clear_origin.x -= 10.0; |
| 33 | |
| 34 | let clear_rect = Rect::from_center_size(clear_origin, Vec2::splat(15.0)); |
| 35 | let clear_widget = Button::new(icons::X).small().frame(false); |
| 36 | |
| 37 | let clear_resp = ui.put(clear_rect, clear_widget); |
| 38 | |
| 39 | if clear_resp.clicked() { |
| 40 | input.clear(); |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | /// Draw a line edit with a button for clearing it and optional right-aligned text. |
| 46 | pub fn clearable_line_edit_with_status( |
no outgoing calls
no test coverage detected