Expand description
Runs a densa interface in a native window.
run opens a window, creates a Ui for it and hands it to an App
to fill with widgets. From then on it translates the window system’s input (winit) into
densa_ui events, passes the actions widgets report to the app, and paints the interface
with densa_render (wgpu) in one draw call per frame, presented with V-Sync.
Frames are painted when something changed, when another thread asks for one through a
Waker (new data arrived), or continuously while the app asks for it (animation).
Widgets copy and paste through the system clipboard (on Linux, X11’s; XWayland’s under Wayland).
Screen readers (Narrator, VoiceOver, Orca) read the interface through AccessKit: the
window sends the Ui’s accessibility tree after each frame, only while one is
listening, and carries out what it asks.
The Ui’s text uses densa_paragraph::TextSystem::new: the bundled font, and the
system’s fonts for characters it lacks (Korean, Japanese, Chinese, …). Turning off the
default system-fonts feature leaves the bundled font alone.
use std::error::Error;
use densa_ui::{Ui, Style};
use densa_window::{App, Host, WindowOptions};
struct Hello;
impl App for Hello {
fn build(&mut self, ui: &mut Ui, host: &mut Host<'_>) -> Result<(), Box<dyn Error>> {
// Add widgets under ui.root() here; hand host.waker() to threads that feed them.
let _ = (ui.root(), host.waker());
Ok(())
}
}
densa_window::run(WindowOptions::new("Hello"), Hello)?;Structs§
- Host
- The window an
Appruns in. - Waker
- Asks the window’s thread for a frame, from any thread.
- Window
Options - The window
runopens.
Enums§
- Backend
- The graphics API a window draws with. The
WGPU_BACKENDenvironment variable (vulkan,dx12,metal,gl, comma-separated) overrides it, to try another without rebuilding. When the chosen API gives no device, the window tries every API beforerunfails. - Window
Error - Why
runstopped with an error.
Traits§
- App
- An application: it builds its interface once, then reacts to what widgets report and
updates live content before each frame. Every call gets the
Host: the window it runs in.
Functions§
- run
- Opens a window for
appand runs until it is closed.