smaller imgui impl improvements

This commit is contained in:
SimoZ64
2025-05-06 14:12:35 +02:00
parent dcdf961988
commit 3759be86a1
4 changed files with 26 additions and 14 deletions

View File

@@ -4,12 +4,16 @@
namespace gui { namespace gui {
struct PopupWindow { struct PopupWindow {
PopupWindow(const std::string& title, std::function<void()>&& func = nullptr, bool opened = true) : title(title), exec(func), opened(opened) {} PopupWindow(const std::string& title, std::function<void()>&& func = nullptr, bool opened = false) : title(title), exec(func), opened(opened) {}
void setFunc(std::function<void()>&& func) { void setFunc(std::function<void()>&& func) {
exec = func; exec = func;
} }
void setOpened(bool v) { opened = true; }
bool render() { bool render() {
if(!opened)
return false;
ImGui::OpenPopup(title.c_str()); ImGui::OpenPopup(title.c_str());
ImVec2 center = ImGui::GetMainViewport()->GetCenter(); ImVec2 center = ImGui::GetMainViewport()->GetCenter();
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
@@ -28,6 +32,6 @@ struct PopupWindow {
private: private:
std::function<void()> exec; std::function<void()> exec;
std::string title; std::string title;
bool opened = true; bool opened = false;
}; };
} }

View File

@@ -5,6 +5,8 @@ namespace gui {
struct StatusBar { struct StatusBar {
StatusBar(std::function<void()>&& func = nullptr, bool enabled = true) : exec(func), enabled(enabled) {} StatusBar(std::function<void()>&& func = nullptr, bool enabled = true) : exec(func), enabled(enabled) {}
void setFunc(std::function<void()>&& func) { exec = func; }
bool render() { bool render() {
float statusWindowHeight = ImGui::GetFrameHeight() * 1.4f; float statusWindowHeight = ImGui::GetFrameHeight() * 1.4f;
ImGuiViewport* viewport = ImGui::GetMainViewport(); ImGuiViewport* viewport = ImGui::GetMainViewport();

View File

@@ -12,6 +12,20 @@ KaizenGui::KaizenGui() noexcept : window(SDL_CreateWindow("Kaizen", 1280, 720, S
} }
}; };
about.setFunc([&]() {
ImGui::Text("Kaizen is a Nintendo 64 emulator that strives");
ImGui::Text("to offer a friendly user experience and compatibility.");
ImGui::Text("Kaizen is licensed under the BSD 3-clause license.");
ImGui::Text("Nintendo 64 is a registered trademarks of Nintendo Co., Ltd.");
if(ImGui::Button("OK")) {
about.setOpened(false);
}
});
statusBar.setFunc([&]() {
ImGui::Text("GUI FPS: %.2f, Emulation FPS: %.2f", ImGui::GetIO().Framerate, fpsCounter);
});
menuBar.addMenu({"File", menuBar.addMenu({"File",
{ {
{"Open", [&]() { {"Open", [&]() {
@@ -43,12 +57,7 @@ KaizenGui::KaizenGui() noexcept : window(SDL_CreateWindow("Kaizen", 1280, 720, S
menuBar.addMenu({"Help", menuBar.addMenu({"Help",
{ {
{"About", [&]() { {"About", [&]() {
gui::PopupWindow about{"About Kaizen", [&]() { about.setOpened(true);
ImGui::Text("Kaizen is a Nintendo 64 emulator that strives");
ImGui::Text("to offer a friendly user experience and compatibility.");
ImGui::Text("Kaizen is licensed under the BSD 3-clause license.");
ImGui::Text("Nintendo 64 is a registered trademarks of Nintendo Co., Ltd.");
}};
}}, }},
} }
}); });
@@ -81,11 +90,7 @@ int KaizenGui::run() {
menuBar.render(); menuBar.render();
// TODO VULKAN CANVAS about.render();
gui::StatusBar statusBar{[&]() {
ImGui::Text("GUI FPS: %.2f, Emulation FPS: %.2f", ImGui::GetIO().Framerate, fpsCounter);
}};
statusBar.render(); statusBar.render();
} }

View File

@@ -24,6 +24,7 @@ private:
bool quit = false; bool quit = false;
void handleEvents(); void handleEvents();
std::function<void()> emuExitFunc; std::function<void()> emuExitFunc;
gui::PopupWindow about{"About Kaizen"};
gui::StatusBar statusBar{};
bool textPauseToggle = false; bool textPauseToggle = false;
}; };