fix(input): clamp a dragged ruler on an ordered y range and share the orientation test

This commit is contained in:
Martino Ferrari committed 2026-09-28 17:58:42 +02:00
1 parent 93ad774281
commit a153b73ead
5 files changed
+62 -14

No files matched your search

+8 -3
View File
@@ -505,7 +505,7 @@ void Controller::move_cursor(const PointerEvent& e) {
// A grabbed cursor mutates the coordinate its own orientation owns and nothing else, and
// each half names the one setter for it -- so a ruler dragged along y can never disturb a
// marker's x, and the dead coordinate of either is untouched by construction.
if (cursor.orientation == CursorOrientation::Horizontal) {
if (cursor.is_horizontal()) {
// Clamped to the ruler's own y axis: a pointer that has left the axes has no data under
// it, and the coordinate it extrapolates to is past the end of the axis the ruler reads
// values off -- a position where the ruler would either vanish (the renderer skips a row
@@ -514,7 +514,12 @@ void Controller::move_cursor(const PointerEvent& e) {
// verbatim, so a *caller* that means to park a ruler off range still can.
const Axis& axis = plot_->y_axis(cursor.axis_y);
const f64 y = plot_->y_transform(cursor.axis_y).to_data_y(static_cast<f64>(e.y));
plot_->set_cursor_y(id, std::clamp(y, axis.range.min, axis.range.max));
// `std::clamp` needs an ordered pair and a y range may be inverted -- descending depth,
// row index or time is ordinary -- because `set_y_range()` stores it verbatim and only
// the transform widens it. Order the bounds rather than assuming `min <= max`, or an
// inverted axis would collapse the dragged ruler onto one end (and the call is UB).
plot_->set_cursor_y(id, std::clamp(y, std::min(axis.range.min, axis.range.max),
std::max(axis.range.min, axis.range.max)));
return;
}
plot_->set_cursor_x(id, plot_->x_transform(cursor.axis_x).to_data_x(static_cast<f64>(e.x)));
@@ -611,7 +616,7 @@ u64 Controller::cursor_at(f32 px, f32 py) const {
// either way, which is what keeps hover and grab agreeing about a ruler exactly as
// they do about a marker. A point within reach of one of each resolves to the nearer,
// so neither orientation widens the other's target.
const bool horizontal = cursor.orientation == CursorOrientation::Horizontal;
const bool horizontal = cursor.is_horizontal();
const f32 d = std::fabs(plot_->cursor_screen_coordinate(i) - (horizontal ? py : px));
if (d > radius) continue;
if (best == kInvalid || d < best_d) {