Add Ctrl+W

This commit is contained in:
blankie 2023-02-04 14:31:50 +07:00
parent a6a53eb98a
commit e852ead133
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
11 changed files with 25 additions and 11 deletions

View File

@ -34,7 +34,7 @@ static inline void check_for_logcat_items(LogcatThread& logcat_thread, const Con
}
void event_loop(ImFont* monospace_font, Config& active_config, LogcatThread& logcat_thread, bool* run_event_loop) {
void event_loop(ImFont* monospace_font, Config& active_config, LogcatThread& logcat_thread) {
static Config inactive_config;
static bool show_settings_window = false;
static bool show_filters_window = false;
@ -73,5 +73,5 @@ void event_loop(ImFont* monospace_font, Config& active_config, LogcatThread& log
main_window(log_entries_read == log_entries.size(), monospace_font, logcat_thread,
logcat_entries, filtered_logcat_entry_offsets,
active_config, inactive_config,
&show_settings_window, &show_filters_window, &show_exclusions_window, &show_logs_window, run_event_loop);
&show_settings_window, &show_filters_window, &show_exclusions_window, &show_logs_window);
}

View File

@ -5,4 +5,4 @@
#include "config.h"
#include "logcat_thread.h"
void event_loop(ImFont* monospace_font, Config& active_config, LogcatThread& logcat_thread, bool* run_event_loop);
void event_loop(ImFont* monospace_font, Config& active_config, LogcatThread& logcat_thread);

View File

@ -162,7 +162,7 @@ int main(int, char**) {
ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame();
event_loop(monospace_font, config, logcat_thread, &run_event_loop);
event_loop(monospace_font, config, logcat_thread);
// Rendering
ImGui::Render();

View File

@ -2,6 +2,7 @@
#include <sstream>
#include <system_error>
#include <imgui.h>
#include <imgui_internal.h>
#include "misc.h"
@ -60,3 +61,12 @@ bool ImGui::Button(const char* label, bool enabled) {
}
return res;
}
bool ImGui::BeginWithCloseShortcut(const char* label, bool* p_open, ImGuiWindowFlags flags) {
bool res = ImGui::Begin(label, p_open, flags);
if (p_open && ImGui::Shortcut(ImGuiMod_Shortcut | ImGuiKey_W, 0, ImGuiInputFlags_Repeat)) {
*p_open = false;
}
return res;
}

1
misc.h
View File

@ -12,4 +12,5 @@ namespace ImGui {
void TextUnformatted(const std::string& str);
bool RedButton(const char* label);
bool Button(const char* label, bool enabled);
bool BeginWithCloseShortcut(const char* label, bool* p_open, ImGuiWindowFlags flags = 0);
}; // namespace ImGui

View File

@ -1,5 +1,6 @@
#include <imgui.h>
#include "../misc.h"
#include "../fragments/filters.h"
#include "../filters.h"
#include "../config.h"
@ -8,7 +9,7 @@
void exclusions_window(Config& active_config, Config& inactive_config,
const std::vector<LogcatEntry>& logcat_entries, std::vector<size_t>& filtered_logcat_entry_offsets,
bool* p_open) {
if (!ImGui::Begin("Exclusions", p_open)) {
if (!ImGui::BeginWithCloseShortcut("Exclusions", p_open)) {
ImGui::End();
return;
}

View File

@ -1,5 +1,6 @@
#include <imgui.h>
#include "../misc.h"
#include "../fragments/filters.h"
#include "../filters.h"
#include "../config.h"
@ -8,7 +9,7 @@
void filters_window(Config& active_config, Config& inactive_config,
const std::vector<LogcatEntry>& logcat_entries, std::vector<size_t>& filtered_logcat_entry_offsets,
bool* p_open) {
if (!ImGui::Begin("Filters", p_open)) {
if (!ImGui::BeginWithCloseShortcut("Filters", p_open)) {
ImGui::End();
return;
}

View File

@ -44,7 +44,7 @@ static inline void render_table(ImFont* monospace_font, bool* autoscrolling) {
}
void logs_window(ImFont* monospace_font, bool* autoscrolling, bool* p_open) {
if (!ImGui::Begin("LogMeow Logs", p_open)) {
if (!ImGui::BeginWithCloseShortcut("LogMeow Logs", p_open)) {
ImGui::End();
return;
}

View File

@ -57,11 +57,11 @@ static inline void render_table(ImFont* monospace_font, std::vector<LogcatEntry>
void main_window(bool latest_log_entries_read, ImFont* monospace_font, LogcatThread& logcat_thread,
std::vector<LogcatEntry>& logcat_entries, std::vector<size_t>& filtered_logcat_entry_offsets,
const Config& active_config, Config& inactive_config,
bool* show_settings_window, bool* show_filters_window, bool* show_exclusions_window, bool* show_logs_window, bool* run_event_loop) {
bool* show_settings_window, bool* show_filters_window, bool* show_exclusions_window, bool* show_logs_window) {
ImGui::SetNextWindowPos(ImGui::GetMainViewport()->WorkPos);
ImGui::SetNextWindowSize(ImGui::GetMainViewport()->WorkSize);
if (!ImGui::Begin("LogMeow", run_event_loop,
if (!ImGui::BeginWithCloseShortcut("LogMeow", nullptr,
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBringToFrontOnFocus)) {
ImGui::End();
return;

View File

@ -10,4 +10,4 @@
void main_window(bool latest_log_entries_read, ImFont* monospace_font, LogcatThread& logcat_thread,
std::vector<LogcatEntry>& logcat_entries, std::vector<size_t>& filtered_logcat_entry_offsets,
const Config& active_config, Config& inactive_config,
bool* show_settings_window, bool* show_filters_window, bool* show_exclusions_window, bool* show_logs_window, bool* run_event_loop);
bool* show_settings_window, bool* show_filters_window, bool* show_exclusions_window, bool* show_logs_window);

View File

@ -1,6 +1,7 @@
#include <imgui.h>
#include <imgui_stdlib.h>
#include "../misc.h"
#include "../config.h"
#include "settings.h"
@ -13,7 +14,7 @@ static void try_write_config(const Config& config) {
}
void settings_window(Config& active_config, Config& inactive_config, bool* p_open) {
if (!ImGui::Begin("Settings", p_open)) {
if (!ImGui::BeginWithCloseShortcut("Settings", p_open)) {
ImGui::End();
return;
}