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>,
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>,
Sourcepub fn new(
display: Display,
root: Root,
theme: FsTheme,
i18n: I18n<'text>,
) -> Self
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
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}Sourcepub fn configure_root(&mut self)
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 }Sourcepub const fn registration(&self) -> &ViewRegistration<'text, ViewId, N>
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}Sourcepub fn registration_mut(&mut self) -> &mut ViewRegistration<'text, ViewId, N>
pub fn registration_mut(&mut self) -> &mut ViewRegistration<'text, ViewId, N>
Returns the current root registration mutably.
Sourcepub fn display_mut(&mut self) -> &mut Display
pub fn display_mut(&mut self) -> &mut Display
Returns the display port mutably.
Sourcepub fn with_display_and_root<R>(
&mut self,
apply: impl FnOnce(&mut Display, &Root) -> R,
) -> R
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.
Sourcepub fn with_display_and_root_mut<R>(
&mut self,
apply: impl FnOnce(&mut Display, &mut Root) -> R,
) -> R
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.
Sourcepub fn update(&mut self, dt_ms: u32) -> ViewEvent<Message>
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
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}Sourcepub fn handle_touch(&mut self, touch: TouchEvent) -> ViewEvent<Message>
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
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}Sourcepub fn draw(&mut self) -> Result<(), Display::Error>
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
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 }Sourcepub fn draw_redraw(&mut self, redraw: ViewRedraw) -> Result<(), Display::Error>
pub fn draw_redraw(&mut self, redraw: ViewRedraw) -> Result<(), Display::Error>
Draws only what the supplied redraw request requires.
Examples found in repository?
More 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>
impl<'text, Display, Root, ViewId, Message, const N: usize> RefUnwindSafe for UiSystem<'text, Display, Root, ViewId, Message, N>
impl<'text, Display, Root, ViewId, Message, const N: usize> Send for UiSystem<'text, Display, Root, ViewId, Message, N>
impl<'text, Display, Root, ViewId, Message, const N: usize> Sync for UiSystem<'text, Display, Root, ViewId, Message, N>
impl<'text, Display, Root, ViewId, Message, const N: usize> Unpin for UiSystem<'text, Display, Root, ViewId, Message, N>
impl<'text, Display, Root, ViewId, Message, const N: usize> UnsafeUnpin for UiSystem<'text, Display, Root, ViewId, Message, N>
impl<'text, Display, Root, ViewId, Message, const N: usize> UnwindSafe for UiSystem<'text, Display, Root, ViewId, Message, N>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Casts the value.
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
Source§fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
Source§fn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> WrappingAs for T
impl<T> WrappingAs for T
Source§fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
Source§fn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
Casts the value.