Upstream: crates/rune/README.md § Resizing and centring a window at
65f8eb43f710, MIT © Anomaly. Bundled by build-rune-apps; links point at this snapshot or at GitHub at that rev.
Resizing and centring a window
// In a handler: the next onboarding step is taller.
tx.motion(rune::tok::motion::SNAP); // optional; tok::motion::DEFAULT otherwise
tx.resize_window((480.0, 600.0)); // content size in points
tx.center_window(); // optional: centre the new size, on the same spring
// tx.resize_window_instant(size) or tx.instant() jumps.
// From outside a handler, on the event thread:
window.resize((480.0, 600.0)); // WindowHandle; also resize_instant, center
// Or let the content set the height, like SwiftUI's `.windowResizability(.contentSize)`:
rune::App::new(spec).fit_content_height().run();
- The top edge stays put and the window stays on its screen: growing past the bottom lifts it just enough, and a window the user dragged partly off screen moves no further off.
- Sizes stay inside the window's
min_sizeandmax_size(WindowOptions, elseAppSpec::min_size) on every platform. Headless runs apply only limits the app set. center_windowmatches AppKit'scenter: centred across, with a quarter of the spare height above and three quarters below.- On macOS the frame moves on a Rune spring, one display frame at a time. Each frame sets the window's frame before taking its drawable and lays the content out at the new size, and drawables present inside the frame's Core Animation transaction while it moves, so content pinned to an edge follows it with no stretched, stale or blank strip. Content at rest follows the window; layout springs and matched flights already running keep going. A resize mid-flight keeps its speed. Dragging the window mid-flight wins: it stays where the user puts it and the size carries on from there. Hiding or minimising it lands the frame. Reduced motion jumps.
- Windows and Linux resize at once with
request_inner_size. Wayland can't see or set a window's position, so it resizes without being kept on screen and ignores centring. - Headless runs move the viewport on the virtual clock, so
--treeand scripts see each step; frames keep the launch canvas size, and centring does nothing. - A requested size outlives the window: a closed window reopens at it.
fit_content_heightlays the root out at its natural height for the window's width (give it no fixed orfillheight), opens at that height and follows the content on each change's spring. A width change jumps, and a window the user resizes goes back to its content's height. Unless the app sets a minimum, its minimum height is 0 rather than the default 400 pt.- Overlays ignore these; use
OverlayHandle::resize.