Expand description
Pages and layouts: what a route loads and shows.
A Page is made of two functions:
- an optional load: an
async fnwhose arguments are extractors and which returnsResult<D, E>withE: Into<Rejection>. Any such function implementsHandler. Hooks are handlers too, returningResult<(), E>. - a view: a function of
&mut egui::Uiand extractors, called every frame. Any such function implementsView. Among the extractors,&mut D(or&D) is what the load returned; that the types match is checked at compile time.
use egui::Ui;
use egui_kit::Rejection;
use egui_kit::extract::{Nav, Path};
use egui_kit::page::Page;
struct Post {
title: String,
}
async fn load(Path(id): Path<u32>) -> Result<Post, Rejection> {
Ok(Post { title: format!("Post #{id}") })
}
fn view(ui: &mut Ui, post: &mut Post, nav: Nav) {
ui.heading(&post.title);
nav.link(ui, "Home", "/");
}
let page = Page::<()>::with_load(load, view);A Layout wraps all pages of a router. Its view
(LayoutView) gets the Children to draw the page in as its second argument.
Views can be closures too, with annotated arguments: |ui: &mut Ui, nav: Nav| ….
Structs§
- Children
- The slot a
Layoutrenders its child (a nested layout, a page or an error page) into. Layout views get it as their second argument. - Layout
- A layout wrapping every page of a
Router, including those of nested routers. - Page
- A page: an optional
loadhandler and a view. - View
Context - What a view’s extractors are extracted from: the app state, the page and the view’s data.
Traits§
- Handler
- An async function whose arguments are all
FromRequestextractors. - Layout
View - A layout view:
Fn(&mut Ui, Children, T1, …, T16)where everyTis aFromViewextractor. - View
- A page or error view:
Fn(&mut Ui, T1, …, T16)where everyTis aFromViewextractor, in any order.Tis a tuple of the extractor types and only keeps the implementations apart.