Add material::Tooltip / BeginTooltip / EndTooltip wrappers (tooltip_style.h) that scope a small window padding (8x4, dpi-scaled) and ~85% opacity to tooltips only, then route the tooltip call sites through them. Menus and combo dropdowns are untouched (they keep the global opaque PopupBg). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
67 lines
2.0 KiB
C++
67 lines
2.0 KiB
C++
// DragonX Wallet - ImGui Edition
|
|
// Copyright 2024-2026 The Hush Developers
|
|
// Released under the GPLv3
|
|
//
|
|
// App-wide tooltip styling: a compact (small padding) and slightly-translucent tooltip. ImGui has
|
|
// no tooltip-specific padding (tooltips inherit WindowPadding, shared with every window) and PopupBg
|
|
// is shared with menus/combos, so we can't restyle tooltips via the global style without side
|
|
// effects. Instead, every tooltip goes through these wrappers, which scope the style to the tooltip:
|
|
// dragonx::ui::material::Tooltip("fmt", ...); // replaces ImGui::SetTooltip
|
|
// if (material::BeginTooltip()) { ...; material::EndTooltip(); } // replaces ImGui::Begin/EndTooltip
|
|
|
|
#pragma once
|
|
|
|
#include <cstdarg>
|
|
|
|
#include "imgui.h"
|
|
#include "../layout.h"
|
|
|
|
namespace dragonx {
|
|
namespace ui {
|
|
namespace material {
|
|
|
|
// Scope tooltip-only styling: small padding + a slightly-transparent background.
|
|
inline void PushTooltipStyle()
|
|
{
|
|
const float s = Layout::dpiScale();
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(8.0f * s, 4.0f * s));
|
|
ImVec4 bg = ImGui::GetStyle().Colors[ImGuiCol_PopupBg];
|
|
bg.w = 0.85f; // slightly transparent (the global PopupBg is ~0.98 opaque)
|
|
ImGui::PushStyleColor(ImGuiCol_PopupBg, bg);
|
|
}
|
|
|
|
inline void PopTooltipStyle()
|
|
{
|
|
ImGui::PopStyleColor();
|
|
ImGui::PopStyleVar();
|
|
}
|
|
|
|
// Drop-in replacement for ImGui::SetTooltip (same printf-style signature). (No IM_FMTARGS: GCC
|
|
// rejects the format attribute on an inline definition; call sites already passed SetTooltip's check.)
|
|
inline void Tooltip(const char* fmt, ...)
|
|
{
|
|
PushTooltipStyle();
|
|
va_list args;
|
|
va_start(args, fmt);
|
|
ImGui::SetTooltipV(fmt, args);
|
|
va_end(args);
|
|
PopTooltipStyle();
|
|
}
|
|
|
|
// Drop-in replacements for ImGui::BeginTooltip / ImGui::EndTooltip (must be paired, as before).
|
|
inline bool BeginTooltip()
|
|
{
|
|
PushTooltipStyle();
|
|
return ImGui::BeginTooltip();
|
|
}
|
|
|
|
inline void EndTooltip()
|
|
{
|
|
ImGui::EndTooltip();
|
|
PopTooltipStyle();
|
|
}
|
|
|
|
} // namespace material
|
|
} // namespace ui
|
|
} // namespace dragonx
|