Skip to content
Development

Open a window ​

Start with a self-contained example to see how mirui arranges containers and text inside a window, then bring that structure into the task list.

1. Minimal demo: Column, Row, and Text ​

In mirui, a screen is a ui! tree returned by a #[compose] function. Column stacks children vertically, Row places them side by side, and grow: 1.0 shares the remaining space evenly:

CONCEPT
279#[compose]
280fn mini_window_scene() {
281 ui! {
282 Column (
283 grow: 1.0,
284 padding: Padding::all(20),
285 row_gap: 12,
286 text_color: ColorToken::OnSurface
287 ) {
288 Column (
289 height: 64,
290 padding: Padding::all(14),
291 justify: JustifyContent::Center,
292 bg_color: ColorToken::Secondary,
293 border_radius: 10
294 ) {
295 Text ("Hello Mirui", font_size: 24, height: 32, text_color: ColorToken::OnSecondary)
296 }
297 Row (height: 44, column_gap: 10) {
298 Column (
299 grow: 1.0,
300 padding: Padding::all(12),
301 bg_color: ColorToken::SurfaceVariant,
302 border_radius: 8
303 ) {
304 Text ("First row", font_size: 13, height: 20)
305 }
306 Column (
307 grow: 1.0,
308 padding: Padding::all(12),
309 bg_color: ColorToken::SurfaceVariant,
310 border_radius: 8
311 ) {
312 Text ("Second row", font_size: 13, height: 20)
313 }
314 }
315 }
316 };
317}
Loading preview…

Drag the grip at the bottom-right corner to resize the viewport and see the two grow: 1.0 cards split the row width.


2. In the task list: the first screen ​

In chapter 1 we mount a dark Task list header block with two static rows underneath. Click the desktop.rs tab or toggle the eye button to see how SdlSurface creates the native window and calls install:

CHAPTER 01 · ENTITY & LAYOUT TREE UMLHost Surface, Root Entity & Flexbox UI Tree Ownership

`SdlSurface::new("Task list", 420, 440)` (or `WebCanvasSurface` in browser) provides the physical backing target and logical viewport dimensions.

let mut app = App::new(SdlSurface::new("Task list", 420, 440));Platform-independent Surface trait boundary
01 / 07
lib.rs · desktop.rs Added in this step41 lines
⋯lib.rs:63
63 let root = app.spawn_root().id();
64 if chapter.0 == 1 {
65 app.compose(root, first_window());
66 return None;
67 }
⋯lib.rs:116
116#[compose]
117fn first_window() {
118 ui! {
119 Column (grow: 1.0, padding: Padding::all(20), row_gap: 16) {
120 Column (
121 height: 76,
122 padding: Padding::all(16),
123 bg_color: ColorToken::Secondary,
124 border_radius: 12
125 ) {
126 Text ("Task list", font_size: 32, height: 44, text_color: ColorToken::OnSecondary)
127 }
128 Text ("Connect the display", height: 26)
129 Text ("Open a window", height: 26)
130 }
131 };
132}
⋯desktop.rs:6
6fn main() {
7 let chapter = std::env::args()
8 .nth(1)
9 .and_then(|arg| arg.parse().ok())
10 .and_then(Chapter::new)
11 .unwrap_or(Chapter::FINAL);
12 let storage = if chapter.has_storage() {
13 Some(
14 FileStorage::open("task-list.mirui")
15 .expect("open task storage")
16 .into_handle(),
17 )
18 } else {
19 None
20 };
21 let mut app = App::new(SdlSurface::new("Task list", 420, 440));
22 install(&mut app, chapter, false, storage);
23 app.run();
24}
Loading preview…

Switch to the desktop.rs tab at the top of the source pane to inspect how the native launcher passes SdlSurface into install.

What changed in this step ​

  1. Host vs. UI tree: In desktop.rs, SdlSurface::new("Task list", 420, 440) claims an OS window; in lib.rs, app.spawn_root().id() creates a viewport-filling root entity and app.compose(root, first_window()) mounts the widget tree onto it.
  2. Semantic color tokens: Instead of hardcoded hex values, the header uses ColorToken::Secondary and ColorToken::OnSecondary. Toggle the site's light/dark theme button in the top bar—the canvas adapts automatically.

Run on your machine ​

sh
cargo run -p mirui-first-app --features desktop --example desktop -- 1