Skip to content
Closed
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; 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; 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; touch screens and trackpad gestures (`kit_touch.c`: one finger is the pointer, two are GHOST's trackpad pan / magnify / rotate); 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** |
| `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
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,38 @@ All notable changes to **blenderui** (BUI). The format follows
- **`@blender-ui/native`:** `el.style.display = 'none'` and the other CSS properties as camelCase properties of `el.style`, as in a browser (they were silently ignored); `host.styleRegistry()`, the registry of components' scoped `<style>` blocks that the Svelte and Vue bindings share.
- **D bindings** (`bindings/d`): a DUB package with raw `extern(C)` declarations for the whole kit, GPU and stable C API, plus idiomatic wrappers for nodes, contexts, windows, menus, rasters, images, video, canvases, trees, text areas, custom nodes and themes. The kit is built through CMake from `preBuildCommands`, ownership follows the Python binding's reference-hook model, and `dub run --config=test` covers the wrappers, raw API, events, menus and host errors end to end. Examples: `hello.d` and `headless.d`.
- **D HTML, CSS and RSX** (`bindings/d`): `bui.html` adds an `Element` tree and tag constructors, `bui.css` a selector cascade with a practical CSS subset, and `bui.rsx` a compile-time `rsx!` mixin that lowers markup and `{expression}` values to `Element` calls. `Document` realises the styled tree as kit nodes with flex, grid and table layout, widgets, dynamic `:hover`/`:active` states through `Element.setState` and `Document.restyle`, and in-place text updates through `Element.setText`. Tag constructors use `body_`, `template_`, `object_` and `select_` where D or the existing API already uses the name; markup keeps the HTML spelling. `dub run --config=rsx` opens the new example, and `--config=test` covers the cascade, realiser and RSX. The D wrappers also follow the kit's current header: focus callbacks, `Context.hitAt`, custom theme files, text shadows, font size and transparent rasters.
- **Touch screens and trackpad gestures.** One finger is the pointer: it taps, drags number fields and sliders, opens
menus and picks rows, and leaves no hover behind. A second finger cancels what the first was doing (as Escape
cancels a drag: values go back, nothing is clicked) and the two become a gesture until both lift. Moving them
together scrolls the view under them, spreading them zooms (`BK_magnify`), turning them rotates (`BK_rotate`). These
are GHOST's trackpad Scroll / Magnify / Rotate events (Blender's MOUSEPAN / MOUSEZOOM / MOUSEROTATE); the node editor
pans and zooms on them. New C API: `BK_touch(ctx, id, phase, x, y, mods)` with `BK_TOUCH_DOWN` / `MOVE` / `UP` /
`CANCEL`, `BK_magnify`, `BK_rotate`, the `BK_FROM_TOUCH` modifier bit, and for custom nodes `BK_CUSTOM_TOUCH`,
`BK_CUSTOM_MAGNIFY`, `BK_CUSTOM_ROTATE` with `BKCustomEvent.touch_id`, `touch_phase`, `magnify`, `rotate`, and
`BK_custom_set_touch(node, 1)` to receive every contact raw. Window hosts: `WM_TOUCH` on Windows (touch-made mouse
messages and press-and-hold are dropped), XInput 2.2 touch on X11 (libXi loaded at run time; older servers keep
emulated mouse input), `wl_touch` and the pointer-gestures pinch on Wayland, `magnifyWithEvent:` /
`rotateWithEvent:` on macOS. Dear ImGui reports touch as `ImGuiMouseSource_TouchScreen`. Python
`KitContext.touch` / `magnify` / `rotate`, Lua `ctx:touch` / `magnify` / `rotate` with `bui.TOUCH_*`, D
`Context.touch` / `magnify` / `rotate` and `setTouch`, and `blenderui-sys` declarations. `tests/touch_test.c`; [docs/touch.md](docs/touch.md) and the website's Touch and
gestures page.
- **Gestures for your own content.** A node with the new `"gestures"` property takes touch and trackpad gestures as
`BK_EV_GESTURE` (ref `"mods kind x y"`, `BK_GESTURE_PAN` / `MAGNIFY` / `ROTATE`, a / b the amounts) instead of the
kit scrolling for it; nodes with only `"events"` are unchanged. The two fingers' moves are paired into one update,
so a pan no longer wobbles the zoom. **Rust:** `on_gesture(|e: &GestureEvent, ..|)` on every element
(`GestureEvent { kind: GestureKind, position, dx, dy, magnify, degrees, modifiers, touch }`, `onGesture` in `rsx!`);
a pan no listener stops scrolls the page and reaches `on_scroll_wheel` with the new `ScrollWheelEvent::touch`
(`delta * WHEEL_LINE_PX` = the fingers' pixels), and the virtual list and data table follow the fingers exactly.
`App::simulate_touch` (`TouchPhase`), `simulate_magnify`, `simulate_rotate`. `BK_EV_GESTURE` and the kinds in
`blenderui-sys`, D and Lua; Python and D read its text.
- **Qt syntax:** containers drawn the Blender way (`QStackedWidget`, `QToolBox` as Blender panels, `QSplitter` with region edges to drag, `QToolBar`, `QDockWidget`, `QTabBar`, and `QMainWindow.addToolBar` / `addDockWidget` / `setStatusBar`); model/view (`QStandardItemModel`, `QStringListModel`, the abstract models, `QListView`, `QTreeView`, `QTableView` in Blender's tree list); real `QMessageBox` and `QInputDialog` dialogs; `QSettings` (an INI file with Qt's groups and arrays), `QKeySequence`, `QShortcut` and `QClipboard`; `blockSignals`, dynamic properties, `findChildren`, point mapping, `showEvent` / `hideEvent` and the descriptive properties on every widget. Actions shared by menus, tool buttons and shortcuts (`QAction` with visibility, data, tips and shortcuts bound on its window, `QActionGroup`, a real `QToolButton`, menu sections and corner widgets, `triggered` up to the menu bar), `QButtonGroup` ids, Qt's full layout API (`QBoxLayout` directions, `insert*`, `takeAt`, `replaceWidget`, `QSpacerItem`, grid cell queries and minimum sizes, `QFormLayout` rows), `QDialogButtonBox` (which `QMessageBox` and `QInputDialog` now use), `QAbstractSpinBox`, validators and `maxLength` on `QLineEdit`, spin box prefix / wrapping / special value text, slider tracking and page steps, combo box icons, models and popups, checkable `QGroupBox`, `QFrame` boxes and lines, a `QStatusBar` with permanent widgets, window states, opacity and size limits through the host, `startTimer`, `QFontMetrics`, `QPalette` from Blender's theme, `QCursor.pos`, `QScreen`, and the context-menu policies. Dates and times: `QDate`, `QTime`, `QDateTime` with Qt's format strings, `QDateTimeEdit` / `QDateEdit` / `QTimeEdit` as Blender's aligned number fields, and `QCalendarWidget`. Measured by the new `tools/qt_coverage.py` against Qt's headers: 57% of the core widget classes' methods (was 21% by the same count), 37% across all 142 classes.
- **Kit:** a `select` node flag draws a button held in (Blender's `UI_SELECT`, for checked push buttons), and a separator with `vertical` draws its line across a row (`uiButSeparatorLine.is_vertical`).
- **Touch pans keep to their axis.** The sideways part of a pan no longer scrolls the kit's vertical scrollers (lists,
trees, grids, text areas, scroll views, the region): they read Shift + wheel as vertical, so those steps now reach
only bindings. A Shift held on the keyboard no longer turns a vertical pan sideways. In `blenderui`, a vertical
pan no longer scrolls a horizontal-only container, and the virtual list ignores the sideways part. A cancelled
gesture finger drops the move it held instead of sending it. Gestures over empty space reach the containers
under them (a `"gestures"` root with no widget under the fingers), as the wheel does.

### Fixed
- **Python components:** `NodeEditor` follows `add`, `insert`, `remove`, `replace` and `clear` (its `nodes` and `links` went stale when
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ if(BUI_BUILD_TESTS)
if(BUI_BENCH_NO_IME)
target_compile_definitions(bui_ime_bench PRIVATE BENCH_NO_IME)
endif()
# touch screens and trackpad gestures: the pointer, a second finger's gesture, raw contacts
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ If you're starting fresh in Python, the Blender components are the friendliest.
- Ctrl+Wheel steps values, Ctrl+C / Ctrl+V copy values, Backspace resets.
- **Drag across checkboxes** to set them all.
- Press-drag-release menus, pie menus that pick on key release as in Blender (sub-pies, a "More" level, numpad directions, underlined letters), and **Blender's fuzzy menu search**: "ad cu" finds "Add Cube", typos are forgiven, recent picks rank first.
- **Touch screens and trackpad gestures**: one finger taps and drags like the mouse, two fingers scroll, pinch-zoom and turn (Windows, X11, Wayland; trackpad pinch on Wayland and macOS). See [docs/touch.md](docs/touch.md).
- **Ctrl+Z / Ctrl+Shift+Z** on every UI edit, and inside a text field while you type; Tab between fields.
- 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.
Expand Down
28 changes: 28 additions & 0 deletions bindings/d/source/bui/context.d
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,34 @@ final class Context {
return changed;
}

/// A touch screen contact (`BK_TOUCH_DOWN` / `MOVE` / `UP` / `CANCEL`): one finger is the
/// pointer, two pan, magnify and rotate.
bool touch(int id, int phase, float x, float y, int mods = 0) {
auto c = ctx();
check();
const changed = BK_touch(c, id, phase, x, y, mods) != 0;
check();
return changed;
}

/// Trackpad pinch: `delta` is the scale change (0.1 = 10% larger), about `x`, `y`.
bool magnify(int x, int y, float delta, int mods = 0) {
auto c = ctx();
check();
const changed = BK_magnify(c, x, y, delta, mods) != 0;
check();
return changed;
}

/// Trackpad turn in degrees, positive counter-clockwise, about `x`, `y`.
bool rotate(int x, int y, float degrees, int mods = 0) {
auto c = ctx();
check();
const changed = BK_rotate(c, x, y, degrees, mods) != 0;
check();
return changed;
}

/// Key press with the character `text` and the key name `keysym`.
bool key(string text, string keysym = null, int mods = 0) {
auto c = ctx();
Expand Down
17 changes: 17 additions & 0 deletions bindings/d/source/bui/custom.d
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ struct CustomEvent {
const(char)[] text;
/// The key name, for `BK_CUSTOM_KEY` / `BK_CUSTOM_KEYUP`.
const(char)[] keysym;
/// `BK_CUSTOM_TOUCH`: the contact's id and `BK_TOUCH_*` phase.
int touchId;
int touchPhase;
/// `BK_CUSTOM_MAGNIFY`: scale change (0.1 = 10% larger).
float magnify;
/// `BK_CUSTOM_ROTATE`: degrees, positive counter-clockwise.
float rotate;
}

/// The custom node's implementations.
Expand Down Expand Up @@ -107,6 +114,10 @@ final class Custom {
event.wheelY = raw.wheel_y;
event.text = cslice(raw.text);
event.keysym = cslice(raw.keysym);
event.touchId = raw.touch_id;
event.touchPhase = raw.touch_phase;
event.magnify = raw.magnify;
event.rotate = raw.rotate;
try {
return self.handlers.onEvent(wrapper, event);
}
Expand Down Expand Up @@ -217,6 +228,12 @@ void setCursor(Node node, int cursor) {
BK_custom_set_cursor(need(node, "setCursor"), cursor);
}

/// `true`: every touch contact that begins over the node arrives as `BK_CUSTOM_TOUCH`, with no
/// pointer emulation or gestures; `false` (the default): as the pointer and gestures.
void setTouch(Node node, bool raw) {
BK_custom_set_touch(need(node, "setTouch"), raw ? 1 : 0);
}

/// Non-zero while the custom node has keyboard focus.
bool hasFocus(Node node) {
return BK_custom_has_focus(need(node, "hasFocus")) != 0;
Expand Down
23 changes: 23 additions & 0 deletions bindings/d/source/bui/kit.d
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ enum BK_ALT = 4;
enum BK_BUTTON1 = 8;
enum BK_BUTTON2 = 16;
enum BK_BUTTON3 = 32;
enum BK_FROM_TOUCH = 64;

/* ---- touch phases (BK_touch) --------------------------------------------- */
enum BK_TOUCH_DOWN = 0;
enum BK_TOUCH_MOVE = 1;
enum BK_TOUCH_UP = 2;
enum BK_TOUCH_CANCEL = 3;

/* ---- cursors ------------------------------------------------------------- */
enum BK_CURSOR_DEFAULT = 0;
Expand Down Expand Up @@ -71,6 +78,11 @@ enum BK_EV_VIEW = 17;
enum BK_EV_SCROLL = 18;
enum BK_EV_CONFIGURE = 19;
enum BK_EV_KEYRELEASE = 20;
/// "gestures" nodes: text = "mods kind x y", a, b = amounts (see BK_GESTURE_*).
enum BK_EV_GESTURE = 21;
enum BK_GESTURE_PAN = 1;
enum BK_GESTURE_MAGNIFY = 2;
enum BK_GESTURE_ROTATE = 3;

/* ---- geometry ------------------------------------------------------------ */
enum BK_GEOM_NONE = 0;
Expand Down Expand Up @@ -130,6 +142,9 @@ enum BK_CUSTOM_KEY = 6;
enum BK_CUSTOM_KEYUP = 7;
enum BK_CUSTOM_FOCUS = 8;
enum BK_CUSTOM_BLUR = 9;
enum BK_CUSTOM_TOUCH = 10;
enum BK_CUSTOM_MAGNIFY = 11;
enum BK_CUSTOM_ROTATE = 12;

/* ---- IME ----------------------------------------------------------------- */
enum BK_IME_COMPOSITION_START = 0;
Expand Down Expand Up @@ -266,6 +281,10 @@ struct BKCustomEvent {
float wheel_y;
const(char)* text;
const(char)* keysym;
int touch_id;
int touch_phase;
float magnify;
float rotate;
}

alias BKCustomEventFn =
Expand Down Expand Up @@ -535,6 +554,7 @@ int BK_custom_set(BKNode* node, const(BKCustomClass)* cls, void* data);
void* BK_custom_data(BKNode* node);
void BK_custom_request_frame(BKNode* node, int ms);
void BK_custom_set_cursor(BKNode* node, int cursor);
void BK_custom_set_touch(BKNode* node, int raw);
int BK_custom_has_focus(BKNode* node);
BKContext* BK_node_context(const(BKNode)* node);

Expand Down Expand Up @@ -579,6 +599,9 @@ int BK_wheel(BKContext* ctx, int x, int y, int delta, int mods);
int BK_scroll(BKContext* ctx, int x, int y, float dx, float dy, int mods);
int BK_key(BKContext* ctx, const(char)* text, const(char)* keysym, int mods);
int BK_context_menu(BKContext* ctx, int x, int y, int mods);
int BK_touch(BKContext* ctx, int id, int phase, float x, float y, int mods);
int BK_magnify(BKContext* ctx, int x, int y, float delta, int mods);
int BK_rotate(BKContext* ctx, int x, int y, float degrees, int mods);

/* -- input methods --------------------------------------------------------- */
int BK_ime_event(BKContext* ctx, int type, const(BKImeEvent)* e);
Expand Down
4 changes: 2 additions & 2 deletions bindings/d/source/bui/node.d
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct NodeEvent {
void* ref_;
double a;
double b;
/// The key text for `BK_EV_KEY` / `BK_EV_KEYRELEASE`, else empty.
/// The key text for `BK_EV_KEY` / `BK_EV_KEYRELEASE`, "mods kind x y" for `BK_EV_GESTURE`, else empty.
const(char)[] text;
}

Expand Down Expand Up @@ -366,7 +366,7 @@ final class Node {
return;
}
const(char)[] text;
if (kind == BK_EV_KEY || kind == BK_EV_KEYRELEASE) {
if (kind == BK_EV_KEY || kind == BK_EV_KEYRELEASE || kind == BK_EV_GESTURE) {
text = cslice(cast(const(char)*) ref_);
}
auto event = NodeEvent(this, kind, ref_, a, b, text);
Expand Down
Loading