pub struct TextCallbackData(/* private fields */);Expand description
This struct provides methods to edit the underlying text buffer that Dear ImGui manipulates. Primarily, it gives remove_chars, insert_chars, and mutable access to what text is selected.
Implementations§
Source§impl TextCallbackData
impl TextCallbackData
Sourcepub fn cursor_pos(&self) -> usize
pub fn cursor_pos(&self) -> usize
Get the current cursor position
Sourcepub fn set_cursor_pos(&mut self, pos: usize)
pub fn set_cursor_pos(&mut self, pos: usize)
Set the cursor position
Sourcepub fn selection_start(&self) -> usize
pub fn selection_start(&self) -> usize
Get the selection start position
Sourcepub fn set_selection_start(&mut self, pos: usize)
pub fn set_selection_start(&mut self, pos: usize)
Set the selection start position
Sourcepub fn selection_end(&self) -> usize
pub fn selection_end(&self) -> usize
Get the selection end position
Sourcepub fn set_selection_end(&mut self, pos: usize)
pub fn set_selection_end(&mut self, pos: usize)
Set the selection end position
Sourcepub fn select_all(&mut self)
pub fn select_all(&mut self)
Select all text
Sourcepub fn clear_selection(&mut self)
pub fn clear_selection(&mut self)
Clear selection
Sourcepub fn has_selection(&self) -> bool
pub fn has_selection(&self) -> bool
Returns true if there is a selection
Sourcepub fn remove_chars(&mut self, pos: usize, bytes_count: usize)
pub fn remove_chars(&mut self, pos: usize, bytes_count: usize)
Delete characters in the range [pos, pos+bytes_count)
Sourcepub fn insert_chars(&mut self, pos: usize, text: &str)
pub fn insert_chars(&mut self, pos: usize, text: &str)
Insert text at the given position
Sourcepub unsafe fn str_as_bytes_mut(&mut self) -> &mut [u8] ⓘ
pub unsafe fn str_as_bytes_mut(&mut self) -> &mut [u8] ⓘ
Gives access to the underlying byte array MUTABLY.
§Safety
This is very unsafe, and the following invariants must be upheld:
- Keep the data utf8 valid.
- After editing the string, call set_dirty.
To truncate the string, please use remove_chars. To extend the string, please use insert_chars and push_str.
This function should have highly limited usage, but could be for editing certain characters in the buffer based on some external condition.
Sourcepub fn set_dirty(&mut self)
pub fn set_dirty(&mut self)
Sets the dirty flag on the text to imgui, indicating that it should reapply this string to its internal state.
NB: You only need to use this method if you’re using [str_as_bytes_mut].
If you use the helper methods remove_chars and insert_chars,
this will be set for you. However, this is no downside to setting
the dirty flag spuriously except the minor CPU time imgui will spend.