Skip to main content

Module settings_pages

Module settings_pages 

Source
Expand description

Custom pages in the settings window (ADR 0013): a page a plugin draws itself, next to the pages generated from declared settings.

A page has an id, a title, a place in the tree (under a section or another page, in an order), keywords the settings search finds it by, and the settings it edits: those leave the generated sections, are searched with the page, and its reset takes them back to their defaults as one undo step, with a hook of its own for what is not a setting. It is mounted through the mount contract in the settings page host (crate::mounts::SETTINGS_PAGE): what its component needs is checked first, and a refusal is reported (ADR 0003) with nothing added. Its body is drawn in a focus scope and a fault boundary, only while it is the page shown.

Agents see the pages in the settings_window collector, and open one with the app.settings.page command ({"page": "<id>"}).

use egui_pop_api::settings_pages::SettingsPage;
use egui_pop_api::{App, Ctx, Plugin, PluginError, DefaultPlugins};
use egui_pop_model::ids::PluginId;

struct Compute;

impl Plugin for Compute {
    fn id(&self) -> PluginId {
        PluginId::from_static("compute")
    }

    fn connect(&mut self, ctx: &mut Ctx<'_>) -> Result<(), PluginError> {
        ctx.settings_page(
            SettingsPage::new("compute.devices", "Compute")
                .keywords(&["GPU", "OpenCL", "threads"])
                .order(10),
            |ui, _app| {
                ui.label("The devices found, and which one runs what.");
            },
        );
        Ok(())
    }
}

let app = App::builder()
    .plugins(DefaultPlugins)
    .plugin(Compute)
    .build(&egui::Context::default())
    .unwrap();
let pages = app.handle().settings_pages();
assert_eq!(pages[0].title, "Compute");
assert!(app.handle().mounts().iter().any(|m| m.host == "settings.page"));

A body is drawn while the settings window holds its own state: it moves the window by commands (app.settings, app.settings.page), which run before the next frame, not through the crate::settings_window::SettingsWindow service directly.

Structs§

SettingsPage
A custom page of the settings window: its place, what finds it, what it edits and what it needs.

Functions§

host
What the settings page host offers a page (ADR 0013): the form’s width and the content’s height in the settings window, a modal (Escape closes the window), transient, the main window, a focus scope and a fault boundary, sRGB; its content is not drawn while another page is shown.

Type Aliases§

ChangedFn
Whether a page’s own state is away from its defaults.
PageFn
A page’s body: drawn every frame the page is shown.
ResetFn
A page’s own reset, for what it shows that is not a setting.