feat(cursor): a cursor's stroke is its own -- width and dash
Cursors took `Style::line_width_px` and were always solid, so a host had no way to place a *readout mark* on the data (a measured level, a peak, a pulse's edge) without it reading as another instrument framing the plot. `set_cursor_stroke(id, width, dash)` gives it its own, the same shape as `set_cursor_color()`: per cursor, because one plot holds both kinds. `width <= 0` means the style's default for that cursor (`handle_width_px` while hovered or grabbed, `line_width_px` otherwise), and a hover can only make the stroke *thicker* -- the cue that the pointer has hold of something must not be the thing that hides it. `dash.off <= 0` is solid, the convention a trace's, the crosshair's and the grid's dash already share. Test: a_cursor_stroke_can_be_thinner_and_dashed -- a default cursor and a thin dashed one in the same frame. The dashed column alternates ink and gap (153/151 at the 4/4 the test asks for) while the solid one has no gaps; the ink laid down over each stroke's whole run of columns is less for the thin one. That last assertion is deliberately *not* a single-column peak: a cursor is a data position and is not snapped, so the solid stroke's ink split across two columns and read *lighter* than the thin one -- which is how this test first failed.
This commit is contained in:
1 parent
c4c0a49466
commit
fba8d985cf
6 files changed
+154
-5
No files matched your search
@@ -311,6 +311,12 @@ void Plot::set_cursor_color(u32 id, Color color) {
|
||||
cursors_[id].color = color;
|
||||
}
|
||||
|
||||
void Plot::set_cursor_stroke(u32 id, f32 width, Vec2 dash) {
|
||||
if (id >= cursors_.size()) return;
|
||||
cursors_[id].width = width;
|
||||
cursors_[id].dash = dash;
|
||||
}
|
||||
|
||||
void Plot::set_cursor_selectable(u32 id, bool selectable) {
|
||||
if (id >= cursors_.size()) return;
|
||||
cursors_[id].selectable = selectable;
|
||||
|
||||
@@ -1117,7 +1117,12 @@ void Renderer::draw_cursors(const Plot& plot, const PlotLayout& layout) {
|
||||
// belongs to the plot, and `to_screen_y()` of a range maximum can undershoot `axes.y` by
|
||||
// a floating-point ulp, which a bare `<` would mistake for "outside". Only the ones
|
||||
// beyond that margin are skipped.
|
||||
const f32 half = 0.5f * style_.device(on ? style_.handle_width_px : style_.line_width_px);
|
||||
// The cursor's own width when it has one, else the style's; a hover or a grab can only make
|
||||
// it thicker (the cue that the pointer has hold of something).
|
||||
const f32 own = cursor.width > 0.0f ? style_.device(cursor.width)
|
||||
: style_.device(style_.line_width_px);
|
||||
const f32 width = on ? std::max(own, style_.device(style_.handle_width_px)) : own;
|
||||
const f32 half = 0.5f * width;
|
||||
if (horizontal ? (at < layout.axes.y - half || at > layout.axes.bottom() + half)
|
||||
: (at < layout.axes.x - half || at > layout.axes.right() + half)) {
|
||||
continue;
|
||||
@@ -1141,15 +1146,13 @@ void Renderer::draw_cursors(const Plot& plot, const PlotLayout& layout) {
|
||||
stage_segment(x_range.min, x_range.min, y_drawn, x_range.max, y_drawn, log_x,
|
||||
plot.y_axis(cursor.axis_y).log);
|
||||
flush_lines(mapping(plot, 0, cursor.axis_y, x_range.min),
|
||||
on ? style_.cursor : cursor.color,
|
||||
style_.device(on ? style_.handle_width_px : style_.line_width_px));
|
||||
on ? style_.cursor : cursor.color, width, cursor.dash);
|
||||
} else {
|
||||
const f64 x_drawn = plot.x_transform(cursor.axis_x).to_data_x(static_cast<f64>(drawn));
|
||||
stage_segment(x_drawn, x_drawn, y_range.min, x_drawn, y_range.max,
|
||||
plot.x_axis(cursor.axis_x).log, log_y);
|
||||
flush_lines(mapping(plot, cursor.axis_x, 0, x_drawn),
|
||||
on ? style_.cursor : cursor.color,
|
||||
style_.device(on ? style_.handle_width_px : style_.line_width_px));
|
||||
on ? style_.cursor : cursor.color, width, cursor.dash);
|
||||
}
|
||||
draw_cursor_label(plot, layout, cursor, drawn);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user