Skip to main content

zest_gui/
lib.rs

1//! `zest` — retained-mode GUI framework for embedded touchscreen MCUs.
2//!
3//! Re-exports `zest-core`, `zest-theme`, `zest-widget`, and (with the
4//! `simulator` feature) `zest-simulator`. Provides convenience runners
5//! and a `time` module re-exported from `zest-core`.
6//!
7//! ```ignore
8//! use zest::prelude::*;
9//!
10//! struct App { /* ... */ }
11//!
12//! impl Application for App {
13//!     fn init() -> (Self, Task<Msg>) { /* ... */ }
14//!     // ...
15//! }
16//!
17//! #[embassy_executor::main]
18//! async fn main(_spawner: embassy_executor::Spawner) {
19//!     zest::run::<App>("My App").await;
20//! }
21//! ```
22
23#![cfg_attr(not(test), no_std)]
24#![warn(missing_docs)]
25
26#[cfg(any(feature = "simulator", feature = "net"))]
27extern crate std;
28
29pub use zest_core;
30pub use zest_theme;
31pub use zest_widget;
32
33#[cfg(feature = "simulator")]
34pub use zest_simulator;
35
36/// Re-export of [`zest_core::time`]: built-in subscription helpers.
37pub mod time {
38    pub use zest_core::time::*;
39}
40
41/// Async network helpers for desktop development.
42///
43/// On the simulator the embassy executor doesn't host a tokio reactor,
44/// so true async HTTP isn't available. This module spawns a `std::thread`
45/// for the blocking call and yields between embassy timer ticks until
46/// the worker finishes — entirely an implementation detail. The
47/// signature stays `async fn`, matching what `embassy-net` + `reqwless`
48/// will expose on hardware.
49#[cfg(feature = "net")]
50pub mod net;
51
52/// Everything an application typically wants imported at the top.
53///
54/// Includes the framework primitives plus a curated set of
55/// `embedded_graphics` types (`Rectangle`, `Point`, `Size`,
56/// `Rgb565`, `Rgb888`, `BinaryColor`) so apps generally don't need
57/// to depend on `embedded-graphics` directly.
58pub mod prelude {
59    pub use zest_core::{
60        Application, ButtonState, Constraints, DirtyRegion, DrawTargetRenderer, FocusDirection,
61        FocusState, GesturePhase, Horizontal, InputEvent, Key, KeyEvent, Length, Platform,
62        PlatformCapabilities, Recipe, RenderError, Renderer, Runtime, ScreenView, Subscription,
63        Task, TickResult, TouchEvent, TouchPhase, UiAction, Vertical, WidgetId,
64    };
65    pub use zest_theme::{
66        ButtonAppearance, ButtonCatalog, ButtonClass, Component, CornerRadii, FONT_ZEST_MONO,
67        FONT_ZEST_MONO_CAPTION, FONT_ZEST_MONO_DISPLAY, FONT_ZEST_MONO_HEADING, Palette, Spacing,
68        Status, Theme, Typography, convert_theme,
69    };
70    pub use zest_widget::{
71        Arc, Button, Calendar, CalendarEvent, Canvas, CanvasBuffer, Chart, Checkbox, Column,
72        Container, Divider, Dropdown, EccLevel, Element, Grid, ImageButton, IntoElement, KeyAction,
73        Keyboard, KeyboardMode, LED, Line, List, ListRow, Menu, MessageBox, ProgressBar, Qr,
74        RadioButton, Roller, Row, Scale, ScaleMode, ScrollDirection, ScrollMsg, ScrollState,
75        Scrollable, ScrollbarMode, Slider, SnapMode, Space, Span, SpanGroup, SpinButton,
76        SpinOrientation, Spinner, Stack, Switch, Tab, TabBar, Table, TableRow, Text, TextArea,
77        Tileview, Widget, Window, horizontal_divider, horizontal_space, horizontal_spin_button,
78        tick_task, vertical_divider, vertical_space, vertical_spin_button,
79    };
80
81    pub use embedded_graphics::{
82        pixelcolor::{BinaryColor, Rgb565, Rgb888},
83        prelude::{Point, Size},
84        primitives::Rectangle,
85    };
86}
87
88/// Run application type `A` with the framework's default desktop
89/// platform (the simulator).
90///
91/// libcosmic-shaped: the runtime calls `A::init()` to obtain the
92/// initial app value and a startup task. For custom hardware,
93/// construct a `Platform` yourself and call
94/// `Runtime::<A>::new().run(platform).await` directly.
95///
96/// Calls `std::process::exit(0)` when the simulator window closes, since
97/// embassy's std executor parks the main thread and would otherwise hang.
98#[cfg(feature = "simulator")]
99pub async fn run<A>(title: &str)
100where
101    A: zest_core::Application<Color = embedded_graphics::pixelcolor::Rgb565>,
102{
103    let platform = zest_simulator::SimulatorPlatform::new(title);
104    zest_core::Runtime::<A>::new().run(platform).await;
105    std::process::exit(0);
106}