Create your first window
Launch a native or browser window and render one retained Argui element.
One model, one presentation
A small application implements Render. The runtime owns the event loop and asks the model for an Element tree when its presentation is dirty. The same entry path supports desktop and WebAssembly.
use argui::{
platform::{ApplicationConfig, ApplicationId, ApplicationIdentity, IconSet, WindowConfig},
render::RendererConfig,
runtime::{run_app, Context, Render},
ui::Element,
};
#[derive(Default)]
struct App;
impl Render for App {
fn render(&mut self, _cx: &mut Context<Self>) -> Element {
Element::text("Hello from Argui")
}
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let identity = ApplicationIdentity::new(
ApplicationId::new("dev.example.hello")?,
"Hello Argui",
IconSet::default(),
);
run_app(
ApplicationConfig::new(identity, WindowConfig::default()),
RendererConfig::default(),
App,
|event| println!("{event:?}"),
)?;
Ok(())
}Configure identity and window
ApplicationIdentity gives the application a stable reverse-domain identifier, display name, and icons. WindowConfig documents each public field in cargo doc and your IDE, including logical size, decorations, transparency, canvas attachment, pointer behavior, safe areas, and initial focus.
focus_on_launch defaults to true on native targets and false on WebAssembly. The Web default keeps an embedded canvas from taking focus and moving the surrounding page while it loads; clicks and touches still focus it normally.
Keep accessibility zoom coherent
Application-wide UI zoom is enabled by default. Ctrl or Command with + and - changes the zoom on native and WebAssembly hosts, Ctrl or Command with 0 restores 100%, modifier-wheel and trackpad magnification provide continuous desktop zoom, and a two-finger pinch provides the touch equivalent on mobile.
Argui combines the zoom with native DPI before layout and rendering, so text, geometry, hit testing, scrolling, IME placement, accessibility bounds, popups, backdrops, and hosted WebViews remain aligned. Every open application window receives the same factor through WindowEnvironment::ui_zoom.
use argui::platform::UiZoomConfig;
let config = ApplicationConfig::new(identity, window)
.with_ui_zoom(UiZoomConfig::disabled());Keep startup errors visible
Return a Result from main and report RuntimeEvent failures. Renderer, layout, and command failures are explicit events; production applications should send them to their logging or crash-reporting path.
Reference files
These are the implementation and guide files used for this chapter.
crates/argui/examples/window.rscrates/argui-runtime/src/launch.rsdocs/platform/application.mdA compiled responsive application window
The Rust file below is imported verbatim by this page and compiled into the WebAssembly application running underneath it.
use argui::{
paint::{Border, CornerRadii},
runtime::{Context, Render},
text::TextStyle,
ui::{AlignItems, Element, JustifyContent, Sides, length, percent},
widgets::default_theme,
};
pub struct Example;
impl Render for Example {
fn render(&mut self, cx: &mut Context<Self>) -> Element {
let themes = default_theme(cx.environment());
let theme = themes.resolve(cx.environment().color_scheme);
let heading = Element::text("Hello from Argui").text_style(TextStyle {
font_size: 34.0,
line_height: 42.0,
color: theme.foreground,
weight: 720,
..TextStyle::default()
});
let copy = Element::text(
"The same retained Rust model runs in this browser and on native desktop.",
)
.text_style(TextStyle {
color: theme.muted_foreground,
..TextStyle::default()
});
let card = Element::column([heading, copy])
.width(length(560.0))
.max_width(percent(1.0))
.padding(Sides::length(30.0))
.gap(14.0)
.background(theme.card)
.border(Border::all(1.0, theme.border))
.radius(CornerRadii::all(16.0));
Element::container([card])
.width(percent(1.0))
.height(percent(1.0))
.padding(Sides::length(20.0))
.align_items(AlignItems::CENTER)
.justify_content(JustifyContent::CENTER)
.background(theme.background)
}
}
Starting this lesson’s WebAssembly module…