功能比较完善的一版

This commit is contained in:
2026-08-21 22:12:47 +08:00
parent ae8d2f7272
commit e3d3bfd767
37 changed files with 563 additions and 224 deletions
+46 -25
View File
@@ -94,27 +94,33 @@ TEST(axis_render, scene_prepares_and_paints_uncached_axis_into_frame) {
}
TEST(axis_event, numeric_axis_wheel_zoom_and_drag_update_authoritative_range) {
using Object = Impl<Numeric_Axis>;
using Scene_Object = Impl<Render_Scene_2D>;
initialize_runtime(2);
auto axis = build_axis<Object>();
auto scene = build_axis<Scene_Object>();
axis->set<&Abs_Axis::Prop::position>(Point_F{0.0, 0.0});
axis->set<&Abs_Axis::Prop::pixel_length>(100.0);
axis->set<&Numeric_Axis::Prop::coordinate_range>(Axis_Range{0.0, 10.0});
axis->advance();
Wheel_Event wheel;
wheel.position = {50.0, 0.0};
wheel.angle_delta_y = 120.0;
axis->dispatch_event(wheel);
EXPECT_TRUE(wheel.is_accepted());
axis->advance();
scene->set<&Render_Scene_2D::Prop::viewport>(Size{120, 64});
ASSERT_TRUE((scene->edit_dependency_graph<Prepare_Data_Tag, Paint_Tag>([&](auto& prepare, auto& paint) {
prepare.add(axis.get()); paint.add(axis.get());
}).has_value()));
scene->activate_view();
scene->render();
auto wheel = std::make_unique<Wheel_Event>();
wheel->position = {50.0, 0.0};
wheel->angle_delta_y = 120.0;
scene->dispatch_event(std::move(wheel));
scene->render();
EXPECT_EQ(axis->coordinate_range(), (Axis_Range{0.5, 9.5}));
Pointer_Event press(Event_Type::pointer_press);
press.position = {50.0, 0.0};
press.button = Mouse_Button::left;
axis->dispatch_event(press);
Pointer_Event move(Event_Type::pointer_move);
move.position = {60.0, 0.0};
axis->dispatch_event(move);
EXPECT_TRUE(move.is_accepted());
axis->advance();
auto press = std::make_unique<Pointer_Event>(Event_Type::pointer_press);
press->position = {50.0, 0.0};
press->button = Mouse_Button::left;
scene->dispatch_event(std::move(press));
auto move = std::make_unique<Pointer_Event>(Event_Type::pointer_move);
move->position = {60.0, 0.0};
scene->dispatch_event(std::move(move));
scene->render();
EXPECT_EQ(axis->coordinate_range(), (Axis_Range{-0.4, 8.6}));
}
TEST(axis_event, scene_routes_pointer_interaction_to_the_nearest_axis_segment) {
@@ -139,18 +145,18 @@ TEST(axis_event, scene_routes_pointer_interaction_to_the_nearest_axis_segment) {
scene->activate_view();
scene->render();
Wheel_Event near_vertical;
near_vertical.position = {22.0, 80.0};
near_vertical.angle_delta_y = 120.0;
scene->dispatch_event(near_vertical);
auto near_vertical = std::make_unique<Wheel_Event>();
near_vertical->position = {22.0, 80.0};
near_vertical->angle_delta_y = 120.0;
scene->dispatch_event(std::move(near_vertical));
scene->render();
EXPECT_DOUBLE_EQ(horizontal->coordinate_range().size(), 10.0);
EXPECT_DOUBLE_EQ(vertical->coordinate_range().size(), 9.0);
Wheel_Event near_horizontal;
near_horizontal.position = {120.0, 178.0};
near_horizontal.angle_delta_y = 120.0;
scene->dispatch_event(near_horizontal);
auto near_horizontal = std::make_unique<Wheel_Event>();
near_horizontal->position = {120.0, 178.0};
near_horizontal->angle_delta_y = 120.0;
scene->dispatch_event(std::move(near_horizontal));
scene->render();
EXPECT_DOUBLE_EQ(horizontal->coordinate_range().size(), 9.0);
EXPECT_DOUBLE_EQ(vertical->coordinate_range().size(), 9.0);
@@ -177,8 +183,23 @@ TEST(axis_time, sample_state_drives_range_lookup_and_label_without_snapshot) {
EXPECT_EQ(axis->time_point_count(), 0u);
axis->advance();
EXPECT_EQ(axis->time_point_count(), 1u);
EXPECT_EQ(axis->coordinate_range(), (Axis_Range{0.0, 1.0}));
EXPECT_EQ(axis->coordinate_range(), (Axis_Range{-99.5, 0.5}));
EXPECT_EQ(axis->tick_to_time(0), (Time_Of_Day{3'723'004}));
EXPECT_EQ(axis->tick_label(0.0), "02:03.004");
EXPECT_FALSE(axis->tick_to_time(99).valid());
}
TEST(axis_time, appending_each_time_sample_invalidates_tick_preparation) {
using Object = Impl<Time_Axis>;
auto axis = build_axis<Object>();
axis->advance();
axis->template take_dirty<Prepare_Data_Tag>();
EXPECT_FALSE(axis->template dirty<Prepare_Data_Tag>());
EXPECT_EQ(axis->append_time({1'000}), 0);
EXPECT_TRUE(axis->template dirty<Prepare_Data_Tag>());
axis->advance();
axis->template take_dirty<Prepare_Data_Tag>();
EXPECT_EQ(axis->append_time({2'000}), 1);
EXPECT_TRUE(axis->template dirty<Prepare_Data_Tag>());
axis->advance();
EXPECT_EQ(axis->coordinate_range(), (Axis_Range{-98.5, 1.5}));
}