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): positivediffcallsfocus_nextonce per detent; negativediffcallsfocus_prevonce per detent. Adiffof±Nsteps focusNtimes in the corresponding direction (one step per detent — the simplest correct rule for a discrete encoder). -
Editing mode (
policy.editing == true): deliversObjectEvent::Rotary { diff }to the focused object for any non-zerodiff, andObjectEvent::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: FocusGroupFocus traversal and editing policy.
Implementations§
Source§impl EncoderDevice
impl EncoderDevice
Sourcepub fn new() -> Self
pub fn new() -> Self
Create an encoder device with default focus policy (wrap enabled, navigate mode).
Sourcepub fn rotate(&mut self, root: &mut ObjectNode, diff: i32) -> Disposition
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. ReturnsDisposition::NoTargetwhendiff == 0.
Sourcepub fn press(&mut self, root: &mut ObjectNode) -> Disposition
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.
Sourcepub fn is_editing(&self) -> bool
pub fn is_editing(&self) -> bool
Return whether the encoder is currently in editing mode.
Sourcepub fn set_editing(&mut self, root: &mut ObjectNode, editing: bool)
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.