Component · crate
libbhoo
Minimal GUI foundations for SpectreOS, written in Rust. Package libbhoo, Rust API bhoo.
Inspired by CUI's immediate-mode approach, the core provides controlled widgets, shared pointer/keyboard state, focus, bounded motion and effects, cached labels, semantic snapshots, clipping, fixed-height list virtualization, and Android XML layout/widget support. The Cargo package is libbhoo and the library is imported as bhoo; every native SpectreOS app is written in Rust against it.
#Install
cargo add libbhoo --features waylandor in Cargo.toml:
[dependencies]
libbhoo = { version = "0.2", features = ["wayland"] }use bhoo::window::{self, FrameAction, WindowOptions};#Feature flags
| Feature | What it enables |
|---|---|
| (default) | The core engine only: Ui, Frame, input, motion, widgets and the Android XML runtime, with no GPU or windowing dependencies. |
gles | The OpenGL ES building blocks: glow, harfrust, skrifa, zeno, unicode-bidi and bytemuck for text shaping, glyph rasterization and vertex upload. |
wayland | Implies gles, and adds winit, glutin, glutin-winit and raw-window-handle for a native Wayland window with an explicitly requested GLES 3.0 context. |
#Architecture and backends
- Native Wayland + GLES 3.0.
winitprovides the Wayland window and events,glutinthe EGL surface with VSync,glowthe GLES calls with custom GLSL ES 3.00 shaders (src/platform/gles/shaders.rs). Text and geometry share one indexed draw batch with premultiplied alpha. It requires Linux, a Wayland compositor, EGL with OpenGL ES 3.0 or newer, libxkbcommon and a TTF/OTF font, and does not fall back to X11 or desktop OpenGL. - WebAssembly. The same Rust core compiles to
wasm32-unknown-unknown. The web demos paint the toolkit'sDrawCommands throughcodes/apps/bhoo-web/site/canvas-painter.js(see Bhoo web demos). - Design systems.
src/systems/material/holds Material Design 3 native widgets (one file per family) andsrc/systems/android/holds Android state models and the XML layout/menu runtime. Motion is analytical and critically damped; shared physics (motion.rs,timing.rs,scroll.rs,ripple.rs) stays design-system-agnostic. - Headless tests. A Weston + Mesa software-rendering test checks launcher and gallery pixels at 1× and 2× scale.
#Immediate-mode frame model
You hand window::run a callback that is invoked once per frame. Inside it you describe the UI with widgets, and the callback returns a FrameAction:
FrameAction::Waitis the normal return. The runner still requests more frames while core effects are active, and otherwise waits for input or tooltip deadlines.FrameAction::Redrawasks for another frame for application-owned animation.FrameAction::Exitsubmits the final frame and closes.
CPU and GPU buffers retain capacity, labels use a bounded shared-text cache, and the glyph atlas is uploaded only when it changes.
This is the repository's launcher example (examples/launcher.rs):
use bhoo::window::{self, FrameAction, WindowOptions};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let smoke_test = std::env::args().any(|arg| arg == "--smoke-test");
let mut clicks = 0;
let mut frames = 0;
let options = WindowOptions {
title: "Bhoo · SpectreOS".into(),
size: [440, 360],
capture: std::env::var_os("BHOO_CAPTURE").map(Into::into),
..WindowOptions::default()
};
window::run(options, move |frame| {
frames += 1;
frame.label("Bhoo / SpectreOS");
frame.label("Wayland + OpenGL ES 3");
if frame.button(1, "Say bhoo!").clicked {
clicks += 1;
}
frame.label(format!("Ghosts summoned: {clicks}"));
if frame.button(2, "Close window").clicked || (smoke_test && frames >= 4) {
FrameAction::Exit
} else if smoke_test {
FrameAction::Redraw
} else {
FrameAction::Wait
}
})
}#Run the examples
From codes/libs/ui/libbhoo/ (run make help for every build, test, web and WebXDC target):
make help
make test
make run-launcher
make run-components
make webxdc-galleryThe launcher opens a window with a working click counter and a close button (Escape also closes it) and must be run inside an active Wayland session. If no default font can be found, supply one explicitly, which is useful on NixOS:
BHOO_FONT=/absolute/path/to/font.ttf cargo run --release --features wayland --example launcher#Project Layout & Development Guide
libbhoo is organized so every subsystem has one predictable home and scales cleanly across multiple design systems (Material, Android, and future systems such as Apple HIG / Cupertino) and platform backends:
codes/libs/ui/libbhoo/
├── src/
│ ├── lib.rs, motion.rs, timing.rs, scroll.rs, media.rs, ripple.rs
│ │ → Core UI engine (Ui, Frame, Input, DrawCommand, physics)
│ ├── platform/ → OS windowing (window.rs) & GPU renderer (gles/)
│ ├── icons/ → Bundled icon catalogs (Material Symbols, 59 Material system icons, Android icons)
│ ├── shapes/ → Auto-generated non-icon vector shapes + shape_data()
│ └── systems/ → Design systems & UI compatibility layers
│ ├── material/ → Material Design 3 / Bhoo native widgets (1 file per family)
│ └── android/ → Android state models (state/), XML runtime (xml/), reference bridge
├── tests/
│ ├── allocations.rs → Standalone #[global_allocator] heap-allocation test
│ ├── core/ → Core cross-module integration tests
│ ├── material/ → Cross-component Material integration tests
│ └── android/ → End-to-end Android XML fixture integration tests
├── docs/ → Technical design docs, component specs, motion & review records
├── examples/ → Native Wayland/GLES demos & capture harnesses
└── DEVELOPMENT.md → Full architecture, folder rules, testing rules & extension recipesUnit tests live next to their source file with the exact same filename stem (card.rs + card.spec.rs); multi-module and fixture-based integration tests live in tests/. Read DEVELOPMENT.md for the full folder guide, test commands, and step-by-step instructions for adding widgets, shapes, backends, or new design systems.
#Validation
cargo test --all-features
cargo test --test allocations
cargo clippy --all-targets --all-features -- -D warningsFrom the repository root, run the headless graphics test with Weston installed:
python3 tools/test-bhoo-wayland.pyIt starts isolated Weston sessions at 1× and 2× scale and checks launcher/gallery framebuffer pixels, disabled fill, text and clipping, including the gallery with reduced motion. It uses Mesa software rendering for repeatability; it is not a hardware performance benchmark.
Dev/test builds omit debug information and incremental caches; release strips symbols and uses thin LTO. Use cargo clean --profile dev to reclaim debug/test build artifacts while retaining release output.
For a diagnostic screenshot inside a Wayland session:
BHOO_CAPTURE=/tmp/bhoo.ppm cargo run --features wayland --example launcher -- --smoke-testKeep Ui between frames and supply pointer press/release edges to Ui::frame, or reuse a command buffer with Ui::frame_into. Build widgets each frame with unique, stable widget IDs. Application state stays with the caller.
Licensed under the GNU GPL v3.
#More documentation
Technical design documents, the component catalog, motion records and the Android UI and Material Design 3 parity goal live in the repository under codes/libs/ui/libbhoo/docs/. Components are documented one family per file, with their variants, tokens and motion.
#libbhoo Development Guide
This guide documents the architecture, folder layout, testing rules, and extension recipes for libbhoo (Rust crate bhoo).
Every directory has one clear responsibility so that adding a widget, a new design system (such as Apple HIG / Cupertino), an icon set, or a new platform renderer has one predictable home.
#Folder Structure
codes/libs/ui/libbhoo/
├── Cargo.toml
├── Makefile ← Local build, test, Wayland, WASM, WebXDC & review targets (`make help`)
├── README.md
├── DEVELOPMENT.md ← This guide
├── assets/ ← Bundled raster assets (e.g. 9-patch / Android drawables)
├── docs/ ← Technical design docs, component specs, motion & review records
├── examples/ ← Native Wayland/GLES example apps & capture harnesses
│
├── src/ ← Production code + strict 1-to-1 unit specs (`<file>.spec.rs`)
│ ├── lib.rs (+ lib.spec.rs) ← Core engine: Ui, Frame, Input, Rect, Color, Theme, DrawCommand,
│ │ Role, SemanticNode, public re-exports
│ ├── media.rs (+ media.spec.rs)
│ ├── motion.rs ← Spring physics and motion schemes
│ ├── timing.rs ← Tween and cubic-bezier easing
│ ├── scroll.rs ← Scroll physics, spline fling, overscroll edge stretch
│ ├── ripple.rs ← Press ink/ripple state machine
│ │
│ ├── platform/ ← OS windowing and GPU renderer backends
│ │ ├── mod.rs
│ │ ├── window.rs ← Wayland windowing runner (feature = "wayland")
│ │ └── gles/ ← OpenGL ES 3.0 renderer (feature = "wayland")
│ │ ├── mod.rs ← Renderer lifecycle, FBO layers, vertex flush, capture
│ │ ├── atlas.rs ← Glyph and image texture atlas packing
│ │ ├── commands.rs ← DrawCommand execution loop
│ │ ├── fonts.rs ← System font discovery, weight/italic selection, TextMetrics
│ │ ├── geometry.rs ← Affine2D transforms and quad/shape/polyline mesh builders
│ │ └── shaders.rs ← GLSL ES 3.00 vertex & fragment shaders
│ │
│ ├── icons/ ← Bundled vector & raster icon catalogs + decoders
│ │ ├── mod.rs
│ │ ├── material_symbols.rs (+ material_symbols.spec.rs)
│ │ ├── material_system.rs (+ material_system.spec.rs — 59 Material Outlined RLE4 icons)
│ │ ├── material_navigation.rs
│ │ ├── material_card.rs
│ │ ├── android_search.rs
│ │ └── android_time_picker.rs
│ │
│ ├── shapes/ ← Auto-generated non-icon vector shapes (never hand-edited)
│ │ ├── mod.rs ← Shared shape_data(index) lookup across shapes & vector icons
│ │ ├── beercss_shapes.rs (+ beercss_shapes.spec.rs)
│ │ ├── loading_shapes.rs
│ │ └── android_clock_shapes.rs
│ │
│ └── systems/ ← Design systems & platform UI compatibility layers
│ ├── mod.rs
│ ├── material/ ← Material Design 3 / Bhoo native widgets (1 file per family)
│ │ ├── mod.rs ← Module declarations, re-exports, shared control helpers
│ │ ├── app_bar.rs (+ app_bar.spec.rs)
│ │ ├── avatar.rs (+ avatar.spec.rs)
│ │ ├── badge.rs (+ badge.spec.rs)
│ │ ├── card.rs (+ card.spec.rs)
│ │ ├── menu.rs (+ menu.spec.rs)
│ │ ├── navigation.rs (+ navigation.spec.rs)
│ │ ├── overlay.rs (+ overlay.spec.rs)
│ │ ├── scrollbar.rs (+ scrollbar.spec.rs)
│ │ ├── transitions.rs (+ transitions.spec.rs)
│ │ └── ... (button, fab, fab_menu, chip, slider, switch, tabs, toolbar, etc.)
│ └── android/ ← Android UI compatibility layer
│ ├── mod.rs
│ ├── reference.rs ← Static Android NativeNode resource-tree bridge
│ ├── state/ ← Pure-Rust Android widget state machines (1 file + 1 .spec.rs each)
│ │ ├── mod.rs
│ │ ├── calendar.rs (+ calendar.spec.rs)
│ │ ├── date_spinner.rs (+ date_spinner.spec.rs)
│ │ ├── dialer_filter.rs (+ dialer_filter.spec.rs)
│ │ ├── expandable_list.rs (+ expandable_list.spec.rs)
│ │ ├── number_picker.rs (+ number_picker.spec.rs)
│ │ ├── time_clock.rs (+ time_clock.spec.rs)
│ │ └── time_spinner.rs (+ time_spinner.spec.rs)
│ └── xml/ ← Android XML layout, drawables, solvers & painters
│ ├── mod.rs, state.rs, specs.rs, drawables.rs, text.rs, helpers.rs,
│ ├── measure.rs, render.rs, draw.rs, draw_adapter_views.rs,
│ └── draw_containers.rs, draw_widgets.rs, constraint_layout.rs, relative_layout.rs
│
└── tests/ ← Integration & cross-module tests (mirrored by area)
├── allocations.rs ← Standalone heap-allocation test (uses #[global_allocator])
├── core/ ← Core cross-widget / frame integration tests (`main.rs` + modules)
├── material/ ← Cross-component Material composition tests (`main.rs` + modules)
└── android/ ← End-to-end Android XML fixture & layout tests (`main.rs` + modules)#Where Does New Code Go?
| What you are adding | Where it goes |
|---|---|
Core input, focus, DrawCommand, animation, or scroll primitive | src/ root (lib.rs, motion.rs, scroll.rs, etc.) |
| A new Material / Bhoo widget family | src/systems/material/<widget>.rs + src/systems/material/<widget>.spec.rs |
| A new Android widget state machine | src/systems/android/state/<widget>.rs + <widget>.spec.rs |
| Android XML layout, drawable, or widget painting | src/systems/android/xml/ |
| A new design system (e.g. Apple HIG / Cupertino, Fluent, Spectre) | src/systems/<system>/ (e.g. src/systems/apple/) |
| A new bundled icon set (vector or raster) | Generator in tools/generate-*.py → src/icons/<name>.rs, registered in src/icons/mod.rs (and src/shapes/mod.rs::shape_data if vector ShapeData) |
| A new bundled non-icon vector shape set | Generator in tools/generate-*.py → src/shapes/<name>.rs, registered in src/shapes/mod.rs |
| A new windowing or GPU renderer backend (e.g. Vulkan, Metal) | src/platform/<backend>/ |
Unit tests for a single source file <name>.rs | <name>.spec.rs right beside <name>.rs (exact same filename stem) |
| Integration tests spanning multiple modules, XML fixtures, or public API flows | tests/<area>/ (tests/core/, tests/material/, tests/android/, future tests/apple/) |
| Component specifications, motion docs, validation & review records | docs/ (see docs/components/README.md) |
#Testing Guidelines: Unit Specs (*.spec.rs) vs. Integration Tests (tests/)
#1. Unit tests (<name>.spec.rs — strict 1-to-1 naming rule)
Unit tests live directly next to the source file they test using the exact same filename stem plus .spec.rs (like Angular's .spec.ts):
src/systems/material/
├── card.rs
└── card.spec.rsStrict rules:
- Every
<name>.spec.rsMUST have a matching<name>.rsin the same folder. Never create an orphan spec likestates.spec.rswithoutstates.rs, or split multiple differently named.spec.rsfiles for one.rsfile. - If a single source file has several unit-test groups (for example
app_bar.rscovering top & bottom app bars, ornavigation.rscovering bar, rail, and chrome), group them as submodules (mod top_app_bar { ... },mod bottom_app_bar { ... }) inside the one matchingapp_bar.spec.rs/navigation.spec.rs. - Wire
<name>.spec.rsat the bottom of<name>.rs:rust #[cfg(test)] #[path = "<name>.spec.rs"] mod tests; - Exception for auto-generated files in
src/shapes/andsrc/icons/: wirebeercss_shapes.spec.rsfromsrc/shapes/mod.rsandmaterial_symbols.spec.rsfromsrc/icons/mod.rsso re-runningtools/generate-*.pydoes not overwrite themoddeclaration (they still keep the exact matching<name>.spec.rsfilename). - Small core modules with only a few private unit tests (
motion.rs,timing.rs,ripple.rs,scroll.rs,platform/window.rs,platform/gles/mod.rs) may keep an inline#[cfg(test)] mod tests { ... }block. src/lib.rsdeclares#[cfg(test)] extern crate self as bhoo;, so bothcrate::*andbhoo::*work inside unit specs.
#2. Integration tests (tests/)
Put tests in tests/ whenever they test integration across multiple modules/components, load external XML layout fixtures (e.g. bhoo-web generated layouts), or require a separate test binary (such as #[global_allocator]):
tests/allocations.rs— standalone binary with a custom#[global_allocator]tests/core/(main.rs+ modules) — multi-widget core engine, state, ripple/hover, and text-metrics integration teststests/material/(main.rs+ modules) — cross-component Material composition & wave suitestests/android/(main.rs+ modules) — end-to-end Android XML fixture, layout container, and widget integration tests- (Future design systems add
tests/<system>/main.rs, e.g.tests/apple/)
#Running tests
# Run everything (all unit specs + all integration suites)
cargo test --locked --all-features
# Run only unit tests (all *.spec.rs + inline unit tests)
cargo test --locked --all-features --lib
# Filter unit specs by module path
cargo test --locked --all-features --lib systems::material::card
cargo test --locked --all-features --lib systems::android::state::calendar
cargo test --locked --all-features --lib icons::
cargo test --locked --all-features --lib shapes::
# Run a specific integration test suite
cargo test --locked --test core
cargo test --locked --test material
cargo test --locked --test android
cargo test --locked --test allocations#Step-by-Step Recipes
#1. Adding a new widget to systems/material/
- Create
src/systems/material/<widget>.rswith its option/state types andimpl Frame<'_>methods. - Create
src/systems/material/<widget>.spec.rs(exact same name) and wire it at the bottom of<widget>.rs:rust #[cfg(test)] #[path = "<widget>.spec.rs"] mod tests; - Declare
mod <widget>;and re-export its public types insrc/systems/material/mod.rs(and insrc/lib.rsif exposed at crate root). - If the widget needs multi-component or fixture-based integration tests, add a module under
tests/material/and register it intests/material/main.rs. - Add or update its component specification under
docs/components/. - Verify with
cargo test --locked --lib systems::material::<widget>.
#2. Adding a new design system (e.g. Apple HIG / Cupertino)
- Create
src/systems/apple/mod.rsand registerpub mod apple;insrc/systems/mod.rs. - Add one file + matching
<widget>.spec.rsper component family insidesrc/systems/apple/(e.g.button.rs+button.spec.rs,sheet.rs+sheet.spec.rs,theme.rs). - If needed, add cross-component integration tests in
tests/apple/main.rs. - Keep shared physics (
motion.rs,timing.rs,scroll.rs) and rendering (DrawCommand,platform/gles/) design-system-agnostic; if Apple needs new rendering primitives (such as backdrop blur / vibrancy), add aDrawCommandvariant insrc/lib.rsand implement it insrc/platform/gles/(andcodes/apps/bhoo-web/site/canvas-painter.jsfor web demos). - If Apple needs bundled vector or raster icons, add a generator in
tools/outputting tosrc/icons/and register it insrc/icons/mod.rs(andsrc/shapes/mod.rs::shape_dataif usingShapeData).
#3. Adding bundled icons or shapes
- Add or update the generator script in
tools/generate-*.pyto emit icons intocodes/libs/ui/libbhoo/src/icons/<name>.rsor non-icon shapes intocodes/libs/ui/libbhoo/src/shapes/<name>.rs. - Declare the module in
src/icons/mod.rsorsrc/shapes/mod.rs, and register any vectorShapeDataindex range insrc/shapes/mod.rs(shape_data). - Record license and attribution details in the repo-root
THIRD_PARTY_NOTICES.md(../../../../THIRD_PARTY_NOTICES.md) anddocs/licenses-and-attribution.md.
#Validation & Quality Checks
From codes/libs/ui/libbhoo/:
cargo check --locked --no-default-features
cargo check --locked --all-features --examples
cargo test --locked --all-features
cargo clippy --locked --all-targets --all-features -- -D warningsFrom the repository root:
# Symlink project docs into root docs/
make init
# Check the browser/WASM demo crate against libbhoo
cargo check --manifest-path codes/apps/bhoo-web/Cargo.toml --locked
# Headless Wayland/Weston pixel test
python3 tools/test-bhoo-wayland.py