From eeab477e72519ee70fc73a96c3353d2de9805f4b Mon Sep 17 00:00:00 2001 From: scawful Date: Thu, 17 Apr 2025 21:33:35 -0400 Subject: [PATCH] Add RenderLayout function to handle dynamic rendering of Text and Button elements; introduce Layout struct for managing UI components in input module. --- src/app/gui/input.cc | 22 ++++++++++++++++++++++ src/app/gui/input.h | 18 ++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/app/gui/input.cc b/src/app/gui/input.cc index 774b8543..1891add3 100644 --- a/src/app/gui/input.cc +++ b/src/app/gui/input.cc @@ -2,12 +2,20 @@ #include #include +#include #include "absl/strings/string_view.h" #include "app/gfx/snes_tile.h" #include "imgui/imgui.h" #include "imgui/imgui_internal.h" +template +struct overloaded : Ts... { + using Ts::operator()...; +}; +template +overloaded(Ts...) -> overloaded; + namespace ImGui { static inline ImGuiInputTextFlags InputScalar_DefaultCharsFilter( @@ -420,5 +428,19 @@ bool OpenUrl(const std::string& url) { return system(("open " + url).c_str()) == 0; } +void RenderLayout(const Layout& layout) { + for (const auto& element : layout.elements) { + std::visit(overloaded{[](const Text& text) { + ImGui::Text("%s", text.content.c_str()); + }, + [](const Button& button) { + if (ImGui::Button(button.label.c_str())) { + button.callback(); + } + }}, + element); + } +} + } // namespace gui } // namespace yaze diff --git a/src/app/gui/input.h b/src/app/gui/input.h index 0e253f5c..70760beb 100644 --- a/src/app/gui/input.h +++ b/src/app/gui/input.h @@ -3,15 +3,14 @@ #define IMGUI_DEFINE_MATH_OPERATORS +#include #include #include #include -#include #include #include #include -#include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" #include "app/gfx/snes_tile.h" #include "imgui/imgui.h" @@ -93,6 +92,21 @@ constexpr std::string kSeparator = "-"; IMGUI_API bool OpenUrl(const std::string &url); +struct Text { + std::string content; +}; + +struct Button { + std::string label; + std::function callback; +}; + +struct Layout { + std::vector> elements; +}; + +void RenderLayout(const Layout &layout); + } // namespace gui } // namespace yaze