Add RenderLayout function to handle dynamic rendering of Text and Button elements; introduce Layout struct for managing UI components in input module.

This commit is contained in:
scawful
2025-04-17 21:33:35 -04:00
parent c3d707901c
commit eeab477e72
2 changed files with 38 additions and 2 deletions

View File

@@ -2,12 +2,20 @@
#include <functional>
#include <string>
#include <variant>
#include "absl/strings/string_view.h"
#include "app/gfx/snes_tile.h"
#include "imgui/imgui.h"
#include "imgui/imgui_internal.h"
template <class... Ts>
struct overloaded : Ts... {
using Ts::operator()...;
};
template <class... Ts>
overloaded(Ts...) -> overloaded<Ts...>;
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