Skip to main content

Cursor

Struct Cursor 

Source
pub struct Cursor {
    pub blink_speed: Duration,
    pub style: Style,
    pub text_style: Style,
    /* private fields */
}
Expand description

A cursor component for text input.

Fields§

§blink_speed: Duration

The blink speed.

§style: Style

Style for the cursor block.

§text_style: Style

Style for text when cursor is hidden (blinking off).

Implementations§

Source§

impl Cursor

Source

pub fn new() -> Self

Creates a new cursor with default settings.

Source

pub fn id(&self) -> u64

Returns the cursor’s unique ID.

Source

pub fn mode(&self) -> Mode

Returns the current cursor mode.

Source

pub fn set_mode(&mut self, mode: Mode) -> Option<Cmd>

Sets the cursor mode.

Returns a command to start blinking if the mode is Blink.

Source

pub fn set_char(&mut self, c: &str)

Sets the character displayed under the cursor.

Source

pub fn char(&self) -> &str

Returns the character under the cursor.

Source

pub fn focused(&self) -> bool

Returns whether the cursor is currently focused.

Source

pub fn is_blinking_off(&self) -> bool

Returns whether the cursor is currently in its “off” blink state.

Source

pub fn focus(&mut self) -> Option<Cmd>

Focuses the cursor, allowing it to blink if in blink mode.

Returns a command to start blinking.

Source

pub fn blur(&mut self)

Blurs (unfocuses) the cursor.

Source

pub fn update(&mut self, msg: Message) -> Option<Cmd>

Updates the cursor state based on incoming messages.

Source

pub fn view(&self) -> String

Renders the cursor.

Trait Implementations§

Source§

impl Clone for Cursor

Source§

fn clone(&self) -> Cursor

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 Cursor

Source§

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

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

impl Default for Cursor

Source§

fn default() -> Self

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

impl Model for Cursor

Source§

fn init(&self) -> Option<Cmd>

Initialize the cursor and return a blink command if in blink mode and focused.

Source§

fn update(&mut self, msg: Message) -> Option<Cmd>

Update the cursor state based on incoming messages.

Handles:

  • InitialBlinkMsg - Start blinking if focused and in blink mode
  • FocusMsg - Focus the cursor and start blinking
  • BlurMsg - Blur the cursor and stop blinking
  • BlinkMsg - Toggle blink state and schedule next blink
Source§

fn view(&self) -> String

Render the cursor.

Returns the cursor character styled appropriately based on blink state.

Auto Trait Implementations§

§

impl Freeze for Cursor

§

impl !RefUnwindSafe for Cursor

§

impl Send for Cursor

§

impl Sync for Cursor

§

impl Unpin for Cursor

§

impl !UnwindSafe for Cursor

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