Skip to content

Latest commit

 

History

History
85 lines (67 loc) · 3.21 KB

File metadata and controls

85 lines (67 loc) · 3.21 KB

Rust and Python integration

pbSlintDock keeps one C++ layout engine and exposes it through a stable C ABI. The Rust and Python bindings therefore use exactly the same split tree, hit testing, drag state machine, and JSON layout format as the C++ API.

Rust

The crate is in bindings/rust. Its build script compiles and statically links the engine, so an application does not ship a separate pbSlintDock DLL.

cargo test --manifest-path bindings/rust/Cargo.toml --all-targets
cargo run --manifest-path bindings/rust/Cargo.toml --example demo

The safe DockManager API covers panel registration, all programmatic layout operations, every pointer/splitter/float event, render output, overlays, drag visuals, native cursor position, and save/restore. The public SlintBridge owns synchronization and float-window lifetime through the generated-type-neutral SlintWindowAdapter and optional GhostAdapter traits. See bindings/rust/examples/demo.rs for the complete adapter implementation. It keeps VecModel instances alive and updates rows in place, creates and destroys DemoFloatWindow instances, positions them with Slint's Window API, and renders the drag ghost in a separate window.

The shared UI is imported with:

import { DockHost, DockPanel, FloatWindowFrame, PbDock } from "@pbslintdock";

Map pbslintdock to ui/pbslintdock.slint in slint-build's CompilerConfiguration::with_library_paths.

Python

The Python wheel builds and bundles pbslintdock_c.dll (or the corresponding shared library on Linux/macOS) with scikit-build-core.

cd bindings/python
uv sync
uv run python -m pytest tests -q
uv run python examples/demo.py

Slint Python 1.17 is published as the pre-release version 1.17.1b2 and requires Python 3.12 or newer. The dependency is pinned in pyproject.toml.

Typical setup:

ui = slint.load_file("app.slint", library_paths={
    "pbslintdock": "path/to/ui/pbslintdock.slint"
})
dock = DockManager()
app = ui.MainWindow()
bridge = SlintBridge(dock, ui, app, ui.MyFloatWindow)
app.run()

SlintBridge installs every PbDock callback, automatically refreshes after programmatic engine changes, updates list-model rows in place, manages float component lifetime, and mirrors overlays and drag state. Slint Python does not currently expose top-level window positioning, so the Windows binding uses a unique native title and SetWindowPos for float windows. The engine and main-window docking remain portable; native float positioning on other platforms requires a platform adapter.

API mapping

Operation Rust Python
register add_panel(PanelDef) add_panel(PanelDef(...))
dock dock_panel, dock_panel_root same snake-case names
visibility open_panel, close_panel, is_open same
float float_panel float_panel
persistence save_layout, restore_layout same
render data output(window) output(window)
input tab_pressed, pointer_moved, splitter/float methods same

Panel ids must be UTF-8 strings without an embedded NUL. Returned render data is owned by the language wrapper and remains valid independently of later engine calls.