logmeow/windows/settings.cpp

72 lines
2.7 KiB
C++
Raw Normal View History

#include <imgui/imgui.h>
#include <imgui/misc/cpp/imgui_stdlib.h>
2023-01-23 08:44:16 +00:00
2023-02-04 07:31:50 +00:00
#include "../misc.h"
2023-01-23 08:44:16 +00:00
#include "../config.h"
#include "../fragments/filters.h"
2023-02-11 15:15:21 +00:00
#include "../fragments/ok_buttons_fragment.h"
2023-01-23 08:44:16 +00:00
#include "settings.h"
static void try_write_config(const Config& config) {
2023-01-24 05:17:05 +00:00
try {
write_config(config);
} catch (const std::exception& e) {
log(std::string("Failed to write config: ") + e.what());
}
}
static inline void settings_fragment(ImFont* monospace_font, Config& inactive_config) {
2023-01-28 14:11:46 +00:00
ImGui::TextUnformatted("Logcat command only takes effect when logcat is not running");
ImGui::PushFont(monospace_font);
ImGui::InputTextWithHint("##logcat_command", default_logcat_command, &inactive_config.logcat_command);
ImGui::PopFont();
ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);
ImGui::TextUnformatted("Logcat command");
2023-01-24 05:17:05 +00:00
2023-02-05 06:51:00 +00:00
ImGui::TextWrapped("Font sizes only take effect when LogMeow is restarted (using non-integer values may cause spacing issues)");
2023-01-23 08:44:16 +00:00
#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");
}
void settings_window(ImFont* monospace_font, Config& __restrict active_config, Config& __restrict inactive_config,
2023-03-29 10:08:31 +00:00
LogcatEntries& logcat_entries, bool* p_open) {
if (!ImGui::BeginWithCloseShortcut("Settings", p_open)) {
ImGui::End();
return;
}
if (ImGui::BeginTabBar("settings")) {
if (ImGui::BeginTabItem("Settings")) {
settings_fragment(monospace_font, inactive_config);
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Filters")) {
filters_fragment(inactive_config.filters);
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Exclusions")) {
filters_fragment(inactive_config.exclusions);
ImGui::EndTabItem();
}
ImGui::EndTabBar();
}
2023-01-24 05:17:05 +00:00
ImGui::Separator();
2023-02-11 15:15:21 +00:00
ok_buttons_fragment(p_open, [&]() {
active_config = std::move(inactive_config);
2023-03-29 10:08:31 +00:00
logcat_entries.refresh();
try_write_config(active_config);
2023-02-11 15:15:21 +00:00
}, [&]() {
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;
copy_filters(active_config.filters, inactive_config.filters);
copy_filters(active_config.exclusions, inactive_config.exclusions);
2023-03-29 10:08:31 +00:00
logcat_entries.refresh();
try_write_config(active_config);
2023-02-11 15:15:21 +00:00
});
2023-01-23 08:44:16 +00:00
ImGui::End();
}