Skip to main content

UiRuntimePresenter

Trait UiRuntimePresenter 

Source
pub trait UiRuntimePresenter<'text, Display, Root, ViewId, Message, const N: usize>
where Display: DisplayPort, Root: UiView<'text, ViewId, Message, N>,
{ type Pending: Copy; type Error; // Required methods fn idle_pending(&self) -> Self::Pending; fn merge_pending( &self, current: Self::Pending, next: Self::Pending, ) -> Self::Pending; fn pending_for_event(&mut self, event: ViewEvent<Message>) -> Self::Pending; fn should_present( &mut self, pending: Self::Pending, since_present_ms: u32, system: &UiSystem<'text, Display, Root, ViewId, Message, N>, ) -> bool; fn present( &mut self, pending: Self::Pending, system: &mut UiSystem<'text, Display, Root, ViewId, Message, N>, ) -> Result<(), Self::Error>; // Provided method fn did_present( &mut self, _pending: Self::Pending, _system: &UiSystem<'text, Display, Root, ViewId, Message, N>, ) { ... } }
Expand description

Presentation policy used by run_ui_system to batch redraw requests.

Required Associated Types§

Source

type Pending: Copy

Aggregated pending state used by the presenter between frames.

Source

type Error

Presenter-specific error type.

Required Methods§

Source

fn idle_pending(&self) -> Self::Pending

Returns the empty pending state.

Source

fn merge_pending( &self, current: Self::Pending, next: Self::Pending, ) -> Self::Pending

Merges two pending redraw states.

Source

fn pending_for_event(&mut self, event: ViewEvent<Message>) -> Self::Pending

Converts a view event into pending presentation state.

Source

fn should_present( &mut self, pending: Self::Pending, since_present_ms: u32, system: &UiSystem<'text, Display, Root, ViewId, Message, N>, ) -> bool

Decides whether a frame should be presented now.

Source

fn present( &mut self, pending: Self::Pending, system: &mut UiSystem<'text, Display, Root, ViewId, Message, N>, ) -> Result<(), Self::Error>

Presents the pending frame.

Provided Methods§

Source

fn did_present( &mut self, _pending: Self::Pending, _system: &UiSystem<'text, Display, Root, ViewId, Message, N>, )

Optional callback invoked after a successful presentation.

Examples found in repository?
src/runtime.rs (line 125)
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}

Implementors§