Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ 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). 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 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** |
| `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** |
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to **blenderui** (BUI). The format follows
## [Unreleased]

### Added
- **Touch screens and trackpad gestures, one model on every platform.** The kit turns a host's contacts into what its widgets know (`BK_touch(ctx, id, BK_TOUCH_DOWN/MOVE/UP/CANCEL, x, y, time_ms, mods)`, `kit/intern/kit_touch.c`), with Android's numbers: a finger on a widget that drags (sliders, fields, scrollbars, the node editor) is the pointer at once; anywhere else a tap is a click, half a second held still is the context menu (a right press), and a move past the 8 dp touch slop scrolls exactly as far as the finger went (from just past the slop) and flings on along `OverScroller`'s curve. A second finger cancels what the first did (as `BK_cancel`) and the two pan (Blender's `MOUSEPAN`), magnify (`MOUSEZOOM`) and rotate (`MOUSEROTATE`) about their centre. Trackpad pinches and turns come in through `BK_magnify` / `BK_rotate` (GHOST's `GHOST_kTrackpadEventMagnify` / `Rotate`); custom nodes get them as `BK_CUSTOM_MAGNIFY` / `ROTATE` and "events" nodes as `BK_EV_GESTURE`, and events made from a finger carry `BK_FROM_TOUCH`. `BK_custom_set_touch(node, BK_TOUCH_MODE_SCROLL / POINTER / RAW)` says what a finger does on a custom node (RAW: every contact as `BK_CUSTOM_TOUCH`; the Dear ImGui adapter uses POINTER). In the node editor two fingers pan the view and a pinch zooms about them. Hosts only forward: Windows through `WM_POINTER` (touch only; no promoted mouse clicks or press-and-hold right click; `WM_POINTERCAPTURECHANGED` cancels), X11 through XInput 2.2 touch (libXi loaded at run time) and XInput 2.4 pinches, Wayland through `wl_touch` and `zwp_pointer_gestures_v1`, macOS through `magnifyWithEvent:` / `rotateWithEvent:`, and Android hands every pointer over (its own touch code is gone). Rust: `on_pan(|e: &PanEvent, ..|)` (before the scroll; `cx.stop_propagation()` takes the drag), `on_pinch(|e: &PinchEvent, ..|)`, `on_rotate(|e: &RotateEvent, ..|)` (rsx `onPan` / `onPinch` / `onRotate`) and, headless, `App::simulate_touch`, `simulate_magnify`, `simulate_rotate`. Details that a plain mapping gets wrong: a two-finger update waits until both fingers moved, so a pan does not wobble the zoom or angle; a finger that lands on a fling stops it without clicking; a finger's double tap may land one widget unit away (the mouse's 4 px is too tight); a finger's drag never warps the system pointer; no hover stays behind a lifted finger; `BK_cancel` now cancels an unmoved press too (a box select a second finger interrupted deselects nothing) and every contact, and a window that loses the focus cancels them; a cancelled link drag in the node editor puts back the link it took off an input (`node_link_cancel`), and `Delete` / `X` do nothing mid link or value drag. Rust's `ScrollWheelEvent::position` now comes from the event (a finger's scroll moves no pointer), and a diagonal finger scroll no longer loses an axis. Docs: [docs/touch.md](docs/touch.md). **C API changes:** the `BK_window_wm(win, "touch_drag", 1, 0)` key is removed; call `BK_custom_set_touch(node, BK_TOUCH_MODE_POINTER)` on the custom node instead. A raw `BK_EV_WHEEL` event's text is now `"mods button phase x y"` (where the scroll is, relative to the node).
- **Android scrolling the way Android does it, a rubber band past the ends, and an opt-in smooth wheel.** The touch fling is a port of Android's: `VelocityTracker`'s least squares fit of the last 100 ms of touches (batched touches included) and `OverScroller`'s spline fling with its friction (`kit/intern/kit_fling.c`), not an exponential decay on a two-point velocity; a drag starts from just past the touch slop, so the content no longer jumps by it. New: `BK_scroll_phase` (`BK_SCROLL_WHEEL`/`DRAG`/`FLING`/`END`) tells a view how a scroll came, and Rust's `ScrollWheelEvent::phase` carries it. `Options::overscroll` (off by default, as in Blender) makes a list stretch past either end with UIScrollView's curve while the finger drags (a fling's momentum stretches it less) and spring back when it lifts; the Android demo turns it on. `Options::smooth_wheel` (off by default) eases a wheel notch in over a few frames, as macOS does, instead of scrolling at once. A scroll now moves a list exactly as far as asked in both directions: it used to be turned into a position through estimated heights, so going up through items not yet measured moved the content by whatever the estimates were off by (10 % too far in a test from the middle of 200 000 messages, while down was exact); the list now walks the distance item by item from the anchor at the next layout, measuring what it passes (`view/relative.rs`). The Android Rust demo's chat is a million messages. Checked on a 90 Hz phone: dragging past the top stretches the first message about 400 px and it settles back at rest.
- **Android runs at the display's fastest refresh rate.** Some phones (ColorOS) held the app to 60 Hz on a 90 Hz panel. `kit_window_android.c` now names the fastest mode (at the current size, whatever the panel offers) on the window with `preferredDisplayModeId` / `preferredRefreshRate`, in JNI from the activity's `onWindowFocusChanged` callback (it runs on the UI thread, so no Java class is needed), and also votes with `ANativeWindow_setFrameRate`. An animating pass that drew nothing no longer spins the loop (it waits `IDLE_FRAME_MS`). `-DBUI_ANDROID_FRAME_LOG` logs frames and CPU time per second to logcat (tag `BUI`). Checked on a 90 Hz phone: 60 Hz before, 90 Hz after.
- **Inline layout, as browsers do it.** A block's inline content is laid out in lines by an algorithm of its own (`tree/inline.rs`, `layout/inline.rs`, `linebreak.rs`), not as a wrapping flex row of words. The builder collects the content into one string (white space collapsing across elements; a segment break removed between ideographs or next to U+200B; only space, tab, newline, CR and FF collapsible), finds its line-break opportunities once with UAX #14 (`unicode-linebreak`), tailored by `word-break: break-all | keep-all`, `line-break: anywhere | loose | normal | strict` (small kana, iteration marks), `hyphens` and `overflow-wrap` (a last resort), and the `white-space` of the nearest common ancestor at an element boundary; an atomic inline breaks as an ideograph. Lines fill greedily; spaces at a line's end hang (`pre-wrap`) or go (collapsible), `break-spaces` breaks after each one, `pre` keeps them; a line box is its strut and its items on the baseline, or at its top, middle or bottom (`vertical-align`); `text-align: start | end` (by `direction`), `justify` (the free space shared over the spaces), `justify-all`, `match-parent` and `text-align-last`; preserved tabs advance to the next tab stop (`tab-size`) from the line's start; a soft hyphen breaks and shows a hyphen there; `text-wrap: balance` evens a paragraph of up to 6 lines; `text-autospace` puts 1/8 em between ideographs and Latin letters or digits; `text-transform: full-width | full-size-kana`. Inline boxes with margin, border and padding take room at their edges and paint each line's fragment (background, borders). The `ch` unit is the font's "0"; the root's background paints under negative z-index layers (it is the canvas's). Han characters in a Japanese or Korean paragraph keep its faces word by word (`BUI_FONT_HAN_JA` / `BUI_FONT_HAN_KO` text flags). Web-platform-tests: **4,860 of 7,135 that run pass (68.1%)** (from 1,978 of 6,172), now with the scripted tests running (below).
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ if(BUI_BUILD_TESTS)
if(BUI_BENCH_NO_IME)
target_compile_definitions(bui_ime_bench PRIVATE BENCH_NO_IME)
endif()
# touch screens: taps, scrolls and flings, a second finger's gesture, raw contacts, cancels
add_executable(bui_touch_test tests/touch_test.c)
target_link_libraries(bui_touch_test PRIVATE bui::kit)
add_test(NAME bui_touch_test COMMAND bui_touch_test)
add_executable(bui_theme_test tests/theme_test.c)
target_link_libraries(bui_theme_test PRIVATE bui::kit)
add_test(NAME bui_theme_test COMMAND bui_theme_test)
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ If you're starting fresh in Python, the Blender components are the friendliest.
- Blender's float display precision, multi-field vertical drags, and panels that collapse with Blender's animation.
- The HSV color wheel, color ramps, curves, trees, lists, text areas, canvases, a node editor and Blender's File Browser.
- **Blender's screen layout**: areas you resize by dragging the edges between them (Shift moves aligned edges, Ctrl snaps), split, join and dock by dragging a corner, swap with Ctrl, maximize with Ctrl+Space; headers, toolbars and sidebars that resize, hide and flip; panels that reorder and pin; the arrangement saved and restored as JSON ([Screens, areas and regions](https://bui.preetham.top/docs/concepts/screens/)).
- **Touch screens and trackpad gestures**, one model on every platform: a tap clicks, a drag scrolls exactly with the finger and flings on (Android's `OverScroller`), a long press opens the context menu, and two fingers pan, pinch and turn (Blender's `MOUSEPAN` / `MOUSEZOOM` / `MOUSEROTATE`); trackpad pinches and turns reach the same places. Windows (`WM_POINTER`), X11 (XInput 2), Wayland, macOS trackpads and Android forward to the kit; Rust has `on_pan`, `on_pinch` and `on_rotate` ([docs/touch.md](docs/touch.md)).
- **Blender's Dark and Light themes**, switchable at run time, and **your own themes** from a JSON file (gpui-kit's format, Blender's color names, per-widget corners and borders; [docs/theming.md](docs/theming.md)).

### Python
Expand Down Expand Up @@ -250,7 +251,7 @@ If you're starting fresh in Python, the Blender components are the friendliest.
- **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 scrolling 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.
- **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.
- **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.
Expand Down
Loading
Loading