diff options
Diffstat (limited to 'editor')
-rw-r--r-- | editor/app.hpp | 2 | ||||
-rw-r--r-- | editor/imgui-editors.cpp | 6 | ||||
-rw-r--r-- | editor/imgui-raii.cpp | 6 | ||||
-rw-r--r-- | editor/imgui-raii.hpp | 1 | ||||
-rw-r--r-- | editor/inspect.cpp | 2 | ||||
-rw-r--r-- | editor/tests-private.hpp | 15 | ||||
-rw-r--r-- | editor/tests.cpp | 43 | ||||
-rw-r--r-- | editor/tests/path-test.cpp | 7 |
8 files changed, 65 insertions, 17 deletions
diff --git a/editor/app.hpp b/editor/app.hpp index dad4f539..14a0fcd6 100644 --- a/editor/app.hpp +++ b/editor/app.hpp @@ -168,7 +168,7 @@ private: [[nodiscard]] bool tests_handle_mouse_move(const mouse_move_event& e); void tests_pre_update(); void tests_post_update(); - void draw_tests_pane(); + void draw_tests_pane(float width); void draw_tests_overlay(); void tests_reset_mode(); tests_data& tests(); diff --git a/editor/imgui-editors.cpp b/editor/imgui-editors.cpp index 1c15989f..ad71ea0a 100644 --- a/editor/imgui-editors.cpp +++ b/editor/imgui-editors.cpp @@ -263,9 +263,11 @@ void app::draw_editor_pane(float main_menu_height) ImGuiWindowFlags_NoSavedSettings); const auto b = push_id("editor"); + float width = 425 * dpi.x(); + ImGui::SetNextWindowPos({0, main_menu_height+style.WindowPadding.y}); ImGui::SetNextFrameWantCaptureKeyboard(false); - ImGui::SetNextWindowSize({425 * dpi[0], window_size[1]-main_menu_height - style.WindowPadding.y}); + ImGui::SetNextWindowSize({width, window_size.y()-main_menu_height - style.WindowPadding.y}); if (auto b = begin_window({}, nullptr, igwf)) { const auto b2 = push_id("editor-pane"); @@ -281,7 +283,7 @@ void app::draw_editor_pane(float main_menu_height) else if (wa) impl_draw_editor_scenery_pane<wall_editor>(*wa, dpi); else if (_editor->mode() == editor_mode::tests) - draw_tests_pane(); + draw_tests_pane(width); } } } diff --git a/editor/imgui-raii.cpp b/editor/imgui-raii.cpp index 5396196c..8cae0818 100644 --- a/editor/imgui-raii.cpp +++ b/editor/imgui-raii.cpp @@ -153,4 +153,10 @@ raii_wrapper begin_window(Containers::StringView name, bool* p_open, ImGuiWindow return {}; } +raii_wrapper begin_child(StringView name, const ImVec2& size, int flags, int window_flags) +{ + ImGui::BeginChild(name.data(), size, flags, window_flags); + return {&ImGui::EndChild}; +} + } // namespace floormat::imgui diff --git a/editor/imgui-raii.hpp b/editor/imgui-raii.hpp index c2e8bae9..63c749bb 100644 --- a/editor/imgui-raii.hpp +++ b/editor/imgui-raii.hpp @@ -24,6 +24,7 @@ private: }; [[nodiscard]] raii_wrapper begin_window(StringView name = {}, bool* p_open = nullptr, ImGuiWindowFlags flags = ImGuiWindowFlags_None); +[[nodiscard]] raii_wrapper begin_child(StringView name, const ImVec2& size, int flags = ImGuiChildFlags_None, int window_flags = ImGuiWindowFlags_None); [[nodiscard]] raii_wrapper begin_main_menu(); [[nodiscard]] raii_wrapper begin_menu(StringView name, bool enabled = true); [[nodiscard]] raii_wrapper begin_list_box(StringView name, ImVec2 size = {}); diff --git a/editor/inspect.cpp b/editor/inspect.cpp index 1c329d85..e3fa8bad 100644 --- a/editor/inspect.cpp +++ b/editor/inspect.cpp @@ -22,7 +22,7 @@ const char* label_left(StringView label, char(&buf)[N], size_t width) { std::snprintf(buf, N, "##%s", label.data()); float x = ImGui::GetCursorPosX(); - ImGui::Text("%s", label.data()); + ImGui::TextEx(label.data(), label.data() + label.size()); ImGui::SameLine(); ImGui::SetCursorPosX(x + (float)width + ImGui::GetStyle().ItemInnerSpacing.x); ImGui::SetNextItemWidth(-1); diff --git a/editor/tests-private.hpp b/editor/tests-private.hpp index 0b38b8a5..d7854ac4 100644 --- a/editor/tests-private.hpp +++ b/editor/tests-private.hpp @@ -24,6 +24,7 @@ struct base_test virtual bool handle_mouse_click(app& a, const mouse_button_event& e, bool is_down) = 0; virtual bool handle_mouse_move(app& a, const mouse_move_event& e) = 0; virtual void draw_overlay(app& a) = 0; + virtual void draw_ui(app& a, float width) = 0; virtual void update_pre(app& a) = 0; virtual void update_post(app& a) = 0; @@ -39,6 +40,7 @@ struct path_test : base_test 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; @@ -59,6 +61,8 @@ struct path_test : base_test bool has_result : 1 = false, has_pending : 1 = false; }; +void label_left(StringView label, float width); + using variant = std::variant<std::monostate, tests::path_test>; } // namespace floormat::tests @@ -72,11 +76,16 @@ struct tests_data final : tests_data_, tests::variant ~tests_data() noexcept override; using tests::variant::operator=; - struct pair { StringView str; size_t index; }; + struct pair + { + StringView str; + size_t index; + tests::variant(*ctor)(); + }; static constexpr inline pair fields[] = { - { "None"_s, 0 }, - { "Path"_s, 1 }, + { "None"_s, 0, [] -> tests::variant { return std::monostate{}; } }, + { "Path"_s, 1, [] -> tests::variant { return tests::path_test{}; } }, }; void switch_to(size_t i); diff --git a/editor/tests.cpp b/editor/tests.cpp index 41d39cd2..8d0d72c5 100644 --- a/editor/tests.cpp +++ b/editor/tests.cpp @@ -1,11 +1,25 @@ #include "tests-private.hpp" #include "compat/safe-ptr.hpp" #include "app.hpp" +#include "floormat/main.hpp" #include "floormat/events.hpp" #include "imgui-raii.hpp" #define HAVE_LIBC 1 #include <SDL_keycode.h> +namespace floormat::tests { + +void label_left(StringView label, float width) +{ + float x = ImGui::GetCursorPosX(); + ImGui::TextEx(label.data(), label.data() + label.size()); + ImGui::SameLine(); + ImGui::SetCursorPosX(x + width + ImGui::GetStyle().ItemInnerSpacing.x); + ImGui::SetNextItemWidth(-1); +} + +} // namespace floormat::tests + namespace floormat { using namespace floormat::tests; @@ -23,13 +37,9 @@ using namespace floormat::imgui; void tests_data::switch_to(size_t i) { - constexpr auto size = std::variant_size_v<tests::variant>; - fm_assert(i < size); - switch (i) - { - case 0: *this = std::monostate{}; break; - case 1: *this = path_test{}; break; - } + fm_assert(i < std::size(fields)); + const auto& [str, index, ctor] = fields[i]; + *this = ctor(); } safe_ptr<tests_data_> tests_data_::make() @@ -97,21 +107,34 @@ void app::tests_reset_mode() tests() = std::monostate{}; } -void app::draw_tests_pane() +void app::draw_tests_pane(float width) { ImGui::SeparatorText("Functional tests"); constexpr int selectable_flags = ImGuiSelectableFlags_SpanAvailWidth; - for (auto [str, i] : tests_data::fields) + for (auto [str, i, ctor] : tests_data::fields) if (ImGui::Selectable(str.data(), i == tests().index(), selectable_flags)) tests().switch_to(i); + + std::visit(overloaded { + [](std::monostate) {}, + [&](base_test& x) { + auto dpi = M->dpi_scale(); + ImGui::NewLine(); + ImGui::SeparatorEx(ImGuiSeparatorFlags_Horizontal, 2*dpi.y()); + auto b = push_id("###test-data"); + return x.draw_ui(*this, width); + } + }, tests()); } void app::draw_tests_overlay() { std::visit(overloaded { [](std::monostate) {}, - [&](base_test& x) { return x.draw_overlay(*this); } + [&](base_test& x) { + return x.draw_overlay(*this); + } }, tests()); } diff --git a/editor/tests/path-test.cpp b/editor/tests/path-test.cpp index c21c13c9..ca976a38 100644 --- a/editor/tests/path-test.cpp +++ b/editor/tests/path-test.cpp @@ -126,4 +126,11 @@ void path_test::update_post(app& a) (void)a; } +void path_test::draw_ui(app& a, float width) +{ + static uint32_t val; + label_left("foo", 100); + ImGui::InputScalar("##foo", ImGuiDataType_U32, &val); +} + } // namespace floormat::tests |