From 86ce199ac8c1c85a84d832fb576296ba2d3adfb5 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Sun, 22 Sep 2024 12:35:19 +0200 Subject: [PATCH] improve menus --- src/chat_gui/settings_window.cpp | 4 ++-- src/main_screen.cpp | 24 ++++++++++++++---------- src/main_screen.hpp | 1 + src/object_store_ui.cpp | 4 ++-- src/tox_dht_cap_histo.cpp | 4 ++-- src/tox_ui_utils.cpp | 8 ++++---- 6 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/chat_gui/settings_window.cpp b/src/chat_gui/settings_window.cpp index 2c987a78..b8d2173f 100644 --- a/src/chat_gui/settings_window.cpp +++ b/src/chat_gui/settings_window.cpp @@ -109,8 +109,8 @@ void SettingsWindow::render(void) { if (ImGui::BeginMenuBar()) { ImGui::Separator(); if (ImGui::BeginMenu("Settings")) { - if (ImGui::MenuItem("settings window")) { - _show_window = true; + if (ImGui::MenuItem("settings window", nullptr, _show_window)) { + _show_window = !_show_window; } ImGui::EndMenu(); } diff --git a/src/main_screen.cpp b/src/main_screen.cpp index d0f1c200..285f1a4e 100644 --- a/src/main_screen.cpp +++ b/src/main_screen.cpp @@ -284,20 +284,24 @@ Screen* MainScreen::render(float time_delta, bool&) { if (ImGui::BeginMenu("Settings")) { ImGui::SeparatorText("ImGui"); - if (ImGui::MenuItem("Style Editor")) { - _show_tool_style_editor = true; + if (ImGui::MenuItem("Style Editor", nullptr, _show_tool_style_editor)) { + _show_tool_style_editor = !_show_tool_style_editor; } - if (ImGui::MenuItem("Metrics")) { - _show_tool_metrics = true; + if (ImGui::MenuItem("Metrics", nullptr, _show_tool_metrics)) { + _show_tool_metrics = !_show_tool_metrics; } - if (ImGui::MenuItem("Debug Log")) { - _show_tool_debug_log = true; + if (ImGui::MenuItem("Debug Log", nullptr, _show_tool_debug_log)) { + _show_tool_debug_log = !_show_tool_debug_log; } - if (ImGui::MenuItem("ID Stack Tool")) { - _show_tool_id_stack = true; + if (ImGui::MenuItem("ID Stack Tool", nullptr, _show_tool_id_stack)) { + _show_tool_id_stack = !_show_tool_id_stack; + } + + if (ImGui::MenuItem("Demo", nullptr, _show_tool_demo)) { + _show_tool_demo = !_show_tool_demo; } ImGui::EndMenu(); @@ -328,8 +332,8 @@ Screen* MainScreen::render(float time_delta, bool&) { ImGui::ShowIDStackToolWindow(&_show_tool_id_stack); } - if constexpr (false) { - ImGui::ShowDemoWindow(); + if (_show_tool_demo) { + ImGui::ShowDemoWindow(&_show_tool_demo); } float tc_unfinished_queue_interval; diff --git a/src/main_screen.hpp b/src/main_screen.hpp index 2d469dc8..1aa5939d 100644 --- a/src/main_screen.hpp +++ b/src/main_screen.hpp @@ -95,6 +95,7 @@ struct MainScreen final : public Screen { bool _show_tool_metrics {false}; bool _show_tool_debug_log {false}; bool _show_tool_id_stack {false}; + bool _show_tool_demo {false}; bool _window_hidden {false}; uint64_t _window_hidden_ts {0}; diff --git a/src/object_store_ui.cpp b/src/object_store_ui.cpp index edf14c06..eeb895a8 100644 --- a/src/object_store_ui.cpp +++ b/src/object_store_ui.cpp @@ -118,8 +118,8 @@ void ObjectStoreUI::render(void) { if (ImGui::BeginMenuBar()) { ImGui::Separator(); if (ImGui::BeginMenu("ObjectStore")) { - if (ImGui::MenuItem("Inspector")) { - _ee.show_window = true; + if (ImGui::MenuItem("Inspector", nullptr, _ee.show_window)) { + _ee.show_window = !_ee.show_window; } ImGui::EndMenu(); } diff --git a/src/tox_dht_cap_histo.cpp b/src/tox_dht_cap_histo.cpp index e9cfc25f..e6233bca 100644 --- a/src/tox_dht_cap_histo.cpp +++ b/src/tox_dht_cap_histo.cpp @@ -38,8 +38,8 @@ void ToxDHTCapHisto::render(void) { ImGui::Checkbox("enabled", &_enabled); - if (ImGui::MenuItem("show DHT announce capability histogram")) { - _show_window = true; + if (ImGui::MenuItem("announce capability histogram", nullptr, _show_window)) { + _show_window = !_show_window; } ImGui::EndMenu(); diff --git a/src/tox_ui_utils.cpp b/src/tox_ui_utils.cpp index 06445aa6..b1bc3bd0 100644 --- a/src/tox_ui_utils.cpp +++ b/src/tox_ui_utils.cpp @@ -26,14 +26,14 @@ void ToxUIUtils::render(void) { if (ImGui::BeginMenu("Tox")) { ImGui::SeparatorText("Friends/Groups"); - if (ImGui::MenuItem("add Friend by ID")) { - _show_add_friend_window = true; + if (ImGui::MenuItem("add Friend by ID", nullptr, _show_add_friend_window)) { + _show_add_friend_window = !_show_add_friend_window; } if (ImGui::MenuItem("copy own ToxID")) { ImGui::SetClipboardText(_tc.toxSelfGetAddressStr().c_str()); } - if (ImGui::MenuItem("join Group by ID (ngc)")) { - _show_add_group_window = true; + if (ImGui::MenuItem("join Group by ID (ngc)", nullptr, _show_add_group_window)) { + _show_add_group_window = !_show_add_group_window; } ImGui::SeparatorText("DHT");