Fix apply button not turning grey after clicking on it.

This commit is contained in:
IrisZ64
2025-12-14 16:21:21 +01:00
parent affb221c2c
commit 9a1089b70e
8 changed files with 87 additions and 64 deletions

View File

@@ -2,13 +2,42 @@
#include <log.hpp>
#include <Options.hpp>
#include <imgui.h>
#include <ranges>
void GeneralTab::render() {
if(ImGui::Button("Pick...")) {
SDL_ShowOpenFolderDialog([](void *userdata, const char * const *filelist, int _) {
auto* general = static_cast<GeneralTab*>(userdata);
auto& settings = general->settingsWindow;
if (!filelist) {
panic("An error occurred: {}", SDL_GetError());
}
if (!*filelist) {
warn("The user did not select any file.");
warn("Most likely, the dialog was canceled.");
general->modified = false;
return;
}
settings.savesPath = *filelist;
Options::GetInstance().SetValue<std::string>("general", "savePath", settings.savesPath);
general->modified = true;
}, this, settingsWindow.window.getHandle(), nullptr, false);
}
ImGui::SameLine();
ImGui::BeginDisabled();
ImGui::InputText("Save Path", const_cast<char*>(settingsWindow.savesPath.c_str()), settingsWindow.savesPath.length());
ImGui::EndDisabled();
}
SettingsWindow::SettingsWindow(gui::NativeWindow& window) : window(window) {
savesPath = Options::GetInstance().GetValue<std::string>("general", "savePath");
}
bool SettingsWindow::render() {
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
const ImVec2 center = ImGui::GetMainViewport()->GetCenter();
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
if(!ImGui::BeginPopupModal("Settings", &isOpen))
@@ -17,46 +46,14 @@ bool SettingsWindow::render() {
if(!ImGui::BeginTabBar("SettingsTabBar"))
return false;
if(ImGui::BeginTabItem("General")) {
if(ImGui::Button("Pick...")) {
SDL_ShowOpenFolderDialog([](void *userdata, const char * const *filelist, int filter) {
SettingsWindow* settings = (SettingsWindow*)userdata;
if (!filelist) {
panic("An error occured: {}", SDL_GetError());
return;
} else if (!*filelist) {
warn("The user did not select any file.");
warn("Most likely, the dialog was canceled.");
return;
}
settings->savesPath = *filelist;
Options::GetInstance().SetValue<std::string>("general", "savePath", settings->savesPath);
settings->applyEnabled = true;
}, this, window.getHandle(), nullptr, false);
}
ImGui::SameLine();
ImGui::BeginDisabled();
ImGui::InputText("Save Path", (char*)savesPath.c_str(), savesPath.length());
ImGui::EndDisabled();
ImGui::EndTabItem();
}
if(ImGui::BeginTabItem("Core")) {
if(cpuSettings.render()) {
if(cpuSettings.getModified())
for (auto& [name, tab] : tabs) {
if (ImGui::BeginTabItem(name.c_str())) {
tab->render();
if (tab->modified && !applyEnabled)
applyEnabled = true;
}
ImGui::EndTabItem();
}
if(ImGui::BeginTabItem("Audio")) {
if(audioSettings.render()) {
if(audioSettings.getModified())
applyEnabled = true;
ImGui::EndTabItem();
}
ImGui::EndTabItem();
}
ImGui::EndTabBar();
@@ -65,6 +62,10 @@ bool SettingsWindow::render() {
if(ImGui::Button("Apply")) {
applyEnabled = false;
Options::GetInstance().Apply();
for (auto &tab : tabs | std::views::values) {
tab->modified = false;
}
}
ImGui::EndDisabled();