adapters: route pointer events by cell rect
This commit is contained in:
1 parent
7d8c453232
commit
e5b7faadec
6 files changed
+145
-93
No files matched your search
@@ -14,6 +14,9 @@
|
||||
#include <glfw/glfw_host.hpp>
|
||||
#include <plot/plot/figure.hpp>
|
||||
|
||||
#include <span>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
|
||||
/// A figure of `rows` rows over a known rect, with an x and a y axis in every row (so
|
||||
@@ -315,3 +318,31 @@ PLOT_TEST(the_host_keeps_its_own_controller_while_no_figure_is_set) {
|
||||
PLOT_CHECK(host.row_controller(0u) == nullptr);
|
||||
PLOT_CHECK(&host.controller_at(10.0f, 10.0f) == &host.controller());
|
||||
}
|
||||
|
||||
PLOT_TEST(glfw_host_routes_by_cell) {
|
||||
// A figure of two rows, the first of one cell and the second of two side by side: the
|
||||
// pointer's x as well as its y picks the plot, and the controllers are indexed by the
|
||||
// flattened plot.
|
||||
std::vector<plot::u32> cells{1, 2};
|
||||
plot::Figure figure{std::span<const plot::u32>(cells)};
|
||||
figure.set_viewport(plot::Rect{0, 0, 300, 600});
|
||||
figure.set_col_gap(6.0f);
|
||||
for (plot::u32 i = 0; i < 3; ++i) {
|
||||
figure.plot(i).add_x_axis({"t", {0.0, 1.0}, false, plot::AxisPlace::Bottom, false});
|
||||
figure.plot(i).add_y_axis({"v", {-1.0, 1.0}, false, plot::AxisPlace::Left, false});
|
||||
}
|
||||
plot::glfw::Host host;
|
||||
host.set_figure(&figure);
|
||||
const std::vector<plot::Rect> c = figure.layout().cells;
|
||||
PLOT_CHECK(c.size() == 3u);
|
||||
for (plot::u32 i = 0; i < 3; ++i) {
|
||||
PLOT_CHECK(host.row_controller(i) != nullptr);
|
||||
const double cx = c[i].x + c[i].w * 0.5, cy = c[i].y + c[i].h * 0.5;
|
||||
PLOT_CHECK(&host.controller_at(static_cast<plot::f32>(cx), static_cast<plot::f32>(cy)) ==
|
||||
host.row_controller(i));
|
||||
}
|
||||
PLOT_CHECK(host.row_controller(3u) == nullptr);
|
||||
// in the column gap: the nearest cell wins
|
||||
PLOT_CHECK(&host.controller_at(c[1].right() + 1.0f, c[1].y + 5.0f) == host.row_controller(1));
|
||||
PLOT_CHECK(&host.controller_at(c[2].x - 1.0f, c[2].y + 5.0f) == host.row_controller(2));
|
||||
}
|
||||
Reference in new issue
Block a user