//! The immediate-mode renderer for [`quasi_router`]: a described screen in, an //! egui frame out. //! //! //! //! The third renderer, and the one the stack was missing. `quasi-webview` and //! `quasi-tui` have consumed a [`Screen`] since the beginning; nothing did in //! egui, so an egui app describing a screen had nowhere to send it. What looked //! like the egui renderer was `makeover-immediate`, which draws described //! *nodes* and takes no dependency on `quasi-router` at all: it is the peer of //! `makeover-webview` and `makeover-tui`, one layer below this. //! //! | Layer | webview | terminal | egui | //! |---|---|---|---| //! | nodes, from `makeover-layout` | `makeover-webview` | `makeover-tui` | `makeover-immediate` | //! | screens, from `quasi-router` | `quasi-webview` | `quasi-tui` | **this crate** | //! //! Named for the mode and not the library, the way `makeover-immediate` is: what //! separates this renderer from the other two is that there is no retained tree //! and no cascade, and egui is the backend it is written against. //! //! # What immediate mode gives this renderer for free //! //! `quasi-tui` holds five things a browser provides quietly: what is typed, what //! has focus, how far a pane is scrolled, what is ticked, and where back goes. //! egui provides three of them, so this crate is smaller than the terminal's //! rather than larger: //! //! - **Reach and focus are egui's**, entirely. Its own id stack decides what is //! reachable and its own state decides what holds the keyboard, which is the //! rule `makeover-immediate`'s header already states for the ring. There is no //! `focus.rs` here and there should not be one. //! - **Scroll is egui's**, through `ScrollArea`. //! - **What is typed and what is ticked are not.** A described field is built //! from the description every frame, so the buffer behind it has to outlive //! the frame and belongs to the app. That is [`View`], and it is the same //! discovery the terminal made for the same reason. //! //! # Where a description stops being enough //! //! The three findings `quasi-tui`'s `region` module records apply here unchanged, //! because they are about the description rather than about terminals: a tabbed //! arrangement does not say which tab is showing, a tab has no label, and //! nothing says a region's share beyond [`Arrangement::share`]. Nothing new is //! invented here to paper over them; the same guesses are made and named. #![forbid(unsafe_code)] mod node; mod region; mod runtime; mod view; #[cfg(test)] mod tests; pub use runtime::{Runtime, Step}; pub use view::View; use egui::Ui; use makeover_immediate::table::TableStyle; use makeover_immediate::widget::WidgetStyle; use makeover_immediate::{FieldStyle, FrameStyle, Palette}; use quasi_router::{Action, Message, Params, Screen, layout}; /// A banner this renderer raises about itself. /// /// A description bug reported to the user rather than swallowed: a fragment /// naming a region that is not there would otherwise look like a control that /// does nothing. pub(crate) fn layout_notice(text: String) -> Message { Message { kind: layout::Notice::Banner, tone: layout::Tone::Danger, text, undo: None, } } /// An egui renderer for a described screen. /// /// Holds what a drawing needs and no screen state: the resolved palette and the /// styles derived from it. A host makes one and keeps it, the same way it keeps /// a `Tui`. #[derive(Debug, Clone)] pub struct Immediate { palette: Palette, frame: FrameStyle, field: FieldStyle, widget: WidgetStyle, table: TableStyle, } impl Immediate { /// A renderer drawing in this palette, with default styling. #[must_use] pub fn new(palette: Palette) -> Self { Self { palette, frame: FrameStyle::default(), field: FieldStyle::default(), widget: WidgetStyle::default(), table: TableStyle::default(), } } /// The colours this renderer draws in. #[must_use] pub const fn palette(&self) -> &Palette { &self.palette } /// Use these frame, field, widget and table styles, chaining. #[must_use] pub fn styled( mut self, frame: FrameStyle, field: FieldStyle, widget: WidgetStyle, table: TableStyle, ) -> Self { self.frame = frame; self.field = field; self.widget = widget; self.table = table; self } /// Draw a whole screen, and answer what the user did to it. /// /// The title is not drawn, for the reason `quasi-tui` gives: a window title /// is the host's to set, the same way a webview host puts it in `