Skip to main content

UiSystem

Struct UiSystem 

Source
pub struct UiSystem<'text, Display, Root, ViewId, Message, const N: usize>
where Display: DisplayPort, Root: UiView<'text, ViewId, Message, N>,
{ /* private fields */ }
Expand description

Owns the root view, display, theme, localization, and registration state.

Implementations§

Source§

impl<'text, Display, Root, ViewId, Message, const N: usize> UiSystem<'text, Display, Root, ViewId, Message, N>
where Display: DisplayPort, Root: UiView<'text, ViewId, Message, N>,

Source

pub fn new( display: Display, root: Root, theme: FsTheme, i18n: I18n<'text>, ) -> Self

Creates a fully configured UI system and runs the root configure pass.

Examples found in repository?
examples/uikit_root.rs (lines 208-213)
206fn main() {
207    let bounds = Rectangle::new(Point::zero(), Size::new(320, 240));
208    let mut system = UiSystem::new(
209        NullDisplay::new(bounds),
210        RootView::new(),
211        FsTheme::default(),
212        I18n::new("en", "en", &[]),
213    );
214
215    let redraw = system.update(16).redraw;
216    let _ = system.draw_redraw(redraw);
217    let _ = system.handle_touch(TouchEvent::new(Point::new(24, 24), TouchPhase::Start, 1));
218    let _ = system.handle_touch(TouchEvent::new(Point::new(24, 24), TouchPhase::End, 2));
219    let _ = system.draw();
220    let _ = system.registration();
221    let _ = ViewRedraw::Full;
222}
More examples
Hide additional examples
src/runtime.rs (line 95)
81pub fn run_ui_system<'text, Display, Root, ViewId, Message, Driver, Presenter, const N: usize>(
82    display: Display,
83    root: Root,
84    theme: FsTheme,
85    i18n: I18n<'text>,
86    mut driver: Driver,
87    mut presenter: Presenter,
88) -> Result<(), UiRuntimeError<Driver::Error, Presenter::Error>>
89where
90    Display: DisplayPort,
91    Root: UiView<'text, ViewId, Message, N>,
92    Driver: UiRuntimeDriver,
93    Presenter: UiRuntimePresenter<'text, Display, Root, ViewId, Message, N>,
94{
95    let mut system = UiSystem::new(display, root, theme, i18n);
96    let mut pending = presenter.idle_pending();
97    let mut last_tick_ms = driver.now_ms();
98    let mut last_present_ms = last_tick_ms;
99
100    loop {
101        let poll_delay_ms = if driver.needs_active_poll() {
102            driver.active_poll_ms()
103        } else {
104            driver.idle_poll_ms()
105        };
106        driver.delay_ms(poll_delay_ms);
107
108        let now_ms = driver.now_ms();
109        let dt_ms = now_ms.saturating_sub(last_tick_ms).max(1);
110        last_tick_ms = now_ms;
111
112        let update_pending = presenter.pending_for_event(system.update(dt_ms));
113        pending = presenter.merge_pending(pending, update_pending);
114
115        if let Some(touch) = driver.poll_touch(now_ms).map_err(UiRuntimeError::Driver)? {
116            let touch_pending = presenter.pending_for_event(system.handle_touch(touch));
117            pending = presenter.merge_pending(pending, touch_pending);
118        }
119
120        let since_present_ms = now_ms.saturating_sub(last_present_ms);
121        if presenter.should_present(pending, since_present_ms, &system) {
122            presenter
123                .present(pending, &mut system)
124                .map_err(UiRuntimeError::Present)?;
125            presenter.did_present(pending, &system);
126            pending = presenter.idle_pending();
127            last_present_ms = driver.now_ms();
128        }
129    }
130}
Source

pub fn configure_root(&mut self)

Re-runs the root configuration against the current display bounds.

Examples found in repository?
src/system.rs (line 39)
29    pub fn new(display: Display, root: Root, theme: FsTheme, i18n: I18n<'text>) -> Self {
30        let registration = ViewRegistration::new(display.bounds());
31        let mut system = Self {
32            display,
33            root,
34            theme,
35            i18n,
36            registration,
37            marker: PhantomData,
38        };
39        system.configure_root();
40        system
41    }
Source

pub const fn root(&self) -> &Root

Returns the root view.

Source

