Skip to main content

EncoderDevice

Struct EncoderDevice 

Source
pub struct EncoderDevice {
    pub focus_group: FocusGroup,
}
Expand description

LPAR-04 §8 Encoder input device adapter.

Holds a FocusGroup and routes encoder events according to the group’s navigate / editing mode:

  • Navigate mode (policy.editing == false): positive diff calls focus_next once per detent; negative diff calls focus_prev once per detent. A diff of ±N steps focus N times in the corresponding direction (one step per detent — the simplest correct rule for a discrete encoder).

  • Editing mode (policy.editing == true): delivers ObjectEvent::Rotary { diff } to the focused object for any non-zero diff, and ObjectEvent::Key(Key::Enter) for encoder presses.

§Mode toggle

An encoder press in either mode inverts policy.editing (LVGL encoder convention: Enter toggles between navigate and edit). The press is delivered as ObjectEvent::Key(Key::Enter) to the focused object before the toggle in editing mode.

§Focus group ownership

Each EncoderDevice owns its own FocusGroup, keeping the per-device state isolated (LPAR-04 §8.4).

Fields§

§focus_group: FocusGroup

Focus traversal and editing policy.

Implementations§

Source§

impl EncoderDevice

Source

pub fn new() -> Self

Create an encoder device with default focus policy (wrap enabled, navigate mode).

Source

pub fn rotate(&mut self, root: &mut ObjectNode, diff: i32) -> Disposition

Process a rotation event.

  • Navigate mode: steps focus diff.abs() times in the direction of the sign (positive → next, negative → prev).
  • Editing mode: delivers ObjectEvent::Rotary { diff } to the focused object. Returns Disposition::NoTarget when diff == 0.
Source

pub fn press(&mut self, root: &mut ObjectNode) -> Disposition

Process an encoder press (the physical click of the encoder shaft).

Toggles editing mode and:

  • Before toggle from editing → navigate: delivers ObjectEvent::Key(Key::Enter) to the focused object.
  • Toggle from navigate → editing: delivers ObjectEvent::Key(Key::Enter) to the focused object after entering editing mode (so the widget sees Enter while in edit mode).

Returns the Disposition of the key delivery, or Disposition::NoTarget if no focused object exists.

Source

pub fn is_editing(&self) -> bool

Return whether the encoder is currently in editing mode.

Source

pub fn set_editing(&mut self, root: &mut ObjectNode, editing: bool)

Directly set editing mode without delivering a key event.

Sets or clears rlvgl_core::object::ObjectStates::EDITED on the currently focused node in root.

Trait Implementations§

Source§

impl Default for EncoderDevice

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

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.