Skip to main content

root_delegate/
root_delegate.rs

1use embedded_graphics::{draw_target::DrawTarget, pixelcolor::Rgb565, primitives::Rectangle};
2use faststep::{FsTheme, I18n, Localized, TouchEvent, UiApp, ViewDelegate, ViewResponse};
3
4#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5enum AppView {
6    Home,
7    Detail,
8}
9
10struct DemoDelegate;
11
12impl DemoDelegate {
13    const fn new() -> Self {
14        Self
15    }
16}
17
18impl<'a> ViewDelegate<'a, AppView> for DemoDelegate {
19    fn title(&self, view: AppView) -> Localized<'a> {
20        match view {
21            AppView::Home => Localized::new("home.title", "Home"),
22            AppView::Detail => Localized::new("detail.title", "Detail"),
23        }
24    }
25
26    fn draw_view<D>(
27        &self,
28        _view: AppView,
29        _display: &mut D,
30        _frame: Rectangle,
31        _theme: &FsTheme,
32        _i18n: &I18n<'a>,
33    ) where
34        D: DrawTarget<Color = Rgb565>,
35    {
36    }
37
38    fn handle_view_touch(
39        &mut self,
40        view: AppView,
41        _touch: TouchEvent,
42        _frame: Rectangle,
43        _theme: &FsTheme,
44        _i18n: &I18n<'a>,
45    ) -> ViewResponse<AppView> {
46        match view {
47            AppView::Home => ViewResponse::push(AppView::Detail),
48            AppView::Detail => ViewResponse::pop(),
49        }
50    }
51}
52
53fn main() {
54    let _ui = UiApp::<AppView, DemoDelegate, 8>::new(
55        AppView::Home,
56        DemoDelegate::new(),
57        FsTheme::default(),
58        I18n::new("en", "en", &[]),
59    );
60}