WeaveUI

Developer handbook

From an empty Windows checkout to a working Mora window. This guide describes the current prototype and its limits.

Build your first window

Use Windows 10 (1703 or newer) or Windows 11 x64. You need access to the private WeaveUI repository, PowerShell, Mora 0.4.1 and a MinGW-w64 GCC targeting x64. Run these commands from the repository root.

git clone https://github.com/MuaraAI/WeaveUI.git
cd WeaveUI
mora --version
gcc -dumpmachine

The GCC target should be x86_64-w64-mingw32. Start with stock Mora; this path does not require Rust or the arena patch.

.\build.ps1 -Mora mora -StandardArena
.\build\WeaveUICounter.exe

Click Tambah 1 to increment, or press Tab to move focus and Space or Enter to activate a button. Narrow the window until the two actions stack. Build the second example with -Example Status and open build\WeaveUIStatus.exe.

Where each piece lives

examples/counter.mr
Smallest complete app. It uses the counter helper and sets a maximum value.
examples/status.mr
Application-owned state and two independent Mora functions. Start here if your buttons do different things.
src/panel.mr
Counter, Panel and Action. Maps window events to application actions and skips unchanged values.
src/column.mr
Readable view declarations. Chooses control IDs, default sizes, spacing and breakpoint behavior.
src/ui.mr
Geometry, stacks, wrapping cells, styling and the foreign-function declarations for the platform bridge.
platform/windows/win32.c
Creates native windows and controls. Owns system input, fonts, DPI conversion, focus and the blocking message loop.
build.ps1
Checks the selected .mr example and links the native output with the platform bridge.
toolchain/
Contains the optional Mora 0.4.1 compiler patch. Applications do not load a separate arena library.
tests/flow.mr
Checks cell boundaries, rounding and stack positions without showing a window.
tests/smoke.ps1
Drives real Windows controls and optionally measures layout and input latency.
build/
Local generated executables. This is output, not framework source.
docs/
Static documentation and a browser simulation. The site does not run the native renderer.

Two complete Mora apps

Counter: use a built-in behavior

import "../src/panel.mr"

fn main() {
    counter("Counter", "Total", "Tambah 1", "Reset", 99999999)
}

The five arguments set the title, value label, increment label, reset label and maximum. The count starts at zero. No event loop is needed in the application.

Status: own the behavior

import "../src/panel.mr"

fn start_work() -> str { return "Fokus" }
fn take_break() -> str { return "Istirahat" }

fn main() {
    var panel = open_panel("Status kerja", "Mode sekarang", "Mulai", "Jeda")
    var status = "Siap"
    while true {
        match panel.next(status) {
            Action::Primary => { status = start_work() }
            Action::Secondary => { status = take_break() }
            Action::Closed => { return }
        }
    }
}

panel.next(status) writes the value only if it changed, handles resize internally, then returns the next action. Change the button caption without changing the action enum. Returning on Closed exits the app.

Choose an API layer

Panel API · src/panel.mr
counter(title, caption, increment, reset, maximum) runs a bounded counter. open_panel(title, caption, primary, secondary) returns a Panel. Bind it with var because next(value) updates cached state. Actions are Primary, Secondary and Closed.
Column API · src/column.mr
After opening the window, call column() once per view construction. heading(text) and text(caption) place labels. value(text) and button(caption) return control IDs; buttons(first, second) returns a ButtonPair with primary and secondary IDs. label(caption, height, style) is the explicit-size escape hatch.
Geometry · src/ui.mr
container(width, inset, maximum) creates a centered Box. content_box(width) uses a 20-unit inset and caps content at 640. stack(box, top, gap) returns a cursor; rows.take(height) returns a Cell and advances it. Pass the result to cell_label or cell_button.
Wrap arbitrary items
flow_cell(box, top, index, count, flow) returns one cell's bounds without visiting earlier items. Use a positive count, a zero-based index below count, positive minimum width and height, and a nonnegative gap. button_pair is the low-level helper when assigning IDs yourself.
Platform calls
ui_open(title) creates the window. ui_width() reads logical client width. ui_label and ui_button create or update controls by ID; ui_set_text(id, text) updates a caption without laying out siblings. ui_next() returns 0 on close, −1 on resize, or the activated button ID.

The column is positional, not a dynamic list reconciler. Reconstruct controls in the same order on resize. Do not create two independent columns in the same view: their generated IDs would overlap.

Layout, style and input

Dimensions are logical Windows pixels. The bridge converts them to device pixels at the current DPI. The default action pair uses a 12-unit gap and a minimum width of 234 per button. It needs 480 units of content width, or 520 units of client width with the default margins. Below that point the second button moves down.

