feat(render): logical style metrics with a UI scale, so chrome has a consistent physical size
This commit is contained in:
1 parent
1f03631e98
commit
7500fc90d2
21 files changed
+708
-82
No files matched your search
@@ -303,6 +303,12 @@ void PlotArea::render() noexcept {
|
||||
last_render_s_ = started;
|
||||
if (frame_) frame_(*plot_, dt);
|
||||
|
||||
// The mapping's factor is the display's scale, so the renderer draws its logical
|
||||
// style metrics at the same ratio the viewport and every forwarded coordinate are
|
||||
// in: a 12 px label is the same physical size on a 1x and a 2x widget. It is the
|
||||
// `::resize` ratio, not `gtk_widget_get_scale_factor()` -- the latter is the
|
||||
// ceiling under fractional scaling and would over-scale the chrome by up to 60%.
|
||||
renderer_->style().ui_scale = mapping_.factor;
|
||||
renderer_->begin_frame(static_cast<u32>(viewport.w), static_cast<u32>(viewport.h), viewport);
|
||||
renderer_->draw(*plot_);
|
||||
renderer_->end_frame();
|
||||
|
||||
@@ -110,11 +110,14 @@ using FrameFn = std::function<void(Plot&, f64 dt)>;
|
||||
/// a delta is then a logical difference scaled by the factor in force now, never
|
||||
/// the difference of two device positions (see `DragAnchor`).
|
||||
///
|
||||
/// Note that this also means the renderer's *style metrics* stay in device
|
||||
/// pixels: at scale 2 the label font is 24 device px = 12 logical px, so labels
|
||||
/// are smaller relative to the widget than at 1x. That is the same convention
|
||||
/// the GLFW and Qt adapters use, and a host that wants a constant logical text
|
||||
/// size scales `Renderer::style()` metrics by the factor itself.
|
||||
/// The same factor states the display to the *renderer*: it is written to
|
||||
/// `Renderer::style().ui_scale` every frame, which is what makes the chrome the
|
||||
/// same physical size at any scale. The style's metrics are logical (see the unit
|
||||
/// rule on `render::Style` -- spec §10 reverses the older convention that had them
|
||||
/// in device pixels and accepted smaller labels on a high-DPI host), so at scale 2
|
||||
/// the label font is 12 logical px drawn at 24 device px: the same size on screen as
|
||||
/// at 1x, not a smaller one. This is the same convention the GLFW, Qt and ImGui
|
||||
/// adapters use, and none of them has to scale a style metric by hand.
|
||||
///
|
||||
/// ## Input
|
||||
///
|
||||
|
||||
Reference in new issue
Block a user