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
@@ -20,6 +20,11 @@ enum class LegendPlace { TopLeft, TopRight, BottomLeft, BottomRight };
|
||||
/// All of it is deliberately coarse: the size, the row heights and the panel's
|
||||
/// extent come from the text backend's metrics and the names themselves, never from
|
||||
/// a caller's arithmetic, so a legend can only be *placed* and never mis-measured.
|
||||
///
|
||||
/// The sizes below are **logical** units, like every other metric a user
|
||||
/// perceives as a size (see the unit rule on `render::Style`): `Plot::layout()`
|
||||
/// converts each through `Style::device()` before it measures the panel, so a
|
||||
/// legend is the same physical size on a 2x panel as on a 1x one.
|
||||
struct Legend {
|
||||
/// Draw the legend at all. This is on by default and costs nothing to leave on:
|
||||
/// a legend with no entries -- no trace named, or no backend to measure a name
|
||||
|
||||
@@ -17,9 +17,11 @@
|
||||
namespace plot {
|
||||
|
||||
/// Pixel geometry of a plot's chrome, all of it in the same pixel space as
|
||||
/// `Rect` (origin top-left). `axes` is the area data is drawn into; the label
|
||||
/// areas are the strips the tick labels live in and the title areas the strips
|
||||
/// the axis titles live in, each outside `axes` and so never over the data.
|
||||
/// `Rect` (origin top-left) and therefore in **device** pixels: everything here is
|
||||
/// what the renderer draws with, already converted from the logical metrics in
|
||||
/// `Style` (see the unit rule on `Style`). `axes` is the area data is drawn into;
|
||||
/// the label areas are the strips the tick labels live in and the title areas the
|
||||
/// strips the axis titles live in, each outside `axes` and so never over the data.
|
||||
///
|
||||
/// `y_*` strips are left of `axes` and `x_*` ones below it, whatever an axis'
|
||||
/// `place` says: an axis placed on the opposite edge still has its labels and
|
||||
@@ -86,6 +88,15 @@ class Plot {
|
||||
/// uses the renderer's values.
|
||||
void set_style(const render::Style& s) noexcept { style_ = s; }
|
||||
const render::Style& style() const noexcept { return style_; }
|
||||
/// Device pixels per logical unit: what every metric in `style()` means, and what
|
||||
/// the controller's pointer tolerances are scaled by. Set from the renderer, which
|
||||
/// owns presentation -- `Renderer::draw()` writes `style().ui_scale` here before it
|
||||
/// lays the chrome out, so the strips and the strokes cannot disagree about the
|
||||
/// scale -- and set directly by a host that lays a plot out itself, or by a
|
||||
/// controller whose plot no renderer draws.
|
||||
void set_ui_scale(f32 scale) noexcept { style_.ui_scale = scale; }
|
||||
/// The scale the last layout was computed at. 1.0 until a host says otherwise.
|
||||
f32 ui_scale() const noexcept { return style_.ui_scale; }
|
||||
|
||||
/// The font layout() measures tick labels with. Borrowed, not owned, and may be
|
||||
/// null -- then the label areas fall back to PlotLayout's defaults and no string
|
||||
|
||||
Reference in new issue
Block a user