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:
@@ -2,12 +2,20 @@
|
|||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <variant>
|
||||||
|
|
||||||
#include "absl/strings/string_view.h"
|
#include "absl/strings/string_view.h"
|
||||||
#include "app/gfx/snes_tile.h"
|
#include "app/gfx/snes_tile.h"
|
||||||
#include "imgui/imgui.h"
|
#include "imgui/imgui.h"
|
||||||
#include "imgui/imgui_internal.h"
|
#include "imgui/imgui_internal.h"
|
||||||
|
|
||||||
|
template <class... Ts>
|
||||||
|
struct overloaded : Ts... {
|
||||||
|
using Ts::operator()...;
|
||||||
|
};
|
||||||
|
template <class... Ts>
|
||||||
|
overloaded(Ts...) -> overloaded<Ts...>;
|
||||||
|
|
||||||
namespace ImGui {
|
namespace ImGui {
|
||||||
|
|
||||||
static inline ImGuiInputTextFlags InputScalar_DefaultCharsFilter(
|
static inline ImGuiInputTextFlags InputScalar_DefaultCharsFilter(
|
||||||
@@ -420,5 +428,19 @@ bool OpenUrl(const std::string& url) {
|
|||||||
return system(("open " + url).c_str()) == 0;
|
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 gui
|
||||||
} // namespace yaze
|
} // namespace yaze
|
||||||
|
|||||||
@@ -3,15 +3,14 @@
|
|||||||
|
|
||||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||||
|
|
||||||
|
#include <cctype>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <optional>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "absl/strings/str_cat.h"
|
|
||||||
#include "absl/strings/string_view.h"
|
#include "absl/strings/string_view.h"
|
||||||
#include "app/gfx/snes_tile.h"
|
#include "app/gfx/snes_tile.h"
|
||||||
#include "imgui/imgui.h"
|
#include "imgui/imgui.h"
|
||||||
@@ -93,6 +92,21 @@ constexpr std::string kSeparator = "-";
|
|||||||
|
|
||||||
IMGUI_API bool OpenUrl(const std::string &url);
|
IMGUI_API bool OpenUrl(const std::string &url);
|
||||||
|
|
||||||
|
struct Text {
|
||||||
|
std::string content;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Button {
|
||||||
|
std::string label;
|
||||||
|
std::function<void()> callback;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Layout {
|
||||||
|
std::vector<std::variant<Text, Button>> elements;
|
||||||
|
};
|
||||||
|
|
||||||
|
void RenderLayout(const Layout &layout);
|
||||||
|
|
||||||
} // namespace gui
|
} // namespace gui
|
||||||
} // namespace yaze
|
} // namespace yaze
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user