pub fn root_mut(&mut self) -> &mut Root

Returns the root view mutably.

Source

pub const fn registration(&self) -> &ViewRegistration<'text, ViewId, N>

Returns the current root registration.

Examples found in repository?
examples/uikit_root.rs (line 220)
206fn main() {
207    let bounds = Rectangle::new(Point::zero(), Size::new(320, 240));
208    let mut system = UiSystem::new(
209        NullDisplay::new(bounds),
210        RootView::new(),
211        FsTheme::default(),
212        I18n::new("en", "en", &[]),
213    );
214
215    let redraw = system.update(16).redraw;
216    let _ = system.draw_redraw(redraw);
217    let _ = system.handle_touch(TouchEvent::new(Point::new(24, 24), TouchPhase::Start, 1));
218    let _ = system.handle_touch(TouchEvent::new(Point::new(24, 24), TouchPhase::End, 2));
219    let _ = system.draw();
220    let _ = system.registration();
221    let _ = ViewRedraw::Full;
222}
Source

pub fn registration_mut(&mut self) -> &mut ViewRegistration<'text, ViewId, N>

Returns the current root registration mutably.

Source

pub const fn theme(&self) -> &FsTheme

Returns the active theme.

Source

pub fn theme_mut(&mut self) -> &mut FsTheme

Returns the active theme mutably.

Source

pub const fn i18n(&self) -> &I18n<'text>

Returns the active localization tables.

Source

pub fn i18n_mut(&mut self) -> &mut I18n<'text>

Returns the active localization tables mutably.

Source

pub const fn display(&self) -> &Display

Returns the display port.

Source

pub fn display_mut(&mut self) -> &mut Display

Returns the display port mutably.

Source

pub fn with_display_and_root<R>( &mut self, apply: impl FnOnce(&mut Display, &Root) -> R, ) -> R

Borrows the display mutably and the root immutably for one closure.

Source

pub fn with_display_and_root_mut<R>( &mut self, apply: impl FnOnce(&mut Display, &mut Root) -> R, ) -> R

Borrows the display and root mutably for one closure.

Source

pub fn update(&mut self, dt_ms: u32) -> ViewEvent<Message>

Runs one logical update tick on the root view.

Examples found in repository?
examples/uikit_root.rs (line 215)
206fn main() {
207    let bounds = Rectangle::new(Point::zero(), Size::new(320, 240));
208    let mut system = UiSystem::new(
209        NullDisplay::new(bounds),
210        RootView::new(),
211        FsTheme::default(),
212        I18n::new("en", "en", &[]),
213    );
214
215    let redraw = system.update(16).redraw;
216    let _ = system.draw_redraw(redraw);
217    let _ = system.handle_touch(TouchEvent::new(Point::new(24, 24), TouchPhase::Start, 1));
218    let _ = system.handle_touch(TouchEvent::new(Point::new(24, 24), TouchPhase::End, 2));
219    let _ = system.draw();
220    let _ = system.registration();
221    let _ = ViewRedraw::Full;
222}
More examples
Hide additional examples
src/runtime.rs (line 112)
81pub fn run_ui_system<'text, Display, Root, ViewId, Message, Driver, Presenter, const N: usize>(
82    display: Display,
83    root: Root,
84    theme: FsTheme,
85    i18n: I18n<'text>,
86    mut driver: Driver,
87    mut presenter: Presenter,
88) -> Result<(), UiRuntimeError<Driver::Error, Presenter::Error>>
89where
90    Display: DisplayPort,
91    Root: UiView<'text, ViewId, Message, N>,
92    Driver: UiRuntimeDriver,
93    Presenter: UiRuntimePresenter<'text, Display, Root, ViewId, Message, N>,
94{
95    let mut system = UiSystem::new(display, root, theme, i18n);
96    let mut pending = presenter.idle_pending();
97    let mut last_tick_ms = driver.now_ms();
98    let mut last_present_ms = last_tick_ms;
99
100    loop {
101        let poll_delay_ms = if driver.needs_active_poll() {
102            driver.active_poll_ms()
103        } else {
104            driver.idle_poll_ms()
105        };
106        driver.delay_ms(poll_delay_ms);
107
108        let now_ms = driver.now_ms();
109        let dt_ms = now_ms.saturating_sub(last_tick_ms).max(1);
110        last_tick_ms = now_ms;
111
112        let update_pending = presenter.pending_for_event(system.update(dt_ms));
113        pending = presenter.merge_pending(pending, update_pending);
114
115        if let Some(touch) = driver.poll_touch(now_ms).map_err(UiRuntimeError::Driver)? {
116            let touch_pending = presenter.pending_for_event(system.handle_touch(touch));
117            pending = presenter.merge_pending(pending, touch_pending);
118        }
119
120        let since_present_ms = now_ms.saturating_sub(last_present_ms);
121        if presenter.should_present(pending, since_present_ms, &system) {
122            presenter
123                .present(pending, &mut system)
124                .map_err(UiRuntimeError::Present)?;
125            presenter.did_present(pending, &system);
126            pending = presenter.idle_pending();
127            last_present_ms = driver.now_ms();
128        }
129    }
130}
Source

