diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index e08b3207..7a4e0652 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -14,10 +14,11 @@ through `gpu/`'s software raster or GPU renderer: tkinter / Qt syntax / components (Python) · Rust (blenderui) · JS / React · Dear ImGui · C │ kit/ node tree · geometry managers · input & interaction · widget drawing · menus - · editors · undo · animation · themes · native windows (Win32, X11, Cocoa) + · editors · undo · animation · themes · touch · accessibility · desktop shell + · native windows (Win32, X11, Wayland, Cocoa, Android) · kit/intern/blender/ (Blender files copied in: string search, UI undo, float precision) │ - gpu/ software raster (default) or GPU renderer (Direct3D 11 / OpenGL 3.3) · text engine + gpu/ software raster (default) or GPU renderer (Direct3D 11 or 12 / OpenGL 3.3) · text engine │ core/ blenlib subset (math, rct, string_search.cc, expr_pylike_eval.cc ...) ``` @@ -65,11 +66,12 @@ include `ui/`.) | `gpu/` | The draw surface used by the toolkit (`GPU_*`, `imm*`) behind seam headers + a null backend that *records and forwards*: with a sink installed it emits screen-space primitives (`GPU_backend_sink.h`); without one it discards them. Theme colors reach the GPU layer through function-pointer hooks. | **Builds + tested** | | `compat/` | Seam headers carrying upstream API names (`RNA_access.hh`, `BLF_api.hh`, …) with BUI-owned opaque types and stub implementations (`intern/bui_stubs.cc`). | **Builds** | | `ui/` | The toolkit sources from `editors/interface`: interface.cc family, widgets, handlers, regions, view2d, views, textbox. Kept for reference and porting work; **not compiled by default** (`-DBUI_BUILD_UI=ON` builds it as `bui_ui`). `kit/` re-ports what it needs in C. | **Compiles + links** (opt-in) | -| `kit/` | Blender's UI as a retained-mode C runtime: node tree, uiLayout-style layout, `interface_handlers.cc` interaction rules, widget drawing ported from `interface_widgets.cc` (widget-base shader parameters rendered by `gpu/` raster), menus, color picker, views, editors; Blender's screen layout (`kit/intern/screen`, ported from `editors/screen`: areas on a graph of shared edges that split, join, dock and resize, regions that resize, hide and flip, saved as JSON); Tk-style pack/grid/place geometry managers, canvas display list, multi-line text area; UI undo/redo, Tab field traversal, vertical multi-drag, panel animation; Blender's file browser; images (`kit/intern/image`: Blender's imbuf design, one format table over Wuffs, libjpeg-turbo, libwebp and BUI's HDR/PNM/SVG readers in `kit/extern`, decode at the drawn size, a worker pool and a memory-budgeted cache; see [the Images page](https://bui.preetham.top/docs/concepts/images/)); damage-driven rendering; Blender's Dark and Light themes (`kit_theme_presets.c`, generated by `tools/gen_theme.py` from Blender's `Blender_Dark.xml` / `Blender_Light.xml` presets over `userdef_default_theme.c`; `BK_set_theme`); native window hosts for Win32, X11 and Cocoa (`kit_window_win32.c`, `kit_window_x11.c`, `kit_window_cocoa.m`; `kit_window_null.c` elsewhere). Touch screens and trackpad gestures live in the kit, not the hosts: `kit/intern/kit_touch.c` is one state machine (Android's model: taps, long presses, scrolls past the touch slop, a second finger's pan, pinch and turn as Blender's `MOUSEPAN` / `MOUSEZOOM` / `MOUSEROTATE`) with the fling in `kit_fling.c` (`VelocityTracker`, `OverScroller`), and every host (Win32 `WM_POINTER`, X11 XInput 2, Wayland `wl_touch` and pointer gestures, Cocoa's magnify and rotate, Android) only forwards contacts to `BK_touch` and trackpad gestures to `BK_magnify` / `BK_rotate` ([docs/touch.md](docs/touch.md)). The Win32 host is BUI's own; the X11 host follows Blender's GHOST input mapping, and the Cocoa host (experimental: checked by CI and tried by hand on two Apple Silicon Macs) is ported from GHOST's Cocoa backend. `kit/intern/blender/` holds Blender files copied in and edited for the kit (each edit marked `BUI:`): `interface_string_search.cc` (menu search with recent searches), `interface_undo.cc` (text-edit undo), `interface_utils.cc` (float display precision). C API: `kit/include/BUI_kit.h`. | **Builds + tested** | +| `kit/` | Blender's UI as a retained-mode C runtime: node tree, uiLayout-style layout, `interface_handlers.cc` interaction rules, widget drawing ported from `interface_widgets.cc` (widget-base shader parameters rendered by `gpu/` raster), menus, color picker, views, editors; Blender's screen layout (`kit/intern/screen`, ported from `editors/screen`: areas on a graph of shared edges that split, join, dock and resize, regions that resize, hide and flip, saved as JSON); Tk-style pack/grid/place geometry managers, canvas display list, multi-line text area; UI undo/redo, Tab field traversal, vertical multi-drag, panel animation; Blender's file browser; images (`kit/intern/image`: Blender's imbuf design, one format table over Wuffs, libjpeg-turbo, libwebp, libtiff, OpenEXRCore, libavif, libjxl, the OS's HEIC decoder and BUI's HDR/PNM/SVG readers in `kit/extern`, decode at the drawn size, a worker pool and a memory-budgeted cache; see [the Images page](https://bui.preetham.top/docs/concepts/images/)); damage-driven rendering; Blender's Dark and Light themes (`kit_theme_presets.c`, generated by `tools/gen_theme.py` from Blender's `Blender_Dark.xml` / `Blender_Light.xml` presets over `userdef_default_theme.c`; `BK_set_theme`); native window hosts for Win32, X11, Wayland, Cocoa and Android (`kit_window_win32.c`, `kit_window_x11.c`, `kit_window_wayland.c`, `kit_window_cocoa.m`, `kit_window_android.c`; `kit_window_null.c` elsewhere); the desktop shell (`kit/intern/shell`: tray icons, notifications, taskbar progress, recent files); one accessibility tree per window (`kit/intern/a11y`, served to screen readers by `a11y/`). Touch screens and trackpad gestures live in the kit, not the hosts: `kit/intern/kit_touch.c` is one state machine (Android's model: taps, long presses, scrolls past the touch slop, a second finger's pan, pinch and turn as Blender's `MOUSEPAN` / `MOUSEZOOM` / `MOUSEROTATE`) with the fling in `kit_fling.c` (`VelocityTracker`, `OverScroller`), and every host (Win32 `WM_POINTER`, X11 XInput 2, Wayland `wl_touch` and pointer gestures, Cocoa's magnify and rotate, Android) only forwards contacts to `BK_touch` and trackpad gestures to `BK_magnify` / `BK_rotate` ([docs/touch.md](docs/touch.md)). The Win32 host is BUI's own; the X11 host follows Blender's GHOST input mapping, and the Cocoa host (checked by CI and tried by hand on three Macs: two Apple Silicon, one Intel) is ported from GHOST's Cocoa backend. `kit/intern/blender/` holds Blender files copied in and edited for the kit (each edit marked `BUI:`): `interface_string_search.cc` (menu search with recent searches), `interface_undo.cc` (text-edit undo), `interface_utils.cc` (float display precision). C API: `kit/include/BUI_kit.h`. | **Builds + tested** | +| `a11y/` | `bui-a11y`, a Rust crate: the kit's accessibility trees as AccessKit trees, served to UI Automation on Windows through the window's `WM_GETOBJECT`. The only code that uses AccessKit; C API in `a11y/include/bui_a11y.h`. Gate: `-DBUI_A11Y=ON` (needs cargo); on for Rust and Node. | **Builds + tested** (Windows) | | `api/` | `bui_c_api.h` — small stable C ABI: version info + sink/viewport plumbing for hosts and bindings. | **Builds + tested** | | `bindings/python/` | `buipy` CPython extension (no third-party deps; Dear ImGui is compiled into it, `blenderui.imgui`, so a process holds one kit) + `bui` package: `bui.components` (Blender component library), `bui.qtsyntax` / `bui.tksyntax` (Qt / tkinter APIs as thin facades over the kit), `bui.host` (native or Tk windows), `SvgSink` headless renderer, `bui.qt.BuiCanvas` PySide6/PyQt6 widget. | **Builds + tested** | | `bindings/imgui/` | Dear ImGui (vendored, 1.93.1 WIP) on BUI: `imgui_impl_bui` platform + renderer backend hosted in a kit `custom` node (input, cursors, clipboard, DPI, damage-driven frames) drawing through `BUI_raster_mesh` and BUI textures; Blender style and Inter font; the C API (`cimgui.h`) and the generator behind the Python and Rust bindings; the Blender-widgets build (`blender/`, `-DBUI_IMGUI_BLENDER_WIDGETS=ON`). Gate: `-DBUI_BUILD_IMGUI` (ON with C++). | **Builds + tested** | -| `bindings/rust/` | `blenderui` (HTML/CSS/Tailwind, `rsx!` and gpui-style builders, hooks, Blender components; layout by taffy) over `blenderui-sys`; `blenderui-macros`, `blenderui-tailwind`, `blenderui-imgui`, and the JavaScript runtimes `blenderui-jsview`, `blenderui-node` (napi-rs) and `blenderui-qjs` (QuickJS). | **Builds + tested** | +| `bindings/rust/` | `blenderui` (HTML/CSS/Tailwind, `rsx!` and gpui-style builders, hooks, Blender components; layout by taffy) over `blenderui-sys`; `blenderui-macros`, `blenderui-tailwind`, `blenderui-paint`, `blenderui-table`, `blenderui-vlist`, `blenderui-imgui`, `blenderui-web` (WebAssembly), and the JavaScript runtimes `blenderui-jsview`, `blenderui-node` (napi-rs) and `blenderui-qjs` (QuickJS). | **Builds + tested** | | `bindings/node/`, `bindings/react/` | `@blender-ui/native` (DOM-like API, signals) and `@blender-ui/react` (React 19.3 renderer) on `blenderui-node`. | **Builds + tested** | | `backends/qt/` | C++ Qt backend: `BUI::QtSink` (BuiGpuSink → QPainter) + `BUI::BuiWidget` (QWidget host, no moc needed). Gate: `-DBUI_BUILD_QT_BACKEND=ON`. | **Shipped** (builds where Qt exists) | | `examples/` | `kit_hello.c` (the kit in a native window), `svg_demo.c` (C, sink → SVG), `python_demo.py` (buipy → SVG), the Python, Qt, tkinter and ImGui demos, and `site/` (the website's screenshot programs). C examples need `-DBUI_BUILD_EXAMPLES=ON`. | **Builds + run** | @@ -104,7 +106,8 @@ The kit itself draws through `GPU_raster.h`: integrates exact coverage. With `BUI_SLUG=0`, it uses glyph bitmaps from the shared glyph cache in the mask atlas instead. - **GPU renderer**: Direct3D 11 on Windows (`gpu/intern/gpu_d3d11.c`, - `gpu/shaders/bui_ui.hlsl`) and OpenGL 3.3 core on Linux + `gpu/shaders/bui_ui.hlsl`; Direct3D 12 opt-in, `gpu_d3d12.c`, both on the + shared core in `gpu_device.c`) and OpenGL 3.3 core on Linux (`gpu/intern/gpu_gl.c`: the same instances, atlases and Slug textures, the uber-shader translated to GLSL, GLX on the X11 window or EGL offscreen, libGL loaded at run time). Opt-in with `BUI_GPU=1`, `BUI_gpu_set_default`, @@ -176,7 +179,8 @@ Options: `BUI_BUILD_PYTHON_BINDINGS` (ON; auto-skips without Python dev files), `BUI_BUILD_QT_BACKEND` (OFF; needs Qt5/Qt6 Widgets), `BUI_BUILD_EXAMPLES`, `BUI_BUILD_TESTS`, `BUI_BUILD_UI` (OFF), `BUI_BUILD_IMGUI`, `BUI_IMGUI_BLENDER_WIDGETS`, `BUI_TEXT_FREETYPE`, -`BUI_TEXT_GDI`, `BUI_SLUG`, `BUI_IMAGE_SVG`, `BUI_WARNINGS_AS_ERRORS`. See +`BUI_TEXT_GDI`, `BUI_SLUG`, the image formats (`BUI_IMAGE_SVG`, `BUI_IMAGE_EXR` ...), +`BUI_SHELL`, `BUI_A11Y`, `BUI_WARNINGS_AS_ERRORS`. See [docs/getting-started.md](docs/getting-started.md#build-options). Windows note: the toolchain must resolve MinGW runtime DLLs from diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a2bfa16b..e8f590ee 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -46,7 +46,7 @@ headers (`libx11-dev` / `libX11-devel`). More detail: - Keep each PR focused on one change, and add a test for it: - C: `ctest`. - Python: `bindings/python/tests/`. For tkinter behavior, add to the side-by-side compat suite. - - Rust: `bindings/rust/blenderui/tests/`. + - Rust: `bindings/rust/blenderui/tests/suite/` (one test binary: add a module to its `main.rs`). - JavaScript: `bindings/node/test/` and `bindings/react/test/`. - Don't let performance regress. The test suite enforces frame budgets. For rendering or layout changes, run the benchmark in `bindings/rust/bench/` diff --git a/INTEGRATION.md b/INTEGRATION.md index 322a14b2..f59a1f8f 100644 --- a/INTEGRATION.md +++ b/INTEGRATION.md @@ -12,7 +12,7 @@ | Path | Who uses it | What it draws into | |---|---|---| -| **The kit's raster path** | Everything in `kit/` and every binding | A `BuiRaster`: the software raster (`gpu/intern/gpu_raster.c`) or, on a GPU window, Direct3D 11 / OpenGL instances. A native window presents it; headless code reads its pixels. | +| **The kit's raster path** | Everything in `kit/` and every binding | A `BuiRaster`: the software raster (`gpu/intern/gpu_raster.c`) or, on a GPU window, Direct3D 11 (or 12) / OpenGL instances. A native window presents it; headless code reads its pixels. | | **Render sinks** (this page) | `api/bui_c_api.h`, the Qt backend, `bui.svg`, `buipy.demo_scene` | Triangles, lines, points and text runs from the immediate-mode GPU seam (`gpu/intern/gpu_null.c`), handed to a `BuiGpuSink` you install | The sink layer never opens a window, creates a GL context or picks a UI @@ -137,8 +137,7 @@ software raster the kit uses) and shows it with a single Two facades speak the syntax of established toolkits on top of the C kit (`kit/`, exposed to Python as `buipy.KitNode` / `buipy.KitContext`): widgets are kit nodes, layouts are the kit's C geometry managers, and windows come -from `bui.host` (native Win32 / X11 / Cocoa windows, the Cocoa one still -experimental, or Tk with `BUI_HOST=tk`). They use the kit's raster path, not +from `bui.host` (native Win32 / X11 / Wayland / Cocoa windows, or Tk with `BUI_HOST=tk`). They use the kit's raster path, not render sinks: ### Qt syntax — `bui.qtsyntax` diff --git a/README.md b/README.md index 49c0e18a..8b427c14 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,8 @@ People spent decades building and optimizing Blender's GUI. It's battery and mem [![crates.io](https://img.shields.io/crates/v/blenderui?label=crates.io%20blenderui)](https://crates.io/crates/blenderui) [![@blender-ui/react](https://img.shields.io/npm/v/@blender-ui/react?label=%40blender-ui%2Freact)](https://www.npmjs.com/package/@blender-ui/react) [![Wheels](https://github.com/ppmpreetham/BUI/actions/workflows/wheels.yml/badge.svg)](https://github.com/ppmpreetham/BUI/actions/workflows/wheels.yml) -[![License: GPL-3.0-or-later](https://img.shields.io/badge/license-GPL--3.0--or--later-blue)](#44-license-and-credits) -![Platforms](https://img.shields.io/badge/platforms-Windows%20%7C%20Linux%20%7C%20macOS-lightgrey) +[![License: GPL-3.0-or-later](https://img.shields.io/badge/license-GPL--3.0--or--later-blue)](#45-license-and-credits) +![Platforms](https://img.shields.io/badge/platforms-Windows%20%7C%20Linux%20%7C%20macOS%20%7C%20Android%20%7C%20WebAssembly-lightgrey) [![Discord](https://img.shields.io/badge/chat-Discord-5865F2?logo=discord&logoColor=white)](https://discord.gg/MWXZfdyM3D) @@ -178,8 +178,8 @@ in any language, can have both: Blender's feel, and Blender's efficiency. [concepts](#part-iii-concepts) are explained in plain words. Before you ship something with BUI, read the -[known limitations](#41-status-and-roadmap): no accessibility support yet, no -input methods, and it looks like Blender, not like your operating system. +[known limitations](#42-status-and-roadmap): screen readers and input methods +work on Windows only, and it looks like Blender, not like your operating system. ## 4. Pick your language @@ -199,6 +199,7 @@ all get the same widgets and interactions: | **C#** (the `Bui` assembly in `bindings/csharp`): `Node`, `Frame`, `Button`, `Context`, `Window` | C# components over every `BK_*` function, generated from `BUI_kit.h` | Partial | | **Go**: the kit's nodes (`bindings/go/bui`), or [MyGo](https://github.com/egoist/mygo)-style views (`ui.Column(c).Children(...)`, `ui.Checkbox(c, &v, "Sync")`) | Blender's widgets from Go, with a headless `Tester` for `go test` | Working | | **Ruby** (the `blenderui` gem in `bindings/ruby`) | A C extension over the kit (no FFI): nodes, windows and menus, interfaces built from blocks, headless tests | Working | +| **Lua** 5.4 (`luarocks install blenderui`, or the `bui-lua` host in `bindings/lua`) | The kit's nodes, widgets and windows as a native Lua module; the same scripts run as Android apps | Working | Not sure which to pick? If you already have code, use the row that matches it. If you're starting fresh in Python, the Blender components are the friendliest. @@ -249,9 +250,9 @@ If you're starting fresh in Python, the Blender components are the friendliest. ### Fast by design - **Damage rendering**: an idle UI costs 0% CPU, and a hover redraws only the widget it touches. -- **Opt-in GPU renderer** (Direct3D 11 on Windows, OpenGL 3.3 on Linux), modeled on Blender's instanced widget drawing. It draws the same pixels as the CPU raster. -- **GPU effects**: your own GLSL pixel shader in a canvas (`BK_ITEM_EFFECT`, Rust `Painter::effect`), run on Direct3D 11 and OpenGL in paint order with an image as the fallback; the compile log comes back as a string. -- **Android** (`platform/android`, [docs/android.md](docs/android.md)): the kit's window host on a `NativeActivity`, so C, Lua and Rust apps run as on a desktop (`Application::run`, `bui.open`); damage-driven rendering, [touch](docs/touch.md) (taps, flings, long presses, pinches) and the soft keyboard; `python platform/android/build.py [--lua DIR | --rust CRATE]` makes a signed APK of 1 to 2 MB. Run on an emulator; the arm64 builds were not run. +- **Opt-in GPU renderer** (Direct3D 11 on Windows, or Direct3D 12 when asked; OpenGL 3.3 on Linux), modeled on Blender's instanced widget drawing. It draws the same pixels as the CPU raster. +- **GPU effects**: your own GLSL pixel shader in a canvas (`BK_ITEM_EFFECT`, Rust `Painter::effect`), run on Direct3D and OpenGL in paint order with an image as the fallback; the compile log comes back as a string. +- **Android** (`platform/android`, [docs/android.md](docs/android.md)): the kit's window host on a `NativeActivity`, so C, Lua and Rust apps run as on a desktop (`Application::run`, `bui.open`); damage-driven rendering, [touch](docs/touch.md) (taps, flings, long presses, pinches) and the soft keyboard; `python platform/android/build.py [--lua DIR | --rust CRATE]` makes a signed APK of 1 to 2 MB. Run on an x86_64 emulator, and on an arm64 phone (the refresh rate, a Rust app on `blenderui::android_main!`). - **GPU render targets**: an effect can draw into a texture (`RenderTarget`, `BUI_target_create`, `Painter::effect_to`, `Rgba8` / `Rgba16F` / `Rgba32F`) and sample it in a later pass, so simulations can feed back on themselves. Tested on Direct3D 11; the OpenGL backend has the same code and has not been run. - In the benchmark, **2–4× less CPU per frame than gpui-fast**, with **less RAM** and a **~5 ms first frame**. - **Blender's text**: Inter (Blender's UI font) is embedded and rendered with FreeType the way Blender renders it, so text looks the same on every platform. On the GPU, glyphs are drawn from their outlines with [Slug](https://github.com/EricLengyel/Slug), falling back to a per-glyph atlas like Blender's. @@ -261,7 +262,7 @@ If you're starting fresh in Python, the Blender components are the friendliest. - **One decoder set for every language**, in C: PNG, GIF, BMP, TGA, QOI ([Wuffs](https://github.com/google/wuffs), memory-safe), JPEG (libjpeg-turbo), WebP including animated (libwebp), Radiance HDR, PNM, SVG, TIFF (libtiff) and HEIC (the OS decoder, loaded at run time), and opt-in OpenEXR (OpenEXRCore), AVIF (libavif + dav1d) and JPEG XL (libjxl), animated AVIF and JPEG XL included. The design is Blender's imbuf: one image type and a format table. - **Decoded at the size it is drawn, off the UI thread**: JPEG thumbnails use DCT scaling (a 4K photo becomes a 256 px thumbnail in ~12 ms), visible images first, scrolled-away requests cancelled, and only the image's rectangle redraws when it arrives. The page never jumps: sizes come from the file header. - **One memory-budgeted cache** (256 MiB by default). Scrolling 1,000 photo thumbnails: **2.9 ms p99 frames and 100 MB**, against 96 ms and 2.5 GB when decoding on the UI thread; **0 allocations** in a settled frame, every block freed at exit. [Images](https://bui.preetham.top/docs/concepts/images/). -- **Animated GIF and WebP play** everywhere an image shows, decoded one frame at a time at the size drawn (two frames held per animation), each frame for its own delay, only the image's rectangle repainting. Off screen, scrolled away or in a hidden window they pause: 200 animations at once take **0.76 ms p50 / 1.5 ms p99** render frames, and **nothing at all** once off screen. `frame` holds one frame; reduced motion holds them all. +- **Animated GIF, WebP, AVIF and JPEG XL play** everywhere an image shows, decoded one frame at a time at the size drawn (two frames held per animation), each frame for its own delay, only the image's rectangle repainting. Off screen, scrolled away or in a hidden window they pause: 200 animations at once take **0.76 ms p50 / 1.5 ms p99** render frames, and **nothing at all** once off screen. `frame` holds one frame; reduced motion holds them all. - **Large images on the GPU**: images over 2047 px get a texture of their own on Direct3D 11 and OpenGL (tiled only past the device limit), freed with the image. - **Video**: `