Debug UI #880

Merged
SakulFlee merged 17 commits from feat/debug-ui into main 2026-10-23 17:02:00 +00:00
Owner
No description provided.
Adds a fourth panel that shows the selected entity's components with a text
field per editable value, and writes the parsed value back into the ECS.

## What is editable, and why not everything

Display is already generic — every `Component` is `Debug` — but editing is not:
turning "1.5" back into a `T` requires knowing `T`. So `EditableValue` is
implemented for the types a game is most likely to want to tweak live: the
numeric scalars, `bool`, `String`, the `cgmath` 2/3/4-vectors, points,
quaternions, angles, and the engine's own `Position` and `Rotation`.

`editable_ops` returns the display and apply functions for a `TypeId` *from
the same match arm*, so a type can never get a text form without a matching
parser. Anything else shows its `Debug` output and is marked read-only.

Two bugs worth calling out, both caught by tests rather than review:

- Integers are parsed through `f64` and then range-checked. Casting directly
  would be simpler but is wrong: a float-to-int `as` cast saturates, so typing
  `-1` into a `u32` field would silently write 0 instead of reporting an error.
- The text form is not the `Debug` form. `Position` prints as
  `Position(Point3 [1.0, 2.0, 3.0])` but edits as "1.0 2.0 3.0", and the field
  is seeded from the latter.

## ECS additions

Editing in place needs a mutable erased handle, which the introspection change
did not have:

- `ComponentStore::get_component_mut`
- `WorldComponentStorage::component_any_mut`
- `World::component_mut_any` / `WriteComponentHandle`, the write-locked
  counterpart of `component_debug`

`set_component_any` from the introspection change takes an owned `Box<dyn Any>`,
which cannot be produced from a store, so it was the wrong tool here.

## orbital_iced addition

`IcedState::with_message_handler`, because `handle_message` only hid the panel
on its close message. It is the one place holding both the world and the panel
state, which is exactly where a component write has to happen. The default is
unchanged, so existing panels are unaffected.

`text_input::on_submit` in this fork takes a fixed message rather than a
closure, so Enter and the `set` button both send `ApplyField(FieldKey)` and the
handler reads the buffered text. One code path, and no way for the two to
disagree.

A failed edit is shown in the panel and leaves the component untouched.
Adds a sparkline to the performance panel and lets a panel rate-limit how
often its widget tree is rebuilt.

## The graph

`plotters-iced` would be the obvious choice, but its latest release (0.11.0,
Sep 2024) requires `iced` 0.13 while this workspace runs a 0.15-dev fork, so
it would need forking as a second submodule. The fork's `canvas` widget is
already there behind a feature flag and pulls in only `lyon`/`lyon_path`,
which are workspace dependencies, so this enables `canvas` and writes a
~90-line `Program` instead. The point-to-bounds mapping is factored out and
tested without a GPU.

Note the 0.15 canvas API is `Frame`-based — draw into a `Frame` and return
`frame.into_geometry()` — rather than returning filled and stroked paths, and
`Path` is immutable and built through a closure.

One graph only: whole-frame time over the retained history. The per-stage
breakdown stays numeric — stacking 11 series would be unreadable at this size,
and the table already answers "which stage".

## The throttle

`IcedState::with_refresh_interval` caps how often the renderer rebuilds a
panel's widget tree. Rebuilding is what re-runs the widget diff and layout and
calls the view closure, and these panels re-read the whole world to do it.

Input is deliberately *not* throttled: events are still routed to the retained
tree every frame, so a click is always hit-tested against a live layout. Only
the redraw of the tree is rate-limited, and `mark_dirty` — which
`handle_message` now does — bypasses the interval entirely, so a click is
reflected on the very next frame.

The default is `Duration::ZERO`, i.e. rebuild every frame, so existing panels
are unaffected. The debug panels set 50 ms.

Rebuilds are also forced when the window resizes, since the retained layout
would otherwise be laid out for the old size.
fix(orbital_iced): invoke a panel's message handler from handle_message
All checks were successful
Lint / lint (pull_request) Successful in 2m37s
ec00e11e3b
`IcedState::with_message_handler` stored a handler, but `handle_message`
never called it, so every panel that installed one silently dropped its
messages. The debug panels do exactly that, which left their controls
inert: tabs, entity selection/filter, log level, clear-log and the
component inspector all published messages that went nowhere.

Call the handler when present. It receives the panel and the world, and the
default close handling is skipped, so a handler owns its panel's behaviour.
For the debug panels that means a `ClosePanel` is routed into the ECS
`DebugUiState` (hiding the overlay) rather than only flipping the renderer's
copy of `visible` — which is also what lets the overlay be shown again with
the toggle key after it was closed.
FloatingPanel laid its children out with `Limits::NONE`, so any
`Length::Fill` body resolved to infinity. The panel node became infinite,
and its background, border, title bar and close button filled degenerate
quads that never drew, leaving only finite text visible.

