- QuitCommand::Quit (window.quit, Cmd+Q) replaces egui's quit shortcut, which the runtime clears at install. The runtime runs it from any source through the root window's close path, so the app's close decision asks about unsaved work. Its default yields to another command bound to the chord, as the window shortcuts' defaults do (library::yields_default). - HostBuilder::icon_png gives the app's icon once, beside its AppInfo; the update dialogs show it in their head instead of the name's initial. - Docs: craft-framework.md §2.2 Quit and Zoom keys rows, craft-host README.
1.7 KiB
craft-host
The services every Craft library feature reads from the app: who the app is (AppInfo, and its
icon), the catalogs and current language, settings sections, command words and background jobs. The app builds
one Host at startup and installs it on the egui context; features read it with Host::of(ui) and
never take services as parameters.
let host = craft_host::Host::builder(craft_host::AppInfo { id: "photocraft", name: "PhotoCraft", version: "1.0" })
.icon_png(include_bytes!("../assets/icon-128.png"))
.i18n(i18n)
.settings(settings)
.build();
host.install(&ctx); // feature `ui`
Every service has a default, so a test writes Host::builder(app).install(ctx):
| Service | Trait | Default |
|---|---|---|
| Settings sections | SectionStore |
MemorySections |
| Command words | Commands |
NoCommands (English labels) |
| Background work | Jobs |
ThreadJobs; InlineJobs on wasm32 |
| Catalogs | craft_i18n::I18n |
none (English) |
queue::JobQueue runs prioritised background work with one job per key on the host's Jobs.
Stories and tests step it with ManualJobs, which keeps each job until run_next runs it.
Host::install_scoped installs a host until the returned HostScope drops, then puts back the
one installed before. A story swaps in a fake service this way for the time it draws.
Boundaries
- Depends on
craft-i18n,serdeandtomlonly. Implementations depend on this crate:craft-settingsimplementsSectionStore,craft-keymapimplementsCommands. - Feature
uiadds egui forinstallandof. It never depends oncraft-ui. - A settings section is a serde struct saved as one TOML table under
Section::KEY.