Next try to make the settings modal work

This commit is contained in:
SimoZ64
2025-05-22 23:39:05 +02:00
parent ca21e57835
commit 1de29dd76d
5 changed files with 10 additions and 5 deletions

View File

@@ -2,6 +2,7 @@
#include <imgui.h> #include <imgui.h>
#include <string> #include <string>
#include <functional> #include <functional>
#include <utils/log.hpp>
namespace gui { namespace gui {
struct PopupWindow { struct PopupWindow {
@@ -15,7 +16,10 @@ struct PopupWindow {
bool render() { bool render() {
if(!opened) if(!opened)
return false; return false;
if (!ImGui::IsPopupOpen(title.c_str()))
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));

View File

@@ -8,7 +8,7 @@ struct PushButton {
bool render() { bool render() {
if(name != "") { if(name != "") {
ImGui::Text(name.c_str()); ImGui::Text("%s", name.c_str());
ImGui::SameLine(); ImGui::SameLine();
} }

View File

@@ -48,6 +48,7 @@ KaizenGui::KaizenGui() noexcept : window("Kaizen", 1280, 720), core(std::make_sh
actionStop, actionStop,
actionReset, actionReset,
{"Settings", [&]() { {"Settings", [&]() {
settingsWindow.popup.setOpened(true);
settingsWindow.render(); settingsWindow.render();
}}, }},
}}); }});

View File

@@ -52,7 +52,7 @@ SettingsWindow::SettingsWindow() : settings{JSONOpenOrCreate("resources/settings
apply.setEnabled(false); apply.setEnabled(false);
canvas.setFunc([&]() { popup.setFunc([&]() {
tabs.render(); tabs.render();
if(apply.render()) { if(apply.render()) {
@@ -69,7 +69,7 @@ SettingsWindow::SettingsWindow() : settings{JSONOpenOrCreate("resources/settings
} }
bool SettingsWindow::render() { bool SettingsWindow::render() {
if(canvas.render()) if(popup.render())
return true; return true;
return false; return false;

View File

@@ -9,12 +9,12 @@
class SettingsWindow final { class SettingsWindow final {
gui::PushButton cancel{"Cancel"}, apply{"Apply", "", false}, savesFolder{"Open", "Save path: {}"}; gui::PushButton cancel{"Cancel"}, apply{"Apply", "", false}, savesFolder{"Open", "Save path: {}"};
gui::PopupWindow canvas{"Settings"};
nlohmann::json settings; nlohmann::json settings;
CPUSettings cpuSettings{settings}; CPUSettings cpuSettings{settings};
AudioSettings audioSettings{settings}; AudioSettings audioSettings{settings};
InputSettings inputSettings{settings}; InputSettings inputSettings{settings};
public: public:
gui::PopupWindow popup{"Settings"};
bool render(); bool render();
SettingsWindow(); SettingsWindow();
[[nodiscard]] float getVolumeL() const { return audioSettings.volumeL.getValue() / 100.f; } [[nodiscard]] float getVolumeL() const { return audioSettings.volumeL.getValue() / 100.f; }