feat(render): logical style metrics with a UI scale, so chrome has a consistent physical size

This commit is contained in:
Martino Ferrari committed 2026-09-28 12:17:53 +02:00
1 parent 1f03631e98
commit 7500fc90d2
21 files changed
+708 -82

No files matched your search

+6
View File
@@ -249,6 +249,12 @@ void Host::refresh_sizes() noexcept {
fb_height_ = fh > 0 ? static_cast<u32>(fh) : 0u;
if (ww > 0 && fw > 0) fb_scale_x_ = static_cast<f32>(fw) / static_cast<f32>(ww);
if (wh > 0 && fh > 0) fb_scale_y_ = static_cast<f32>(fh) / static_cast<f32>(wh);
// The renderer draws its logical style metrics at this same ratio, so the chrome
// is the same physical size at any scale: one value states the display, and a
// 12 px label is 24 device px on the 2x panel both these sizes describe. Read here
// rather than in the frame loop because this is the one place the two sizes are,
// and re-read whenever the window moves to a display with another scale.
if (renderer_) renderer_->style().ui_scale = fb_scale_x_;
}
// ------------------------------------------------------------------ events
+4 -1
View File
@@ -48,7 +48,10 @@ using FrameFn = std::function<void(plot::Plot&, f64 dt)>;
/// `glfwGetWindowSize()` disagree. The host calls `begin_frame` with the
/// framebuffer size and scales every pointer coordinate by the ratio
/// `framebuffer / window`, so a gesture lands on the pixels the plot was laid out
/// in. On an unscaled display the ratio is 1.0 and nothing changes.
/// in. The same ratio states the display to the renderer
/// (`Style::ui_scale`), which is what makes the chrome -- labels, strokes, paddings
/// -- one physical size at any scale. On an unscaled display the ratio is 1.0 and
/// nothing changes.
///
/// Headless smoke mode, read once per `run()`:
///