logmeow/windows/settings.cpp

45 lines
1.8 KiB
C++

#include <imgui.h>
#include <imgui_stdlib.h>
#include "../misc.h"
#include "../config.h"
#include "../fragments/ok_buttons_fragment.h"
#include "settings.h"
static void try_write_config(const Config& config) {
try {
write_config(config);
} catch (const std::exception& e) {
log(std::string("Failed to write config: ") + e.what());
}
}
void settings_window(Config& __restrict active_config, Config& __restrict inactive_config, bool* p_open) {
if (!ImGui::BeginWithCloseShortcut("Settings", p_open)) {
ImGui::End();
return;
}
ImGui::TextUnformatted("Logcat command only takes effect when logcat is not running");
ImGui::InputTextWithHint("Logcat command", default_logcat_command, &inactive_config.logcat_command);
ImGui::TextWrapped("Font sizes only take effect when LogMeow is restarted (using non-integer values may cause spacing issues)");
#ifdef USE_FONTCONFIG
ImGui::InputFloat("Normal font size", &inactive_config.normal_font_size, 0.5f, 1.0f, "%.3f");
#endif
ImGui::InputFloat("Monospace font size", &inactive_config.monospace_font_size, 0.5f, 1.0f, "%.3f");
ImGui::Separator();
ok_buttons_fragment(p_open, [&]() {
active_config.logcat_command = std::move(inactive_config.logcat_command);
active_config.normal_font_size = inactive_config.normal_font_size;
active_config.monospace_font_size = inactive_config.monospace_font_size;
try_write_config(active_config);
}, [&]() {
active_config.logcat_command = inactive_config.logcat_command;
active_config.normal_font_size = inactive_config.normal_font_size;
active_config.monospace_font_size = inactive_config.monospace_font_size;
try_write_config(active_config);
});
ImGui::End();
}