pub fn handle_touch(&mut self, touch: TouchEvent) -> ViewEvent<Message>

Routes one touch event into the root view.

Examples found in repository?
examples/uikit_root.rs (line 217)
206fn main() {
207    let bounds = Rectangle::new(Point::zero(), Size::new(320, 240));
208    let mut system = UiSystem::new(
209        NullDisplay::new(bounds),
210        RootView::new(),
211        FsTheme::default(),
212        I18n::new("en", "en", &[]),
213    );
214
215    let redraw = system.update(16).redraw;
216    let _ = system.draw_redraw(redraw);
217    let _ = system.handle_touch(TouchEvent::new(Point::new(24, 24), TouchPhase::Start, 1));
218    let _ = system.handle_touch(TouchEvent::new(Point::new(24, 24), TouchPhase::End, 2));
219    let _ = system.draw();
220    let _ = system.registration();
221    let _ = ViewRedraw::Full;
222}
More examples
Hide additional examples
src/runtime.rs (line 116)
81pub fn run_ui_system<'text, Display, Root, ViewId, Message, Driver, Presenter, const N: usize>(
82    display: Display,
83    root: Root,
84    theme: FsTheme,
85    i18n: I18n<'text>,
86    mut driver: Driver,
87    mut presenter: Presenter,
88) -> Result<(), UiRuntimeError<Driver::Error, Presenter::Error>>
89where
90    Display: DisplayPort,
91    Root: UiView<'text, ViewId, Message, N>,
92    Driver: UiRuntimeDriver,
93    Presenter: UiRuntimePresenter<'text, Display, Root, ViewId, Message, N>,
94{
95    let mut system = UiSystem::new(display, root, theme, i18n);
96    let mut pending = presenter.idle_pending();
97    let mut last_tick_ms = driver.now_ms();
98    let mut last_present_ms = last_tick_ms;
99
100    loop {
101        let poll_delay_ms = if driver.needs_active_poll() {
102            driver.active_poll_ms()
103        } else {
104            driver.idle_poll_ms()
105        };
106        driver.delay_ms(poll_delay_ms);
107
108        let now_ms = driver.now_ms();
109        let dt_ms = now_ms.saturating_sub(last_tick_ms).max(1);
110        last_tick_ms = now_ms;
111
112        let update_pending = presenter.pending_for_event(system.update(dt_ms));
113        pending = presenter.merge_pending(pending, update_pending);
114
115        if let Some(touch) = driver.poll_touch(now_ms).map_err(UiRuntimeError::Driver)? {
116            let touch_pending = presenter.pending_for_event(system.handle_touch(touch));
117            pending = presenter.merge_pending(pending, touch_pending);
118        }
119
120        let since_present_ms = now_ms.saturating_sub(last_present_ms);
121        if presenter.should_present(pending, since_present_ms, &system) {
122            presenter
123                .present(pending, &mut system)
124                .map_err(UiRuntimeError::Present)?;
125            presenter.did_present(pending, &system);
126            pending = presenter.idle_pending();
127            last_present_ms = driver.now_ms();
128        }
129    }
130}
Source

pub fn draw(&mut self) -> Result<(), Display::Error>

Draws a full frame through the display port.