What happens after a click?

  1. Windows sends a button event to the bridge. The bridge returns the control ID to Mora.
  2. Panel maps the ID to an Action. Application code changes its state.
  3. The next call to panel.next compares the displayed and requested values. Only a changed caption is sent to Win32. A resize takes the layout path instead.

Stable native handles preserve keyboard focus during reflow. The application waits for input rather than running a permanent animation loop.

Customize before opening the window

ui_style(15921654, 1581093, 16, 26, 52)
ui_open("My window")

The first two values are 24-bit RGB background and foreground colors. The last three are logical font heights for body, heading and display text. Omit the call for system defaults. Windows high contrast overrides custom colors. Buttons retain Windows styling.

Current boundaries

One window, up to 32 stable controls. No removal API, custom renderer, transition engine or virtual list yet. Text sent to the bridge must fit its 256 UTF-16 code-unit buffer including the terminator. These are prototype limits, not design targets.

Build with a smaller native arena

Use this path to reduce private committed memory. It requires Rust, Cargo and Git in addition to GCC. From WeaveUI, with no existing sibling Mora checkout:

git clone --branch v0.4.1 --depth 1 https://github.com/MuaraAI/Mora.git ../Mora
git -C ../Mora apply ../WeaveUI/toolchain/mora-0.4.1-small-arena.patch
cargo build --manifest-path ../Mora/Cargo.toml --locked --bin mora --no-default-features --features cli
.\build.ps1
.\build\WeaveUICounter.exe

The build script finds the patched compiler in the sibling checkout. The first slab per arena starts at 4 KiB instead of 4 MiB. Larger requests still fit and later slabs retain the stock minimum. The executable itself does not require Cargo or the compiler at launch.

In two local counter runs per configuration, private commit fell from 5.61–5.63 MiB to 1.47 MiB. The optimized counter's private resident memory was 1.00–1.01 MiB and total working set was 9.60 MiB. These measure different things; they are not a universal RAM guarantee.

Test, measure and troubleshoot

Use an interactive Windows desktop. Run each test in a fresh PowerShell process so the native test helper is loaded once.

.\build.ps1
.\build.ps1 -Example Status
powershell -NoProfile -File tests/smoke.ps1 -Exe build/WeaveUICounter.exe
powershell -NoProfile -File tests/smoke.ps1 -Exe build/WeaveUIStatus.exe -Status
powershell -NoProfile -File tests/smoke.ps1 -Exe build/WeaveUICounter.exe -Benchmark

With stock Mora, append -Mora mora -StandardArena to both build commands. Smoke tests cover clicks, keyboard activation, focus, resize and clean exit. Benchmark mode measures startup to a visible handle, working set, resize to observed geometry and click to observed label. It does not measure display presentation latency.

Compiler lacks --small-arena
Use the stock command in Getting Started or build the patched compiler above. This flag is local to the patch, not part of stock 0.4.1.
GCC not found
Check Get-Command gcc and gcc -dumpmachine in the same shell that runs the build.
Source links return 404
Sign in to GitHub with access to MuaraAI/WeaveUI. The standalone handbook and demos do not need a GitHub session.

Release review: complete source

One approval per item, one aggregate count, and separate navigation actions. Source and state belong to the Mora app. See the Windows app and download it.

import "../src/column.mr"

schema Controls {
    progress: i64
    item: i64
    state: i64
    actions: ButtonPair
    home: i64
}

fn layout() -> Controls {
    var page = column()
    page.heading("Release review")
    let progress = page.label("", 24, 0)
    let item = page.label("", 36, 1)
    let state = page.label("", 24, 0)
    let actions = page.buttons("Next item", "Toggle approval")
    let home = page.button("First item")
    return Controls { progress: progress, item: item, state: state, actions: actions, home: home }
}

fn main() {
    ui_style(16777215, 1513239, 15, 24, 40)
    ui_open("WeaveUI | Release review")
    let items = ["Keyboard navigation", "Compact layout", "Window lifecycle"]
    var approved = [false, false, false]
    var current = 0
    var total = 0
    var controls = layout()
    var event = -1
    while event != 0 {
        if event == controls.actions.primary {
            current = current + 1
            if current == len(items) { current = 0 }
        }
        if event == controls.home { current = 0 }
        if event == controls.actions.secondary {
            if approved[current] { total = total - 1 } else { total = total + 1 }
            approved[current] = !approved[current]
        }
        if event == -1 || event == controls.actions.secondary {
            ui_set_text(controls.progress, str(total) + " / " + str(len(items)) + " approved")
        }
        ui_set_text(controls.item, items[current])
        if approved[current] { ui_set_text(controls.state, "Approved") }
        else { ui_set_text(controls.state, "Needs review") }
        event = ui_next()
        if event == -1 { controls = layout() }
    }
}