Lay the title and content out against the real window limits, clamped to
the space left below and to the right of the panel, and add
`max_height_fraction` so a Fill body can stop short of the window edge.
`IcedState::visible` is a renderer-side bool, so state living in the ECS
world could only blank a panel's content, never its chrome. That left
bare title bars on screen while the overlay was off.

Add `with_visibility`, evaluated against the world before the view is
built, and `with_height_fraction` to forward the panel's height cap.
fix(debug_ui): hide panels with the overlay and bound their size
Some checks failed
Lint / lint (pull_request) Failing after 1m59s
17d7e7fe21
Visibility now follows `DebugUiState`, so F1 hides the title bars too
instead of leaving labels floating over the game. Cap list panels at 70%
of the window, size the performance and empty inspector panels to their
content, and move the inspector in from x=900 so it stays on screen.
The renderer drew with `Style::default()`, whose text colour is black, on
the dark panel backgrounds; most labels have no explicit colour, so they
were unreadable. Derive the style from the dark palette instead.

Also mark the panel dirty when a widget captures an event, so a drag or
resize is applied immediately rather than at the next refresh tick.
The canvas widget already translates geometry by its bounds origin, but
the sparkline added `bounds.x`/`bounds.y` to every point, pushing the
graph outside its viewport so the graph never appeared. Keep the points
relative to the canvas and cover a non-zero origin with a test.
Add a bottom-right grip that resizes the panel while dragged, clamped to
the window and to a sensible minimum. The chosen size is kept in widget
state, so it survives rebuilds and falls back to the declared size when
untouched. The grip takes precedence over the content's scrollbar.
Replace the height-fraction knob with `with_size` and `with_resizable`,
forwarded to the floating panel. Windows are resizable by default.
feat(debug_ui): size and place the panels for their content
Some checks failed
Lint / lint (pull_request) Failing after 1m4s
1c5cd9d222
Panels now fill the size they are given instead of deriving it from a
70% cap: the console is wide and short for long log lines, the inspector
and ECS list are shorter, and the performance panel gets a taller graph.
Bodies fill their window so the resize grip works on every panel.
Author
Owner

Closes #744

Closes #744
Author
Owner

Closes #849

Closes #849
Author
Owner

Closes #811

Closes #811
- forward wheel events to iced and keep them out of game input over panels
- collapse an ECS entry when clicking the selected row again
- show model/camera labels in the ECS list, inspector and filter
- pretty-print inspector values and cap Debug formatting cost
- fix the sparkline fill, add rolling avg/min/max and multi-stage graphs
- align the timing table and keep the resize grip clear of the scrollbar
- anchor the log console to the bottom
- remove the separate Inspector window and edit components inline
- add a derive-based EditableFields API for primitive and string fields
- apply it to camera, model-descriptor and light components
- add a ModelInstances editor with Euler rotation and add/remove controls
- mark camera/model/light realization dirty flags after edits
- make the all graph four distinct lines instead of overlapping fills
- close individual panels and restore them when the overlay is shown again
chore(deps): refresh lockfile for the git iced dependency
Some checks failed
Lint / lint (pull_request) Failing after 1m51s
PR / test (pull_request) Successful in 9m19s
Templates / templates (pull_request) Successful in 4m20s
cd6a0ee13f

Smart test results

Result: PASS

Scope: full workspace

Reason: workspace-level change: Cargo.lock

Elapsed: 6m 7s

Workflow run

Overall: 388 tests, 378 passed, 0 failed, 10 skipped

Nextest: 377 tests, 377 passed, 0 failed, 0 skipped
Doctests: 11 tests, 1 passed, 0 failed, 10 skipped

Outcome charts are split between nextest and doctests. The timing chart covers nextest only.

Crate Nextest Passed Failed Skipped Doctests Time
orbital 1 1 0 0 - 0.73s
orbital_2d 29 29 0 0 0/1 0.21s
orbital_app 9 9 0 0 0/1 0.06s
orbital_camera 4 4 0 0 - 0.03s
orbital_core 2 2 0 0 - 0.01s
orbital_debug_render 0 0 0 0 0/1 0.00s
orbital_debug_ui 28 28 0 0 0/1 0.21s
orbital_ecs 114 114 0 0 0/2 0.92s
orbital_ecs_bridge 33 33 0 0 - 0.29s
orbital_file_manager 5 5 0 0 - 0.05s
orbital_iced 15 15 0 0 - 0.13s
orbital_importer_gltf 13 13 0 0 - 0.19s
orbital_input 10 10 0 0 - 0.08s
orbital_light 6 6 0 0 - 0.05s
orbital_macros 0 0 0 0 0/1 0.00s
orbital_math 4 4 0 0 - 0.03s
orbital_procgeo 2 2 0 0 - 0.02s
orbital_resources 18 18 0 0 - 0.20s
orbital_shader_core 0 0 0 0 1/1 0.00s
orbital_shader_preprocessor 12 12 0 0 - 0.09s
orbital_shadow 3 3 0 0 - 0.02s
orbital_text 14 14 0 0 0/1 0.48s
orbital_texture 9 9 0 0 - 0.07s
orbital_touch_ui 1 1 0 0 0/1 0.01s
orbital_ui 32 32 0 0 0/1 0.25s
orbital_world_environment 13 13 0 0 - 0.10s
pie showData
    title Nextest outcomes
    "Passed" : 377
