Use OK/Canel/Apply buttons
This commit is contained in:
parent
1aa93dfea2
commit
c46c7778b6
6
config.h
6
config.h
|
@ -12,3 +12,9 @@ std::string get_config_folder();
|
||||||
void create_config_folders_if_necessary();
|
void create_config_folders_if_necessary();
|
||||||
Config load_config();
|
Config load_config();
|
||||||
void write_config(const Config& config);
|
void write_config(const Config& config);
|
||||||
|
|
||||||
|
constexpr bool operator!=(const Config& lhs, const Config& rhs) {
|
||||||
|
return lhs.logcat_command != rhs.logcat_command
|
||||||
|
|| lhs.normal_font_size != rhs.normal_font_size
|
||||||
|
|| lhs.monospace_font_size != rhs.monospace_font_size;
|
||||||
|
}
|
||||||
|
|
|
@ -11,15 +11,6 @@
|
||||||
#include "windows/debug.h"
|
#include "windows/debug.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static inline 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void check_for_logcat_items(LogcatThread& logcat_thread, std::vector<LogcatEntry>& filtered_logcat_entries) {
|
static inline void check_for_logcat_items(LogcatThread& logcat_thread, std::vector<LogcatEntry>& filtered_logcat_entries) {
|
||||||
LogcatThreadItem* logcat_thread_item;
|
LogcatThreadItem* logcat_thread_item;
|
||||||
|
|
||||||
|
@ -36,7 +27,8 @@ static inline void check_for_logcat_items(LogcatThread& logcat_thread, std::vect
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void event_loop(ImFont* monospace_font, Config& config, float* config_write_timer, LogcatThread& logcat_thread, bool* run_event_loop) {
|
void event_loop(ImFont* monospace_font, Config& active_config, LogcatThread& logcat_thread, bool* run_event_loop) {
|
||||||
|
static Config inactive_config;
|
||||||
static bool show_settings_window = false;
|
static bool show_settings_window = false;
|
||||||
static bool show_logs_window = false;
|
static bool show_logs_window = false;
|
||||||
static size_t log_entries_read = 0;
|
static size_t log_entries_read = 0;
|
||||||
|
@ -49,13 +41,7 @@ void event_loop(ImFont* monospace_font, Config& config, float* config_write_time
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (show_settings_window) {
|
if (show_settings_window) {
|
||||||
settings_window(config, config_write_timer, &show_settings_window);
|
settings_window(active_config, inactive_config, &show_settings_window);
|
||||||
}
|
|
||||||
if (*config_write_timer > 0.0f) {
|
|
||||||
*config_write_timer -= ImGui::GetIO().DeltaTime;
|
|
||||||
if (*config_write_timer <= 0.0f) {
|
|
||||||
write_config_and_update_structures(config);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (show_logs_window) {
|
if (show_logs_window) {
|
||||||
|
@ -67,5 +53,8 @@ void event_loop(ImFont* monospace_font, Config& config, float* config_write_time
|
||||||
}
|
}
|
||||||
|
|
||||||
// log_entries must not be mutated until the show logs button
|
// log_entries must not be mutated until the show logs button
|
||||||
main_window(log_entries_read == log_entries.size(), monospace_font, filtered_logcat_entries, &show_settings_window, &show_logs_window, run_event_loop);
|
main_window(log_entries_read == log_entries.size(),
|
||||||
|
monospace_font, filtered_logcat_entries,
|
||||||
|
active_config, inactive_config, &show_settings_window,
|
||||||
|
&show_logs_window, run_event_loop);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,4 +5,4 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "logcat_thread.h"
|
#include "logcat_thread.h"
|
||||||
|
|
||||||
void event_loop(ImFont* monospace_font, Config& config, float* config_write_timer, LogcatThread& logcat_thread, bool* run_event_loop);
|
void event_loop(ImFont* monospace_font, Config& active_config, LogcatThread& logcat_thread, bool* run_event_loop);
|
||||||
|
|
11
main.cpp
11
main.cpp
|
@ -131,7 +131,6 @@ int main(int, char**) {
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
bool run_event_loop = true;
|
bool run_event_loop = true;
|
||||||
float config_write_timer = 0.0f;
|
|
||||||
LogcatThread logcat_thread = [&]() {
|
LogcatThread logcat_thread = [&]() {
|
||||||
try {
|
try {
|
||||||
return LogcatThread();
|
return LogcatThread();
|
||||||
|
@ -162,7 +161,7 @@ int main(int, char**) {
|
||||||
ImGui_ImplSDL2_NewFrame();
|
ImGui_ImplSDL2_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
event_loop(monospace_font, config, &config_write_timer, logcat_thread, &run_event_loop);
|
event_loop(monospace_font, config, logcat_thread, &run_event_loop);
|
||||||
|
|
||||||
// Rendering
|
// Rendering
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
|
@ -182,14 +181,6 @@ int main(int, char**) {
|
||||||
SDL_DestroyWindow(window);
|
SDL_DestroyWindow(window);
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
|
||||||
if (config_write_timer > 0.0f) {
|
|
||||||
try {
|
|
||||||
write_config(config);
|
|
||||||
} catch (const std::exception& e) {
|
|
||||||
fprintf(stderr, "Failed to write config: %s\n", e.what());
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
logcat_thread.request_stop();
|
logcat_thread.request_stop();
|
||||||
logcat_thread.join();
|
logcat_thread.join();
|
||||||
|
|
||||||
|
|
|
@ -50,13 +50,14 @@ static inline void main_scrolling_region(ImFont* monospace_font, std::vector<Log
|
||||||
}
|
}
|
||||||
|
|
||||||
void main_window(bool latest_log_entries_read, ImFont* monospace_font, std::vector<LogcatEntry>& filtered_logcat_entries,
|
void main_window(bool latest_log_entries_read, ImFont* monospace_font, std::vector<LogcatEntry>& filtered_logcat_entries,
|
||||||
bool* show_settings_window, bool* show_logs_window, bool* run_event_loop) {
|
const Config& active_config, Config& inactive_config, bool* show_settings_window, bool* show_logs_window, bool* run_event_loop) {
|
||||||
if (!ImGui::Begin("LogMeow", run_event_loop)) {
|
if (!ImGui::Begin("LogMeow", run_event_loop)) {
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ImGui::Button("Settings")) {
|
if (ImGui::Button("Settings") && !*show_settings_window) {
|
||||||
|
inactive_config = active_config;
|
||||||
*show_settings_window = true;
|
*show_settings_window = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "../config.h"
|
||||||
#include "../logcat_entry.h"
|
#include "../logcat_entry.h"
|
||||||
|
|
||||||
void main_window(bool latest_log_entries_read, ImFont* monospace_font, std::vector<LogcatEntry>& filtered_logcat_entries,
|
void main_window(bool latest_log_entries_read, ImFont* monospace_font, std::vector<LogcatEntry>& filtered_logcat_entries,
|
||||||
bool* show_settings_window, bool* show_logs_window, bool* run_event_loop);
|
const Config& active_config, Config& inactive_config, bool* show_settings_window, bool* show_logs_window, bool* run_event_loop);
|
||||||
|
|
|
@ -4,24 +4,48 @@
|
||||||
#include "../config.h"
|
#include "../config.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
void settings_window(Config& config, float* config_write_timer, bool* p_open) {
|
static void write_config_and_update_structures(const Config& config) {
|
||||||
if (!ImGui::Begin("Settings", p_open)) {
|
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) {
|
||||||
|
ImGuiWindowFlags flags = active_config != inactive_config
|
||||||
|
? ImGuiWindowFlags_UnsavedDocument
|
||||||
|
: 0;
|
||||||
|
if (!ImGui::Begin("Settings", p_open, flags)) {
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// TODO actually have process control
|
// TODO actually have process control
|
||||||
ImGui::Text("Logcat command only takes effect when logcat is not running");
|
ImGui::Text("Logcat command only takes effect when logcat is not running");
|
||||||
if (ImGui::InputTextWithHint("Logcat command", "adb logcat -Dv 'threadtime UTC epoch usec uid'", &config.logcat_command)) {
|
ImGui::InputTextWithHint("Logcat command", "adb logcat -Dv 'threadtime UTC epoch usec uid'", &inactive_config.logcat_command);
|
||||||
*config_write_timer = *config_write_timer > 0.0f ? *config_write_timer : 5.0f;
|
|
||||||
}
|
|
||||||
ImGui::Text("Font sizes only take effect when LogMeow is restarted");
|
ImGui::Text("Font sizes only take effect when LogMeow is restarted");
|
||||||
#ifdef USE_FONTCONFIG
|
#ifdef USE_FONTCONFIG
|
||||||
if (ImGui::InputFloat("Normal font size", &config.normal_font_size, 0.5f, 1.0f, "%.3f")) {
|
ImGui::InputFloat("Normal font size", &inactive_config.normal_font_size, 0.5f, 1.0f, "%.3f");
|
||||||
*config_write_timer = *config_write_timer > 0.0f ? *config_write_timer : 5.0f;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
if (ImGui::InputFloat("Monospace font size", &config.monospace_font_size, 0.5f, 1.0f, "%.3f")) {
|
ImGui::InputFloat("Monospace font size", &inactive_config.monospace_font_size, 0.5f, 1.0f, "%.3f");
|
||||||
*config_write_timer = *config_write_timer > 0.0f ? *config_write_timer : 5.0f;
|
|
||||||
|
ImGui::Separator();
|
||||||
|
ImVec2 button_size(4 * ImGui::GetFontSize(), 0);
|
||||||
|
if (ImGui::Button("OK", button_size)) {
|
||||||
|
active_config = inactive_config;
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,4 +2,4 @@
|
||||||
|
|
||||||
#include "../config.h"
|
#include "../config.h"
|
||||||
|
|
||||||
void settings_window(Config& config, float* config_write_timer, bool* p_open);
|
void settings_window(Config& active_config, Config& inactive_config, bool* p_open);
|
||||||
|
|
Loading…
Reference in New Issue