diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-01-25 10:58:57 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-01-25 10:58:57 +0100 |
commit | 83cb9db81f9c0e1e76bf5608cd4a26e50a43a1fa (patch) | |
tree | 8374d28d4df897cf48ee6ae7df3ba8d7f82ce155 /editor/tests-private.hpp | |
parent | 776f0a7b894d99d2621b96de62e1f15e17d049a0 (diff) |
a
Diffstat (limited to 'editor/tests-private.hpp')
-rw-r--r-- | editor/tests-private.hpp | 69 |
1 files changed, 20 insertions, 49 deletions
diff --git a/editor/tests-private.hpp b/editor/tests-private.hpp index d7854ac4..7967256e 100644 --- a/editor/tests-private.hpp +++ b/editor/tests-private.hpp @@ -5,16 +5,13 @@ #include "src/object-id.hpp" #include "floormat/events.hpp" #include <Corrade/Containers/StringView.h> +#include <memory> #include <vector> -#include <variant> namespace floormat { struct app; } namespace floormat::tests { -template<typename... Ts> struct overloaded : Ts... { using Ts::operator()...; }; -template<typename... Ts> overloaded(Ts...) -> overloaded<Ts...>; - struct base_test { fm_DECLARE_DEFAULT_MOVE_ASSIGNMENT_(base_test); @@ -34,61 +31,35 @@ protected: base_test(); }; -struct path_test : base_test -{ - bool handle_key(app& a, const key_event& e, bool is_down) override; - bool handle_mouse_click(app& a, const mouse_button_event& e, bool is_down) override; - bool handle_mouse_move(app& a, const mouse_move_event& e) override; - void draw_overlay(app& a) override; - void draw_ui(app& a, float width) override; - void update_pre(app& a) override; - void update_post(app& a) override; - - struct pending_s - { - point from, to; - object_id own_id; - uint32_t max_dist; - Vector2ub own_size; - } pending = {}; - - struct result_s - { - point from; - std::vector<point> path; - } result; +void label_left(StringView label, float width); - bool has_result : 1 = false, has_pending : 1 = false; +enum class Test : uint32_t { + none, path, COUNT, }; -void label_left(StringView label, float width); - -using variant = std::variant<std::monostate, tests::path_test>; +struct tests_data final : tests_data_ +{ + ~tests_data() noexcept override; -} // namespace floormat::tests + void switch_to(Test i); -namespace floormat { + static std::unique_ptr<base_test> make_test_none(); + static std::unique_ptr<base_test> make_test_path(); -struct tests_data final : tests_data_, tests::variant -{ - fm_DECLARE_DELETED_COPY_ASSIGNMENT(tests_data); - tests_data(); - ~tests_data() noexcept override; - using tests::variant::operator=; + std::unique_ptr<base_test> current_test; + Test current_index = Test::none; - struct pair + struct test_tuple { - StringView str; - size_t index; - tests::variant(*ctor)(); + StringView name; + Test t; + std::unique_ptr<base_test>(*ctor)(); }; - static constexpr inline pair fields[] = { - { "None"_s, 0, [] -> tests::variant { return std::monostate{}; } }, - { "Path"_s, 1, [] -> tests::variant { return tests::path_test{}; } }, + static constexpr test_tuple fields[] = { + { "None"_s, Test::none, &tests_data::make_test_none, }, + { "Path"_s, Test::path, &tests_data::make_test_path, }, }; - - void switch_to(size_t i); }; -} // namespace floormat +} // namespace floormat::tests |