Skip to content

arigl on a phone: UI size, windows in view, the system keyboard - #967

Merged
transfix merged 5 commits into
masterfrom
feat/arigl-phone-ui
Nov 2, 2026
Merged

transfix merged 5 commits into
masterfrom
feat/arigl-phone-ui

Conversation

@transfix

@transfix transfix commented Nov 1, 2026 •

Copy link
Copy Markdown
Owner

Makes Ariadne/arigl apps usable on a phone, cyprty first. There were two problems: the UI came out tiny and hard to hit, and nothing could be typed, because a phone has no keyboard to send keys.

Why the UI was tiny

VTK sizes the browser canvas in device pixels: the CSS size times devicePixelRatio, about 3 on a phone. ImGuiOverlay's touch default of 2.0 therefore drew 16 × 2 = 32 device-px text, which is about 11 CSS px. The phone check had the same problem: it hid the panels when the short side was under 700 px, but a phone's canvas is about 1170 device px across, so the panels stayed open over the scene.

UI size and pixel ratio (cvc::gl::ImGuiOverlay)

  • The scale now has two factors. The UI size (ui.scale) is in logical (CSS) pixels. The overlay multiplies it by the display's pixel ratio:
    • style.FontScaleMain holds the UI size and FontScaleDpi the ratio, and the style is scaled by their product.
    • The ratio is read from devicePixelRatio every frame, so browser zoom also zooms the UI. Natively it is 1.
    • setPixelRatio() overrides it.
  • New defaults. 1.25 on a touch device (20 px text, a hit area about 38 px tall) and 1.0 with a mouse.
    • The "small screen, start with the panels hidden" test now uses logical pixels.
    • The touch slop, the drag threshold and title-bar-only window moves follow touch mode, no longer scale > 1. Before, a 2× desktop browser picked them up too.
  • The touch default now survives start-up (found while taking the screenshots: the phone came up at 100%).
    • UiSettings (cvc/gl/Settings.h) seeds its defaults (size 1, no touch) in its constructor. It runs synchronously, so it handed them straight back to the overlay, and the overlay's touch mode and size were gone before the first frame.
    • master constructs things in the same order, so its touch scale of 2.0 can't have applied either.
    • UiSettings now fences its own writes, as ViewportLayout already does. Its set() no longer calls back either, which is what its comment always said.
  • A size change lands at the next frame. The style no longer changes under a frame's widgets. The open windows are carried along (ScaleWindowsInViewport), and tables take their column widths again.
  • The floating show/hide button stays above every window (except a popup), so a window dragged over its corner can't bury the way back to the scene.

