Skip to content

Ariadne in the browser: windows open inside the canvas and follow it as it resizes - #977

Merged
transfix merged 6 commits into
masterfrom
fix/cyprty-canvas-size
Nov 3, 2026
Merged

transfix merged 6 commits into
masterfrom
fix/cyprty-canvas-size

Conversation

@transfix

@transfix transfix commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

The browser conference page opened its windows as if the canvas were 1024 x 768, and no window moved when the canvas changed size later. On a laptop's browser canvas, 578 to 729 px tall, windows ran off the bottom. In the conference that was the Avatar window, and on #972's branch also the Chat window's message field. Found while testing #972 in headless Chrome.

Why

ARIADNE.md §5.8 says a window opens inside the view: no larger than the work area, and moved in from its pos: until all of it shows. ImGuiBackend does that once, where the window opens. In a browser the view it opened in was the wrong size:

  • arigl's render window starts at 1024 x 768 (run_window, when there is no --width/--height).
  • VTK's wasm interactor fits the canvas to its container (ExpandCanvasToContainer), but only when it handles a window resize event. The first one is the event Initialize() dispatches itself, and it is handled at the next frame's ProcessEvents().
  • So the first frame, where ImGui places the windows, ran at 1024 x 768. I logged the canvas per animation frame in Chrome (1366 x 768 window): 300 x 150, then 1024 x 768 at frame 22, then 1350 x 579 at frame 23.

Native arigl was always right, because its window has its real size from the first frame.

