Skip to main content

Module env

Module env 

Source
Expand description

Env: the host facts a frame driver pushes into the core, which a view reads back with ui.env().

The core never touches a window. The driver (a runner, an FFI host) reports what it knows: the refresh rate and whether the window has focus (Env), the window’s own facts (WindowEnv), and the user’s OS settings (SystemEnv: appearance, accent, reduced motion, locale, assistive technology). A view reads them and decides; the core acts on none of them except to derive the Theme from the appearance and accent.

Every fact under SystemEnv can be unknown, and unknown is the default. A driver that cannot ask the OS says so rather than guessing, and a headless Core reports unknown for all of them.

use kui_core::{Core, Env, MotionPref, Size};

let mut core = Core::new();
let ui = core.frame(Size::new(100.0, 100.0), 1.0);
let env: Env = ui.env();
assert_eq!(env.system.motion, MotionPref::Unknown); // headless: nobody said
assert!(env.frame_budget_ms() > 0.0);
ui.finish();

Structs§

AudioEnv
What the driver’s audio output is doing, for views to read. A fact, not a verb: nothing here lets a view close the device, which stays the driver’s decision (it closes an idle one itself, after a while).
Env
What the host knows about the display/window. Defaults are safe for headless drivers (tests, benches) that never set anything.
Locale
A language tag as the host reports it — "en", "en-US", "zh-Hans-CN". Carried inline rather than as a String so Env stays Copy: a view reads ui.env() every frame, and a tag that allocated would allocate on every one of them.
SystemEnv
The user’s OS settings, as the host reports them. Not window facts and not display facts: things the person chose once, in a settings app, that a view is expected to honour. The core acts on two of them in one way: appearance and accent derive the theme, so the stock widgets and a <text> with no colour follow the OS — and nothing else moves. Reduced motion does not shorten an animation and a dark appearance repaints none of the app’s own colours: the view decides, because only it knows which of its colours is the background and which of its animations carries meaning.

Enums§

Appearance
The OS light/dark setting. Unknown is a real answer — a host with no way to ask says it, and a view that has one palette per appearance picks its own default for it rather than being handed a guess.
Assistive
Whether assistive technology is listening: the difference between an alert that blinks and one that announces. Listening is “an accessibility client has asked this window for its tree”, which is the one signal the platform adapters give and the moment the runner starts deriving trees. None is “the bridge is up and nobody has asked”; Unknown is “there is no bridge” — a headless core, a driver built without the accesskit feature, a C host that never called the setter.
AudioDevice
The output device’s state. Closed is the default and what a headless driver reports; Opening is the ~90 ms the open takes on its own thread; Failed is a device that refused to open, after which commands are dropped.
MotionPref
The OS reduce-motion setting: Reduced is “the user asked for less animation”, Full is “the user did not”, Unknown is “nobody asked the OS”. Spelled as what the user wants rather than as a reduce_motion boolean because the third reading has no place in a boolean, and a missing answer is not the same as a “no”.