Skip to main content

State

Struct State 

Source
pub struct State<T: Copy> { /* private fields */ }
Expand description

Reactive integer state backed by LVGL’s observer subsystem (lv_subject_t). Bind widget properties to a State and they update automatically when you call State::set.

§Stability requirement

lv_subject_t keeps a linked list of observer references, so the State address must be stable from the moment any observer attaches. The intended usage is inside a static slot — either a raw static declared by the user, or via the ove::shared! macro. Dropping a State while observers are still attached will corrupt the observer list. PhantomPinned prevents move after construction.

use ove::lvgl::{State, Label};
ove::shared!(COUNTER: State<i32>);
// init once:
COUNTER.init(State::new(0));
// bind:
Label::create(screen).bind_text(COUNTER.get_ref(), b"Count: %d\0");
// update from anywhere:
COUNTER.get_ref().set(42);  // label updates automatically

Implementations§

Source§

impl<T: Copy + Into<i32> + TryFrom<i32>> State<T>

Source

pub fn new(initial: T) -> Self

Create a new reactive state with an initial value.

Source

pub fn set(&self, value: T)

Set a new value. All bound widgets update immediately.

Takes &self rather than &mut self because LVGL serializes observer notification under the global LVGL lock — the lock is the real mutex, not Rust’s borrow checker.

Source

pub fn get(&self) -> T

Read the current value. Falls back to a zeroed T if the stored i32 cannot be converted back to T (unreachable for well-typed integer states).

Source

pub fn subject_ptr(&self) -> *mut lv_subject_t

Returns the raw *mut lv_subject_t for widget binding.

Source§

impl<T: Copy + Into<i32> + TryFrom<i32>> State<T>

Source

pub fn observe(&self, obj: impl Widget)

Attach an observer that automatically refreshes obj when this state changes. The actual rebinding logic is on the widget side (e.g. Label::bind_text) — this is a low-level escape hatch.

Trait Implementations§

Source§

impl<T: Copy> Drop for State<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: Copy + Send> Send for State<T>

Source§

impl<T: Copy + Send> Sync for State<T>

Auto Trait Implementations§

§

impl<T> !Freeze for State<T>

§

impl<T> !RefUnwindSafe for State<T>

§

impl<T> !Unpin for State<T>

§

impl<T> !UnsafeUnpin for State<T>

§

impl<T> UnwindSafe for State<T>
where T: UnwindSafe,

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.