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

source

pub fn str(&self) -> &str

Get a reference to the text callback buffer’s str.

source

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:

  1. Keep the data utf8 valid.
  2. 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.

source

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.

source

pub fn selection(&self) -> Range<usize>

Gets a range of the selected text. See selection_start_mut and selection_end_mut to mutably edit these values.

This Range is given in usize so that it might be used in indexing operations more easily. To quickly grab the selected text, use selected.

source

pub fn selected(&self) -> &str

Returns the selected text directly. Note that if no text is selected, an empty str slice will be returned.

source

pub fn select_all(&mut self)

Sets the cursor to select all.

source

pub fn clear_selection(&mut self)

Clears the selection.

source

pub fn has_selection(&self) -> bool

Checks if there is a selection within the text.

source

pub fn push_str(&mut self, s: &str)

Pushes the given str to the end of this buffer. If this would require the String to resize, it will be resized. This is automatically handled.

source

pub fn insert_chars(&mut self, pos: usize, s: &str)

Inserts the given string at the given position. If this would require the String to resize, it will be resized automatically.

§Panics

Panics if the pos is not a char_boundary.

source

pub unsafe fn insert_chars_unsafe(&mut self, pos: usize, s: &str)

Inserts the given string at the given position, unsafely. If this would require the String to resize, it will be resized automatically.

§Safety

It is up to the caller to confirm that the pos is a valid byte position, or use insert_chars which will panic if it isn’t.

source

pub fn clear(&mut self)

Clears the string to an empty buffer.

source

pub fn remove_chars(&mut self, pos: usize, char_count: usize)

Removes the given number of characters from the string starting at some byte pos.

§Panics

Panics if the pos is not a char boundary.

source

pub unsafe fn remove_chars_unchecked(&mut self, pos: usize, byte_count: usize)

Removes the given number of bytes from the string starting at some byte pos, without checking for utf8 validity. Use remove_chars for a safe variant.

§Safety

It is up to the caller to ensure that the position is at a valid utf8 char_boundary and that there are enough bytes within the string remaining.

source

pub fn cursor_pos(&self) -> usize

Get a reference to the text callback buffer’s cursor pos.

source

pub fn set_cursor_pos(&mut self, cursor_pos: usize)

Set the text callback buffer’s cursor pos.

source

pub fn selection_start_mut(&mut self) -> &mut i32

Get a mutable reference to the text callback buffer’s selection start.

source

pub fn selection_end_mut(&mut self) -> &mut i32

Get a mutable reference to the text callback buffer’s selection end..

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.