Examples found in repository?
examples/uikit_root.rs (line 219)
206fn main() {
207    let bounds = Rectangle::new(Point::zero(), Size::new(320, 240));
208    let mut system = UiSystem::new(
209        NullDisplay::new(bounds),
210        RootView::new(),
211        FsTheme::default(),
212        I18n::new("en", "en", &[]),
213    );
214
215    let redraw = system.update(16).redraw;
216    let _ = system.draw_redraw(redraw);
217    let _ = system.handle_touch(TouchEvent::new(Point::new(24, 24), TouchPhase::Start, 1));
218    let _ = system.handle_touch(TouchEvent::new(Point::new(24, 24), TouchPhase::End, 2));
219    let _ = system.draw();
220    let _ = system.registration();
221    let _ = ViewRedraw::Full;
222}
More examples
Hide additional examples
src/system.rs (line 150)
147    pub fn draw_redraw(&mut self, redraw: ViewRedraw) -> Result<(), Display::Error> {
148        match redraw {
149            ViewRedraw::None => Ok(()),
150            ViewRedraw::Full => self.draw(),
151            ViewRedraw::Dirty(area) => {
152                let env = ViewEnvironment {
153                    theme: &self.theme,
154                    i18n: &self.i18n,
155                };
156                self.display.draw_dirty(area, |canvas| {
157                    self.root.draw(canvas, &self.registration, &env);
158                })
159            }
160        }
161    }
Source

pub fn draw_redraw(&mut self, redraw: ViewRedraw) -> Result<(), Display::Error>

Draws only what the supplied redraw request requires.

Examples found in repository?
examples/runtime_shell.rs (line 120)
115    fn present(
116        &mut self,
117        pending: Self::Pending,
118        system: &mut UiSystem<'static, support::NullDisplay, RootView, RootId, (), 1>,
119    ) -> Result<(), Self::Error> {
120        let _ = system.draw_redraw(pending);
121        Ok(())
122    }
More examples
Hide additional examples
examples/uikit_root.rs (line 216)
206fn main() {
207    let bounds = Rectangle::new(Point::zero(), Size::new(320, 240));
208    let mut system = UiSystem::new(
209        NullDisplay::new(bounds),
210        RootView::new(),
211        FsTheme::default(),
212        I18n::new("en", "en", &[]),
213    );
214
215    let redraw = system.update(16).redraw;
216    let _ = system.draw_redraw(redraw);
217    let _ = system.handle_touch(TouchEvent::new(Point::new(24, 24), TouchPhase::Start, 1));
218    let _ = system.handle_touch(TouchEvent::new(Point::new(24, 24), TouchPhase::End, 2));
219    let _ = system.draw();
220    let _ = system.registration();
221    let _ = ViewRedraw::Full;
222}

Auto Trait Implementations§

§

impl<'text, Display, Root, ViewId, Message, const N: usize> Freeze for UiSystem<'text, Display, Root, ViewId, Message, N>
where Display: Freeze, Root: Freeze, ViewId: Freeze,

§

impl<'text, Display, Root, ViewId, Message, const N: usize> RefUnwindSafe for UiSystem<'text, Display, Root, ViewId, Message, N>
where Display: RefUnwindSafe, Root: RefUnwindSafe, Message: RefUnwindSafe, ViewId: RefUnwindSafe,

§

impl<'text, Display, Root, ViewId, Message, const N: usize> Send for UiSystem<'text, Display, Root, ViewId, Message, N>
where Display: Send, Root: Send, Message: Send, ViewId: Send,

§

impl<'text, Display, Root, ViewId, Message, const N: usize> Sync for UiSystem<'text, Display, Root, ViewId, Message, N>
where Display: Sync, Root: Sync, Message: Sync, ViewId: Sync,

§

impl<'text, Display, Root, ViewId, Message, const N: usize> Unpin for UiSystem<'text, Display, Root, ViewId, Message, N>
where Display: Unpin, Root: Unpin, Message: Unpin, ViewId: Unpin,

§

impl<'text, Display, Root, ViewId, Message, const N: usize> UnsafeUnpin for UiSystem<'text, Display, Root, ViewId, Message, N>
where Display: UnsafeUnpin, Root: UnsafeUnpin, ViewId: UnsafeUnpin,

§

impl<'text, Display, Root, ViewId, Message, const N: usize> UnwindSafe for UiSystem<'text, Display, Root, ViewId, Message, N>
where Display: UnwindSafe, Root: UnwindSafe, Message: UnwindSafe, ViewId: 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> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
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> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
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> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.