A document's px follow the UI (Ariadne ImGuiBackend)

  • Authored px are logical px at the UI size: a window's pos:/size:/min:/max:, column and row tracks, image and stream-view sizes, plot heights, and the area a group's background: takes (Ariadne: background: on a window or group (media M2, stacked on #931) #932's, merged in). A 360 px window holds the same widgets at any size.
  • What the core persists (tree.<id>.geometry, tracks, columns) is in the same logical px, so it survives a UI-size change. This is the same model the terminal backends use with their cell size.
  • A window opens inside the view: no larger than the work area, and moved in from a pos: past the edge until all of it shows. So a layout made for a laptop opens within reach on a phone.
    • A window that fits its content can't be measured on its first frame, so it is moved in until its smallest fit shows, then again once measured, the way the flow layout already places windows.
    • At UI size 1 and ratio 1 nothing moves (tested).

The "UI size" setting

  • In the state tree it is <scene>.viewers.<viewer>.ui.scale, already mirrored by UiSettings. arigl's is ui.docs.ari.viewers.main.ui.scale.
  • In the Controls window, a new AppRuntime::set_host_ui_size(UiSizeControl) (keys.h) adds a Display section above the keys with a UI size list (75% to 200%).
    • It is a list, not a slider, because each size re-bakes the font.
    • arigl hands it the overlay's path. It holds for the run.
  • The window is titled Controls and Settings > Controls... opens it, the same rename arigl: third-person mouse look, and a Controls window for keys and mouse #963 makes. Those lines and the test expectations are identical to arigl: third-person mouse look, and a Controls window for keys and mouse #963's, so either order merges cleanly except for the few neighbouring lines.

Minimizing on a phone

  • Panels start hidden on a phone, behind the corner button, which is now finger-sized (42 CSS px).
  • Windows collapse with the title arrow or a double tap, close with X, and come back from View/Windows.
  • On touch a window moves by its title bar only, so a finger slipping off a slider no longer drags the window.
  • cyprty.html hides its keyboard hints and log footer under 600 px wide.
  • docs/ARIADNE.md has a new §5.14, "On a phone" (after the media stack's §5.11-§5.13).

The keyboard: can we raise the system keyboard?

Yes. In a browser a phone shows its keyboard only for a focused text field, and the canvas isn't one. So when a finger activates an ImGui text field (io.WantTextInput, via Platform_SetImeDataFn), ImGuiOverlay focuses a hidden <input> that it adds next to the canvas, positioned at the field's caret. The keyboard comes up, and the browser keeps the field in view above it.

What gets typed. The overlay feeds ImGui what the keyboard does to that hidden field, not key events:

  • Phone keyboards send keyCode 229, compose words, and autocorrect.
  • Each change is diffed: Backspaces for what went, characters for what came.
  • Enter, Tab, Escape, the arrows, Home, End and Delete come from keydown.
  • When the field deactivates, the input blurs and the keyboard goes away.

iOS. iOS only raises a keyboard for a focus made inside a user gesture. VTK turns a touchstart into a press that ImGui handles on the next frame, so the field is already active when the finger lifts, and the touchend handler focuses the input then. A field that becomes active with no finger down raises the keyboard on Android, and on iOS at the next tap.

What stays the same. Mouse clicks keep typing through the canvas as before. While the hidden input has focus the canvas doesn't, so SDL's filter (activeElement === canvas) drops those keys and VTK never sees them: typing a name never walks the avatar. SDL is still not given VTK's #canvas as its keyboard element.

An ImGui on-screen keyboard? Not worth it.

  • Dear ImGui has none. Its maintainer's position is that the platform supplies the text and io.WantTextInput tells you when to show one (ocornut/imgui#3968).
  • Third-party ones are small gists or examples, not something to depend on.
  • The system keyboard brings the user's language and layout, autocorrect, dictation, password managers and accessibility, which an ImGui-drawn keyboard would not.
  • An ImGui keypad is only worth it for a native build with no OS keyboard (a kiosk).

Natively, SDL3's SDL_StartTextInput raises the OS keyboard on iOS and Android. arigl has no mobile build yet; when it does, the same WantTextInput edge drives that.

Tests

  • cvcgl_imgui_ui_size (new; bare ImGui context, no GL). At a phone's 1.25 × 3 it checks:
    • the authored windows are scaled and clamped into a 1170 × 2532 view;
    • the px columns are scaled;
    • a group background's 120 px area is 450 device px (it was 120 before this branch scaled it);
    • the persisted geometry is logical;
    • at 1 × 1 the same document opens exactly as authored;
    • UiSettings doesn't hand its seed or the owner's own set() back to the owner, but does hand on an outside edit (the Controls window's pick).
  • AriadneAppRuntime.ControlsWindowOffersTheHostsUiSize. The Display row comes before the keys, the list shows the host's size, a pick writes a number the host reads back, and a host without one gets no row.
  • Existing tests on Windows (MSVC 14.44, RelWithDebInfo, shared libs):
    • 16 cvcgl tests: cvcgl_ari_golden (it renders, and every golden matches), the cvcgl_imgui_* tests, scene_chrome, ari_switch, ariadne_realize, ariadne_physics, tf_editor, stream_view, sdl_input and viewport_input;
    • ariadne_runtime_test 246/246;
    • ariadne_loader_test 210 passed, 2 skipped.
  • The cyprty wasm build (emsdk, cyprty-wasm-deps) compiles and links. In the in-app browser's mobile emulation it has pixel ratio 2 and a 750×1540 canvas, the hidden input is installed (16 px font), and the header hints and footer are hidden.

On a phone-sized page (in-app browser, mobile preset: 375 × 812 at pixel ratio 2)

No screenshots: they were skipped. What was checked by eye, on the build before the UiSettings fix:

  • The page loads with the panels hidden: only the scene and the corner button show. The relay logged the join.
  • A tap on the button brings the windows up, readable and inside the view, with the button still on top. The Settings menu opens over it.
  • Settings > Controls... opens the Controls window with Display / UI size above the keys.
    • It read 100%, which is how the UiSettings start-up bug was found.
    • The rebuilt wasm (with the fix) links, but it hasn't been looked at in the browser.

Not checked in a browser: the keyboard path. The in-app browser's clicks arrive as mouse clicks, which keep the old canvas path by design. Raising the keyboard needs a real touch, ideally on an iPhone and an Android phone.

…tem keyboard

VTK sizes the browser canvas in device pixels (CSS size x devicePixelRatio,
about 3 on a phone), so the overlay's 2.0 touch scale drew ~11 CSS px text, and
the "short side under 700 px" phone check never fired.

- ImGuiOverlay: the UI size (ui.scale) is in logical pixels, times the display's
  pixel ratio (FontScaleMain x FontScaleDpi; devicePixelRatio, read each frame;
  setPixelRatio overrides). Touch starts at 1.25. Scale changes land at the next
  frame and carry the open windows along. Touch slop, drag threshold and
  title-bar-only moves follow touch mode. The show/hide button stays above every
  window but a popup.
- ImGuiBackend: a document's px (window pos/size, tracks, columns, images,
  plots) scale with the UI, and persisted geometry is logical px. A window opens
  inside the view (a fitting one again once measured).
- AppRuntime::set_host_ui_size: a "UI size" list at the top of the Controls
  window (titled Controls, as in #963); arigl binds it to the overlay's scale.
- The browser system keyboard: while a finger activates an ImGui text field the
  overlay focuses a hidden <input> at its caret (in the touchend gesture, for
  iOS) and feeds ImGui what the keyboard does to it.
- cyprty.html hides its key hints and footer under 600 px; ARIADNE.md 5.11.
The constructor seeds the defaults (UI size 1, no touch) and, being synchronous, handed them
straight to ImGuiOverlay's apply callback, so a touch device's mode and UI size were lost before
the first frame: the phone screenshots came up at 100%. Fence the seed and set() as ViewportLayout
does; an outside edit (the Controls window's UI size) still reaches the overlay.
#931 took docs/ARIADNE.md §5.11 for pictures by URL, the slot this
branch had used for phones; the phone section is now §5.12, and the
ImGui layout note that points at it follows.
#932 took docs/ARIADNE.md §5.12 for backgrounds; the phone section is
now §5.13.

#932's ImGui backdrop took a group's authored px as device px, so on a
phone (UI size 1.25 at pixel ratio 3) a `size: [auto, 120]` background
came out a quarter of its height. It now goes through ui_px like every
other px a document authors, and cvcgl_imgui_ui_size checks the area at
the phone's scale and at 1 x 1.
#935 took docs/ARIADNE.md §5.13 for video and audio; the phone section
is now §5.14.
@transfix
transfix merged commit 731a11b into master Nov 2, 2026
27 of 28 checks passed
@transfix
transfix deleted the feat/arigl-phone-ui branch November 2, 2026 07:40
transfix added a commit that referenced this pull request Nov 2, 2026
Driving cyprty as a phone (headless Chrome: 390 x 844 CSS px at pixel
ratio 3, real touch events) after #967 showed two things wrong.

The conference's windows piled up. The document lays them out for a
laptop (My Camera at 20,40, Users at 390,40, Avatar at 20,610), and on a
phone each was moved into the view, all onto the same spot, the front one
translucent over the others. On a phone (a view under 500 CSS px on its
short side) a window whose authored place or size does not fit now opens
collapsed, its title bar under the others' from the top of the view: a
list of titles over the scene, to open one at a time. Opened, it unfolds
from its title, as wide as the view and no taller than the room below.
Windows that fit, those with no pos: (the flow), and every view wider
than a phone are as before.

Labels were cut off in a window that fits its widgets (the Controls
window: "UI", "Sen", "Car"). ImGui gives such a window's widgets 16
lines' width, most of a phone's at its UI size, and #967 stops the window
at the view's edge, so reserve_label_width's "the window grows to the
label" no longer held. There the widget now leaves its label room up to
the widest the window can be (the view less ImGui's safe-area padding),
which does not depend on the window's own size, so it holds still.

cvcgl_imgui_ui_size covers both: the stacked titles, the windows
unfolding from them, a slider in a fitting window with nothing to scroll
to, and a laptop where nothing opens collapsed.
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