pie showData
    title Doctest outcomes
    "Passed" : 1
    "Skipped" : 10
xychart-beta
    title "Slowest crates (nextest seconds)"
    x-axis ["orbital_ecs", "orbital", "orbital_text", "orbital_ecs_bridge", "orbital_ui", "orbital_2d", "orbital_debug_ui", "orbital_resources"]
    y-axis "Seconds" 0 --> 1
    bar [0.92, 0.73, 0.48, 0.29, 0.25, 0.21, 0.21, 0.20]
<!-- orbital-ci-test-results --> ## Smart test results **Result:** PASS **Scope:** full workspace **Reason:** workspace-level change: Cargo.lock **Elapsed:** 6m 7s [Workflow run](https://forgejo.sakul-flee.de/SakulFlee/Orbital/actions/runs/468) **Overall:** 388 tests, 378 passed, 0 failed, 10 skipped **Nextest:** 377 tests, 377 passed, 0 failed, 0 skipped **Doctests:** 11 tests, 1 passed, 0 failed, 10 skipped _Outcome charts are split between nextest and doctests. The timing chart covers nextest only._ | Crate | Nextest | Passed | Failed | Skipped | Doctests | Time | | --- | ---: | ---: | ---: | ---: | ---: | ---: | | orbital | 1 | 1 | 0 | 0 | - | 0.73s | | orbital_2d | 29 | 29 | 0 | 0 | 0/1 | 0.21s | | orbital_app | 9 | 9 | 0 | 0 | 0/1 | 0.06s | | orbital_camera | 4 | 4 | 0 | 0 | - | 0.03s | | orbital_core | 2 | 2 | 0 | 0 | - | 0.01s | | orbital_debug_render | 0 | 0 | 0 | 0 | 0/1 | 0.00s | | orbital_debug_ui | 28 | 28 | 0 | 0 | 0/1 | 0.21s | | orbital_ecs | 114 | 114 | 0 | 0 | 0/2 | 0.92s | | orbital_ecs_bridge | 33 | 33 | 0 | 0 | - | 0.29s | | orbital_file_manager | 5 | 5 | 0 | 0 | - | 0.05s | | orbital_iced | 15 | 15 | 0 | 0 | - | 0.13s | | orbital_importer_gltf | 13 | 13 | 0 | 0 | - | 0.19s | | orbital_input | 10 | 10 | 0 | 0 | - | 0.08s | | orbital_light | 6 | 6 | 0 | 0 | - | 0.05s | | orbital_macros | 0 | 0 | 0 | 0 | 0/1 | 0.00s | | orbital_math | 4 | 4 | 0 | 0 | - | 0.03s | | orbital_procgeo | 2 | 2 | 0 | 0 | - | 0.02s | | orbital_resources | 18 | 18 | 0 | 0 | - | 0.20s | | orbital_shader_core | 0 | 0 | 0 | 0 | 1/1 | 0.00s | | orbital_shader_preprocessor | 12 | 12 | 0 | 0 | - | 0.09s | | orbital_shadow | 3 | 3 | 0 | 0 | - | 0.02s | | orbital_text | 14 | 14 | 0 | 0 | 0/1 | 0.48s | | orbital_texture | 9 | 9 | 0 | 0 | - | 0.07s | | orbital_touch_ui | 1 | 1 | 0 | 0 | 0/1 | 0.01s | | orbital_ui | 32 | 32 | 0 | 0 | 0/1 | 0.25s | | orbital_world_environment | 13 | 13 | 0 | 0 | - | 0.10s | ```mermaid pie showData title Nextest outcomes "Passed" : 377 ``` ```mermaid pie showData title Doctest outcomes "Passed" : 1 "Skipped" : 10 ``` ```mermaid xychart-beta title "Slowest crates (nextest seconds)" x-axis ["orbital_ecs", "orbital", "orbital_text", "orbital_ecs_bridge", "orbital_ui", "orbital_2d", "orbital_debug_ui", "orbital_resources"] y-axis "Seconds" 0 --> 1 bar [0.92, 0.73, 0.48, 0.29, 0.25, 0.21, 0.21, 0.20] ```
Merge branch 'main' into feat/debug-ui
Some checks failed
PR / test (pull_request) Has been cancelled
Templates / templates (pull_request) Has been cancelled
Lint / lint (pull_request) Has been cancelled
1e691a9f17
Format
All checks were successful
Lint / lint (pull_request) Successful in 2m44s
Templates / templates (pull_request) Successful in 2m47s
PR / test (pull_request) Successful in 6m38s
afd60bb9f9
SakulFlee deleted branch feat/debug-ui 2026-10-23 17:02:00 +00:00
Sign in to join this conversation.
No description provided.