The fix

  • ViewportManager (wasm only). Right after the interactor initializes, it takes the canvas container's size, as VTK's resize handling would (vtkGetParentElementBoundingRectSize, then UpdateSize, which also sets the interactor's height for mouse y). This covers every cvcGL page, not only the conference. A container with no size yet keeps the size the app asked for.
  • The page footer (the conference page, and the cvcGL demo template). It was 9 px tall until the program first printed, then a text line taller. That shrank the stage by 19 px one frame after the windows were placed. It is one line tall from the start now.
  • The overlay's small-screen rule. ImGuiOverlay starts its panels hidden when the view's short side is under 700 logical px, decided on the first frame. That was only safe because the first frame was 768 tall. With the real size, a 1366 x 768 laptop's browser (a 578-px canvas) would start with every panel hidden. It is a phone's rule, so the line is now 500, the phone view arigl on a phone: windows as a list, labels in view #974 uses (phones are 360 to 430 on their short side). The decision is also written to the state mirror, as the show/hide button's is, so ui.panels_open says what shows.
  • When the view changes size later (a browser window resized, a phone turned on its side, fullscreen entered or left):
    • Getting smaller: ImGuiBackend keeps the work area each window was last drawn in. When a window is drawn in a smaller one, and it showed in full in the old one, it moves back in as it opened, no larger than the work area.
    • Growing again: a window moved in, whether when it opened or later, keeps its home, the place and size it had without the move (m_home). Each frame it heads there as far as the view allows, so it goes back out as the view grows, and forgets its home once it arrives. A page opened in a small browser window and then enlarged ends up laid out as the document says.
    • The user's choice wins: a window the user moves or resizes after it was moved in stays where they put it. So does one they left partly outside the view.
    • The flow places its windows itself, as before.
  • Docs. §5.8 now says that in a browser the view is the canvas from the first frame, and what happens when the view gets smaller. §5.14 says 500.

Not changed

  • VTK resizes the canvas only on a window resize event. A page whose layout changes without one (the footer, before this PR) still leaves the canvas at its old size.
  • Merging with arigl on a phone: windows as a list, labels in view #974 (open), which stacks a phone's oversized windows, collapsed, from the top of the view. A trial merge conflicts in ImGuiBackend.h and in three spots in ImGuiBackend.cpp. The fix is to keep both sides, with one rule: a stacked window gets no home, so the seed block's if (!existing) becomes if (!existing && !stack). Without that, a stacked window would head back toward its authored place and undo the stacking. ARIADNE.md merges cleanly.

Testing

In a browser. I built the conference page for wasm from this branch and ran it in headless Chrome over DevTools against a local WebSocket arisrv. A script logged the canvas's backing size on every animation frame.

canvas sizes, from page load the Avatar window
before (#972's build, same placement code), 1366 x 768 300 x 150, 1024 x 768 at frame 22, 1350 x 579 at frame 23 its ledger runs off the bottom, and so does the Chat window's field
this branch, 1366 x 768 300 x 150, then 1350 x 579 moved in under the menu bar; its bottom is at 636 of the canvas's 644
this branch, 1600 x 900 300 x 150, then 1584 x 730 its bottom is at 767 of 776
this branch, a phone (390 x 844 window at 3x; headless Chrome widens it to 490 CSS px) 300 x 150, then 1470 x 2120 the panels start hidden, and the round button shows

Before the footer change, the canvas was 1348 x 597 for one frame and then 1348 x 578, which left the Avatar window 19 px off the bottom.

A resize after load. I loaded the page at 1600 x 900 and then resized the browser window to 1366 x 768 over DevTools (Browser.setWindowBounds, a real resize). In both builds the canvas went from 1584 x 730 to 1350 x 579.

  • Without the shrink rule, the Avatar window stayed where it opened, and its bottom ran off the canvas.
  • With it, the window moved up and shrank to the canvas; its bottom is at 636 of 644.
  • Resized back to 1600 x 900, the window returned to its full height, exactly as when the page opened at that size.
  • A page opened at 1366 x 768 and then enlarged to 1600 x 900 also ended up as if it had opened at 1600 x 900.

Against the production relay. I loaded the page from this branch against the production relay's WebSocket. It joined the live room (44 ms ping), the Avatar window loaded its catalog and energy budget from the relay, and the resize behaved the same. The relay code differs from the live relay's commit (6a014a1) only in logging and performance.

A GPU reset I couldn't tie to the change. While builds were running, Chrome's GPU process was reset (DXGI_ERROR_DEVICE_HUNG) 5 times in 4 phone runs of this branch. In the same period, 2 runs of #972's build were not reset. Two of the 5 resets came with this branch's sizing step skipped (the page held the canvas's container at 0 px until VTK had made its window).

I then alternated fresh-profile phone runs, idle and with a wasm build running:

  • this branch: 4 runs, no resets;
  • the same tree with master's ViewportManager.cpp and ImGuiOverlay.cpp: 5 runs, no resets;
  • the final build: 1 run, no resets.

Native (Windows, MSVC 14.44, shared, RelWithDebInfo):

  • The new cvcgl_imgui_panels_start checks that the panels start open on 1348 x 577, 1582 x 729, 1024 x 768 and a 125% 1920 x 810, and hidden on a phone either way up.

  • The new cvcgl_imgui_view_shrink runs on a bare ImGui context:

    • it lays out at 1600 x 900, shrinks to 1350 x 579, 1350 x 450 and 500 x 450, and grows back to 1600 x 900, where every window must be at its pos: and size again;
    • a page opened at 1350 x 579 must go part of the way back at 1450 x 700, and all the way at 1600 x 900;
    • a window the user drags after it was moved in, and one dragged past the bottom edge, must both stay where they were put.

    It passes 16 of 16 checks. Against master's ImGuiBackend.cpp, the shrink checks fail (5 of the first 11).

  • With both, cvcgl_imgui_* (10 tests), cvcgl_ari_golden, cvcgl_ari_switch and cvcgl_streaming_overlays: 13 of 13 pass. ariadne_runtime_test passes 248; ariadne_loader_test passes 213, with 2 skipped.

In a browser VTK fits the canvas to its container only when it handles a
resize event, and the first one comes from a ResizeObserver after the
first frames have drawn at the window's starting size. cyprty starts at
arigl's 1024x768, so ImGui placed every window against that, and on a
shorter canvas (577-729 px tall in a laptop's browser) windows ran off
the bottom: the "opens inside the view" rule (ARIADNE.md 5.8) had moved
them in for a view that was not there. ViewportManager now takes the
container's size right after the interactor initializes, as VTK's own
resize handling would.

With the real size from frame 1, the overlay's small-screen rule would
start a 1366x768 laptop's browser with its panels hidden (short side
under 700). It is a phone's rule, so the line is now 500 logical px, the
phone view libcvc#974 uses. cvcgl_imgui_panels_start checks both sides.
Checked in headless Chrome at 1366x768: with the canvas sized before
the first frame, the Avatar window was placed in a 597-px stage, and a
frame later the stage was 578. The footer is empty until the program
first prints, then a line taller. It is one line tall from the start
now, in cyprty and the cvcGL demo page, so the canvas keeps the size
the windows were placed in.

When the overlay hides its panels on a phone, it writes that to its
state mirror, as the show/hide button does, so ui.panels_open says
what shows.

cvcgl_imgui_panels_start renders three frames per window: the
overlay's GL backend starts at the first render, so ImGui's first
frame is the second.
The first is the window resize event the wasm interactor's Initialize()
dispatches, handled at the next processUIEvents(), not a ResizeObserver
as the comment (and the first commit's message) said. Checked in Chrome:
with the container held at 0 px past that event, the canvas stayed 0 px
tall after the container got its height, until a window resize event.
A window opened inside the view (5.8), but if the view got smaller
after (a browser window made smaller, a phone turned on its side,
fullscreen left), nothing brought it back: on a shorter canvas the
windows below its new edge stayed there.

Each window now keeps the work area it was last drawn in. When it is
drawn in a smaller one, a window that showed in full there moves back
in as it opened, no larger than the work area. A window the user left
partly outside stays where it is, a view that grows again moves
nothing, and the flow places its windows itself, as before.

cvcgl_imgui_view_shrink checks it on a bare ImGui context: 1600x900,
then 1350x579 (a 1366x768 laptop's browser canvas), 1350x450 and
500x450, then back; and a window dragged past the bottom edge.
Against the old ImGuiBackend.cpp 5 of its 11 checks fail.
@transfix transfix changed the title cyprty: place windows against the canvas's real size cyprty: windows open inside the canvas, and stay inside when it shrinks Nov 2, 2026
A window moved in to fit the view, where it opened or when the view got
smaller, now keeps its home: the place and size it had without the move.
Each frame it heads there as far as the view allows, so a view that
grows again returns it, and a page opened in a small browser window and
then made larger puts the windows where the document says. It is home
again when it gets there. If the user has moved or resized it since it
was last put somewhere, where they put it is its place from then on.

cvcgl_imgui_view_shrink: back at 1600x900 every window is where its
pos: says at its size; a page opened at 1350x579 goes back part way at
1450x700 and all the way at 1600x900; a window the user drags after it
was moved in stays there. 16 checks.
@transfix transfix changed the title cyprty: windows open inside the canvas, and stay inside when it shrinks cyprty: windows open inside the canvas and follow it as it resizes Nov 2, 2026
#974 (windows as a list of titles on a phone) and this branch both
changed where ImGuiBackend::begin_window opens a window. Both stay:
a window that does not fit a phone's view opens collapsed in the list,
and one moved in anywhere else keeps its home. A window in the list
gets no home: one would pull it back out of the list, on the phone and
again when the view grows. reset_layout clears the list count, the last
views and the homes.

cvcgl_imgui_view_shrink gains the case (it fails without the rule), and
section 5.8 says a window in a phone's list stays there.
@transfix transfix changed the title cyprty: windows open inside the canvas and follow it as it resizes Ariadne in the browser: windows open inside the canvas and follow it as it resizes Nov 3, 2026
@transfix
transfix merged commit 3df4ec4 into master Nov 3, 2026
28 checks passed
@transfix
transfix deleted the fix/cyprty-canvas-size branch November 3, 2026 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant