Skip to main content

InputBar

Struct InputBar 

Source
pub struct InputBar {
    pub prefix: String,
    pub buffer: String,
    pub cursor: usize,
    pub suggestions: Vec<Suggestion>,
    pub selected: Option<usize>,
    pub palette: Palette,
    pub cursor_visible: bool,
}
Expand description

Single-line text input + dropdown.

Fields§

§prefix: String§buffer: String§cursor: usize

Byte index into Self::buffer where the next character would be inserted. 0..=buffer.len() always; never points into the middle of a UTF-8 codepoint.

§suggestions: Vec<Suggestion>§selected: Option<usize>

Index into Self::suggestions. None means “no selection, Enter uses the typed buffer verbatim”.

§palette: Palette§cursor_visible: bool

Caller-managed cursor blink. Flip every 500ms or so.

Implementations§

Source§

impl InputBar

Source

pub fn with_prefix(prefix: impl Into<String>) -> Self

Build an empty input bar with the given prefix string.

Source

pub fn current_value(&self) -> &str

What the caller should treat as the “confirmed value” on Enter. If a suggestion is selected, returns its value; else returns the raw buffer.

Source

pub fn clear(&mut self)

Reset to “empty + prefix only” state. Doesn’t clear the prefix itself — callers swap the widget for one with a new prefix when transitioning between command line / omnibar.

Source

pub fn handle_text(&mut self, ch: char)

Insert ch at the cursor and advance.

Source

pub fn handle_back(&mut self)

Backspace — delete the codepoint before the cursor.

Source

pub fn handle_delete_word(&mut self)

Delete the word before the cursor (<C-w>). A “word” is a run of non-whitespace, optionally preceded by whitespace.

Source

pub fn handle_clear_line(&mut self)

Clear the buffer entirely (<C-u>).

Source

pub fn handle_left(&mut self)

Move cursor one codepoint left.

Source

pub fn handle_right(&mut self)

Move cursor one codepoint right.

Source

pub fn handle_up(&mut self)

Move suggestion selection one row up. Wraps from 0 → no-op. <Up> arrow / <S-Tab>.

Source

pub fn handle_down(&mut self)

Move suggestion selection one row down. <Down> / <Tab>.

Source

pub fn set_suggestions(&mut self, suggestions: Vec<Suggestion>)

Replace the suggestion list. Resets selected to None.

Source

pub fn total_height(&self) -> u32

Total pixel height when fully expanded with n visible suggestions, where n = min(suggestions.len(), MAX_SUGGESTIONS). Used by the host to compute the CEF child rect.

Source

pub fn paint(&self, buffer: &mut [u32], width: usize, height: usize)

Paint the input bar into the top INPUT_HEIGHT rows of buffer, then any visible suggestion rows below that. Rows below total_height() are left untouched — the caller has either reserved that space or has nothing else to draw there.

Source

pub fn paint_at( &self, buffer: &mut [u32], buf_w: usize, buf_h: usize, x: usize, y: usize, w: usize, h: usize, )

Paint into a sub-rectangle of the surface buffer. x, y, w, h are pixel positions in the full surface (stride = buf_w). The bar draws at the top of the rect; suggestions extend downward within it.

Trait Implementations§

Source§

impl Clone for InputBar

Source§

fn clone(&self) -> InputBar

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for InputBar

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for InputBar

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.