From dfb8d930379b6147ab2cd51a3ee40b05dcbb8bdd Mon Sep 17 00:00:00 2001 From: Aang23 Date: Sun, 25 Jan 2026 10:24:19 +0100 Subject: [PATCH] Tooltips on icons --- src-core/common/widgets/menuitem_tooltip.cpp | 16 ++++++++++++++ src-core/common/widgets/menuitem_tooltip.h | 21 +++++++++++++++++++ .../dsp/flowgraph/dsp_flowgraph_handler.cpp | 11 +++++----- 3 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 src-core/common/widgets/menuitem_tooltip.cpp create mode 100644 src-core/common/widgets/menuitem_tooltip.h diff --git a/src-core/common/widgets/menuitem_tooltip.cpp b/src-core/common/widgets/menuitem_tooltip.cpp new file mode 100644 index 000000000..e7ecfb3af --- /dev/null +++ b/src-core/common/widgets/menuitem_tooltip.cpp @@ -0,0 +1,16 @@ +#include "menuitem_tooltip.h" +#include "imgui/imgui.h" + +namespace satdump +{ + namespace widgets + { + bool MenuItemTooltip(const char *label, const char *tooltip, const char *shortcut, bool selected, bool enabled) + { + bool v = ImGui::MenuItem(label, shortcut, selected, enabled); + if (ImGui::IsItemHovered()) + ImGui::SetTooltip(tooltip); + return v; + } + } // namespace widgets +} // namespace satdump \ No newline at end of file diff --git a/src-core/common/widgets/menuitem_tooltip.h b/src-core/common/widgets/menuitem_tooltip.h new file mode 100644 index 000000000..d683ed950 --- /dev/null +++ b/src-core/common/widgets/menuitem_tooltip.h @@ -0,0 +1,21 @@ +#pragma once + +/** + * @file menuitem_tooltip.h + */ + +namespace satdump +{ + namespace widgets + { + /** + * @brief Just an ImGui::MenuItem, but with a built-in tooltip when hovered + * @param label See ImGui + * @param tooltip Tooltip string + * @param shortcut See ImGui + * @param selected See ImGui + * @param enabled See ImGui + */ + bool MenuItemTooltip(const char *label, const char *tooltip, const char *shortcut = __null, bool selected = false, bool enabled = true); + } // namespace widgets +} // namespace satdump \ No newline at end of file diff --git a/src-core/dsp/flowgraph/dsp_flowgraph_handler.cpp b/src-core/dsp/flowgraph/dsp_flowgraph_handler.cpp index 4cf562bc2..9ff8f5271 100644 --- a/src-core/dsp/flowgraph/dsp_flowgraph_handler.cpp +++ b/src-core/dsp/flowgraph/dsp_flowgraph_handler.cpp @@ -1,4 +1,5 @@ #include "dsp_flowgraph_handler.h" +#include "common/widgets/menuitem_tooltip.h" #include "core/backend.h" #include "dsp/flowgraph/dsp_flowgraph_register.h" @@ -71,12 +72,12 @@ namespace satdump if (running) { - if (ImGui::MenuItem("\ufc62")) + if (widgets::MenuItemTooltip("\ufc62", "Stop flowgraph")) flowgraph.stop(); } else { - if (ImGui::MenuItem("\uf909")) + if (widgets::MenuItemTooltip("\uf909", "Start flowgraph")) { if (flow_thread.joinable()) flow_thread.join(); @@ -86,8 +87,8 @@ namespace satdump } bool is_save_as = false; - if (ImGui::MenuItem("\ueb4b", NULL, false, current_file != "") || // - (is_save_as = ImGui::MenuItem("\ueb4a")) || // + if (widgets::MenuItemTooltip("\ueb4b", "Save file", NULL, false, current_file != "") || // + (is_save_as = widgets::MenuItemTooltip("\ueb4a", "Save file as")) || // (ImGui::IsKeyDown(ImGuiKey_ReservedForModCtrl) && ImGui::IsKeyPressed(ImGuiKey_S))) { auto fun = [this, is_save_as]() @@ -104,7 +105,7 @@ namespace satdump tq.push(fun); } - if (ImGui::MenuItem("\uea7f")) + if (widgets::MenuItemTooltip("\uea7f", "Load a file")) { auto fun = [this]() {