Skip to main content

TextCallbackData

Struct TextCallbackData 

Source
pub struct TextCallbackData<'cb>(/* 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<'cb> TextCallbackData<'cb>

Source

pub fn str(&self) -> &str

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

Source

pub fn cursor_pos(&self) -> usize

Get the current cursor position

Source

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

Set the cursor position

Source

pub fn selection_start(&self) -> usize

Get the selection start position

Source

pub fn set_selection_start(&mut self, pos: usize)

Set the selection start position

Source

pub fn selection_end(&self) -> usize

Get the selection end position

Source

pub fn set_selection_end(&mut self, pos: usize)

Set the selection end position

Source

pub fn select_all(&mut self)

Select all text

Source

pub fn clear_selection(&mut self)

Clear selection

Source

pub fn has_selection(&self) -> bool

Returns true if there is a selection

Source

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

Delete characters in the range [pos, pos+bytes_count)

Source

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

Insert text at the given position

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 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 push_str(&mut self, text: &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.

Auto Trait Implementations§

§

impl<'cb> !Send for TextCallbackData<'cb>

§

impl<'cb> !Sync for TextCallbackData<'cb>

§

impl<'cb> !UnwindSafe for TextCallbackData<'cb>

§

impl<'cb> Freeze for TextCallbackData<'cb>

§

impl<'cb> RefUnwindSafe for TextCallbackData<'cb>

§

impl<'cb> Unpin for TextCallbackData<'cb>

§

impl<'cb> UnsafeUnpin for TextCallbackData<'cb>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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>,

Source§

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>,

Source§

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more