Skip to main content

Module page

Module page 

Source
Expand description

Pages and layouts: what a route loads and shows.

A Page is made of two functions:

  • an optional load: an async fn whose arguments are extractors and which returns Result<D, E> with E: Into<Rejection>. Any such function implements Handler. Hooks are handlers too, returning Result<(), E>.
  • a view: a function of &mut egui::Ui and extractors, called every frame. Any such function implements View. 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 Layout renders 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 load handler and a view.
ViewContext
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 FromRequest extractors.
LayoutView
A layout view: Fn(&mut Ui, Children, T1, …, T16) where every T is a FromView extractor.
View
A page or error view: Fn(&mut Ui, T1, …, T16) where every T is a FromView extractor, in any order. T is a tuple of the extractor types and only keeps the implementations apart.