fix(input): clamp a dragged ruler on an ordered y range and share the orientation test
This commit is contained in:
1 parent
93ad774281
commit
a153b73ead
5 files changed
+62
-14
No files matched your search
+10
-9
@@ -239,13 +239,14 @@ const Cursor& Plot::cursor(u32 id) const {
|
||||
f32 Plot::cursor_screen_coordinate(u32 id) const {
|
||||
if (id >= cursors_.size()) return 0.0f;
|
||||
const Cursor& cursor = cursors_[id];
|
||||
// Which coordinate is the marker's, decided once, here: the axis reached for is the one
|
||||
// the cursor's own orientation names, and the other orientation's coordinate is not
|
||||
// Which coordinate is the marker's, decided once, in `Cursor`: the axis reached for is the
|
||||
// one the cursor's own orientation names, and the other orientation's coordinate is not
|
||||
// consulted at all -- a ruler is never placed by a dead x.
|
||||
if (cursor.orientation == CursorOrientation::Horizontal) {
|
||||
return static_cast<f32>(y_transform(cursor.axis_y).to_screen_y(cursor.y));
|
||||
if (cursor.is_horizontal()) {
|
||||
return static_cast<f32>(
|
||||
y_transform(cursor.coordinate_axis()).to_screen_y(cursor.coordinate()));
|
||||
}
|
||||
return static_cast<f32>(x_transform(cursor.axis_x).to_screen_x(cursor.x));
|
||||
return static_cast<f32>(x_transform(cursor.coordinate_axis()).to_screen_x(cursor.coordinate()));
|
||||
}
|
||||
|
||||
const Annotation& Plot::annotation(u32 id) const {
|
||||
@@ -504,7 +505,7 @@ void Plot::set_cursor_x(u32 id, f64 x) {
|
||||
// `x` is the vertical cursor's coordinate and nobody else's: a ruler's `x` is dead, and
|
||||
// writing it would leave the struct holding two coordinates that disagree about where the
|
||||
// cursor is (see CursorOrientation).
|
||||
if (cursor.orientation != CursorOrientation::Vertical) return;
|
||||
if (cursor.is_horizontal()) return;
|
||||
cursor.x = x;
|
||||
cursor.x = snapped_x(cursor);
|
||||
mark_measures_dirty();
|
||||
@@ -516,7 +517,7 @@ void Plot::set_cursor_snap(u32 id, SnapMode mode) {
|
||||
// The vertical snap, on a vertical cursor: a ruler's snap is `HRulerSnap`, and the two
|
||||
// must not drift into meaning each other's job -- `NearestSample` is a sample of an x
|
||||
// grid, which a ruler has no notion of.
|
||||
if (cursor.orientation != CursorOrientation::Vertical) return;
|
||||
if (cursor.is_horizontal()) return;
|
||||
cursor.snap = mode;
|
||||
cursor.x = snapped_x(cursor);
|
||||
mark_measures_dirty();
|
||||
@@ -525,7 +526,7 @@ void Plot::set_cursor_snap(u32 id, SnapMode mode) {
|
||||
void Plot::set_cursor_y(u32 id, f64 y) {
|
||||
if (id >= cursors_.size()) return;
|
||||
Cursor& ruler = cursors_[id];
|
||||
if (ruler.orientation != CursorOrientation::Horizontal) return;
|
||||
if (!ruler.is_horizontal()) return;
|
||||
ruler.y = y;
|
||||
ruler.y = snapped_y(ruler);
|
||||
// No mark_measures_dirty(), for `add_h_ruler()`'s reason: a measurement is read from two
|
||||
@@ -535,7 +536,7 @@ void Plot::set_cursor_y(u32 id, f64 y) {
|
||||
void Plot::set_cursor_h_snap(u32 id, HRulerSnap mode) {
|
||||
if (id >= cursors_.size()) return;
|
||||
Cursor& ruler = cursors_[id];
|
||||
if (ruler.orientation != CursorOrientation::Horizontal) return;
|
||||
if (!ruler.is_horizontal()) return;
|
||||
ruler.h_snap = mode;
|
||||
ruler.y = snapped_y(ruler);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user