logmeow/windows/settings.cpp

49 lines
1.6 KiB
C++
Raw Normal View History

2023-01-23 08:44:16 +00:00
#include <imgui.h>
#include <imgui_stdlib.h>
#include "../config.h"
#include "settings.h"
2023-01-24 05:17:05 +00:00
static void write_config_and_update_structures(const Config& config) {
try {
write_config(config);
} catch (const std::exception& e) {
log(std::string("Failed to write config: ") + e.what());
return;
}
}
void settings_window(Config& active_config, Config& inactive_config, bool* p_open) {
2023-01-28 14:11:46 +00:00
if (!ImGui::Begin("Settings", p_open)) {
2023-01-23 08:44:16 +00:00
ImGui::End();
return;
}
// TODO actually have process control
2023-01-28 14:11:46 +00:00
ImGui::TextUnformatted("Logcat command only takes effect when logcat is not running");
2023-01-24 05:17:05 +00:00
ImGui::InputTextWithHint("Logcat command", "adb logcat -Dv 'threadtime UTC epoch usec uid'", &inactive_config.logcat_command);
2023-01-23 08:44:16 +00:00
ImGui::Text("Font sizes only take effect when LogMeow is restarted");
#ifdef USE_FONTCONFIG
2023-01-24 05:17:05 +00:00
ImGui::InputFloat("Normal font size", &inactive_config.normal_font_size, 0.5f, 1.0f, "%.3f");
2023-01-23 08:44:16 +00:00
#endif
2023-01-24 05:17:05 +00:00
ImGui::InputFloat("Monospace font size", &inactive_config.monospace_font_size, 0.5f, 1.0f, "%.3f");
ImGui::Separator();
ImVec2 button_size(4 * ImGui::GetFontSize(), 0);
if (ImGui::Button("OK", button_size)) {
2023-01-28 14:11:46 +00:00
active_config = std::move(inactive_config);
2023-01-24 05:17:05 +00:00
write_config_and_update_structures(active_config);
*p_open = false;
}
ImGui::SameLine();
if (ImGui::Button("Cancel", button_size)) {
*p_open = false;
}
ImGui::SameLine();
if (ImGui::Button("Apply", button_size)) {
active_config = inactive_config;
write_config_and_update_structures(active_config);
2023-01-23 08:44:16 +00:00
}
ImGui::End();
}