Process a character input event for the focused text input. Returns true if the character was consumed by a text input.
(&mut self, ch: char)
| 5978 | /// Process a character input event for the focused text input. |
| 5979 | /// Returns true if the character was consumed by a text input. |
| 5980 | pub fn process_text_input_char(&mut self, ch: char) -> bool { |
| 5981 | if !self.is_text_input_focused() { |
| 5982 | return false; |
| 5983 | } |
| 5984 | let elem_id = self.focused_element_id; |
| 5985 | |
| 5986 | // Get max_length from current config (if available this frame) |
| 5987 | let max_length = self.text_input_element_ids.iter() |
| 5988 | .position(|&id| id == elem_id) |
| 5989 | .and_then(|idx| self.text_input_configs.get(idx)) |
| 5990 | .and_then(|cfg| cfg.max_length); |
| 5991 | |
| 5992 | if let Some(state) = self.text_edit_states.get_mut(&elem_id) { |
| 5993 | let old_text = state.text.clone(); |
| 5994 | state.push_undo(crate::text_input::UndoActionKind::InsertChar); |
| 5995 | #[cfg(feature = "text-styling")] |
| 5996 | { |
| 5997 | state.insert_char_styled(ch, max_length); |
| 5998 | } |
| 5999 | #[cfg(not(feature = "text-styling"))] |
| 6000 | { |
| 6001 | state.insert_text(&ch.to_string(), max_length); |
| 6002 | } |
| 6003 | if state.text != old_text { |
| 6004 | let new_text = state.text.clone(); |
| 6005 | // Fire on_changed callback |
| 6006 | if let Some(item) = self.layout_element_map.get_mut(&elem_id) { |
| 6007 | if let Some(ref mut callback) = item.on_text_changed_fn { |
| 6008 | callback(&new_text); |
| 6009 | } |
| 6010 | } |
| 6011 | } |
| 6012 | true |
| 6013 | } else { |
| 6014 | false |
| 6015 | } |
| 6016 | } |
| 6017 | |
| 6018 | /// Process a key event for the focused text input. |
| 6019 | /// `action` specifies which editing action to perform. |
no test coverage detected