adapters: route pointer events by cell rect

This commit is contained in:
Martino Ferrari committed 2026-11-03 17:04:16 +01:00
1 parent 7d8c453232
commit e5b7faadec
6 files changed
+145 -93

No files matched your search

+21 -17
View File
@@ -260,15 +260,17 @@ class PlotArea {
Figure* figure() noexcept { return figure_; }
const Figure* figure() const noexcept { return figure_; }
/// One figure row's controller -- the one a gesture on that row reaches -- or null
/// while no figure is set or the row does not exist. A host reads a drag mode or a
/// One figure plot's controller -- the one a gesture on that plot reaches -- or null
/// while no figure is set or it does not exist. `row` is the **flattened plot index**
/// (`Figure::plot_count()` of them: the row count when no row holds several cells). A host reads a drag mode or a
/// hover out of it.
input::Controller* row_controller(u32 row) noexcept;
/// The controller an event at device pixel `(x, y)` belongs to: `controller()`
/// while no figure is set, and otherwise the controller of the figure row that
/// pixel lands in -- a pixel inside no row (a `Figure::set_row_gap()` gap, a
/// margin) is the *nearest* row rather than dropped, so a drag that leaves the data
/// while no figure is set, and otherwise the controller of the figure plot (cell)
/// that pixel lands in -- x and y both pick it, as a row may hold several cells side
/// by side. A pixel inside no cell (a `Figure::set_row_gap()`/`set_col_gap()` gap, a
/// margin) is the *nearest* cell rather than dropped, so a drag that leaves the data
/// area still ends where it should. It also hands that row its own viewport, which
/// is what keeps the controller's hit-test geometry in step with the layout between
/// two frames.
@@ -277,10 +279,10 @@ class PlotArea {
/// press capture, so a host may call it freely.
input::Controller& controller_at(f32 x, f32 y) noexcept;
/// The figure row a point in the widget's **logical** coordinates lands in -- the
/// The flattened plot index a point in the widget's **logical** coordinates lands in -- the
/// coordinates every GTK event controller reports, so a host's own drop target or
/// context menu can name the row a pointer is over without converting anything. The
/// same nearest-row rule as `controller_at()`, and 0 while no figure is set.
/// context menu can name the plot a pointer is over without converting anything. The
/// same nearest-cell rule (x and y) as `controller_at()`, and 0 while no figure is set.
u32 row_at(double x, double y) const noexcept;
/// Re-reads the figure's row rects into the cache the event routing answers from --
@@ -376,20 +378,21 @@ class PlotArea {
/// into device pixels. The one place that mapping exists.
Vec2 to_device(double x, double y) const noexcept;
/// The controller one event of this area's goes to, given the event's device y.
/// The controller one event of this area's goes to, given the event's device (x, y).
/// `controller_` while no figure is set; otherwise the row the gesture *belongs*
/// to: the row the open press claimed while a press is open, and the row under `y`
/// between gestures. That is the capture `controller_at()` deliberately omits, and
/// between gestures (x and y pick the cell). That is the capture `controller_at()` deliberately omits, and
/// it is why this -- not `controller_at()` -- is what every handler below calls.
///
/// Hands the chosen row its own viewport, so the geometry it hit-tests is the
/// geometry the last frame drew.
input::Controller& target_controller(f32 y) noexcept;
/// The row of `row_rects_` a device y belongs to: the row it is in, or the nearest
/// one when it is in none (a row gap, a margin outside the figure). Selection by
/// distance rather than "the first that matches" is what makes a pixel in a visible
/// gap belong to the row it is *near* instead of to row 0.
static u32 row_in(const std::vector<Rect>& rows, f32 y) noexcept;
input::Controller& target_controller(f32 x, f32 y) noexcept;
/// The cell of `row_rects_` (the figure's flattened cell rects) a device pixel belongs
/// to: the cell it is in, or the nearest one when it is in none (a row or column gap,
/// a margin outside the figure). Selection by distance rather than "the first that
/// matches" is what makes a pixel in a visible gap belong to the cell it is *near*
/// instead of to plot 0.
static u32 row_in(const std::vector<Rect>& rows, f32 x, f32 y) noexcept;
/// The row this area's events currently go to: the press's row while one is open,
/// so an in-flight gesture keeps its highlight, and the row under the last pointer
/// position otherwise. 0 with no rows.
@@ -457,7 +460,8 @@ class PlotArea {
/// `set_figure()` is called, and the single-plot path reads neither.
Figure* figure_ = nullptr;
std::vector<std::unique_ptr<input::Controller>> row_controllers_;
/// The figure's row rects as of the last `refresh_row_rects()`: the cache the event
/// The figure's cell rects (one per plot, flattened; the row rects when no row is split)
/// as of the last `refresh_row_rects()`: the cache the event
/// routing reads instead of laying the figure out per event. Empty while no figure
/// is set, which is the state the routing falls back to `controller_` on.
std::vector<Rect> row_rects_;