feat(material): promote blur-overlay modal primitives (Phase 0a)
First step toward unifying all app modals on the Manage-Portfolio visual style. Add, as shared material:: helpers (additive — no caller yet, no visible change): - blur-overlay open refcount + 1-frame latch (Push/Pop/AnyBlurOverlayActive[LastFrame], LatchBlurOverlayActive) so App::render's effect guard can be modal-agnostic; - capture-frame query (IsCapturingBlurBackdrop) for scroll-fade suppression; - RightAlignX and SegmentedControl (promoted verbatim from market_tab); - BeginFadeScrollChild/EndFadeScrollChild in a dedicated overlay_scroll.h (kept out of the widely-included draw_helpers.h because effects::ScrollFadeShader's GL headers clash with SDL's in some TUs). Also fix IsCurrentWindowOverlayDialog to prefix-match "##OverlayScrim" so suffixed overlay windows are recognized by the modal-aware hover check. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -114,7 +114,9 @@ inline bool IsCurrentWindowOverlayDialog()
|
||||
{
|
||||
ImGuiWindow* window = ImGui::GetCurrentWindow();
|
||||
for (ImGuiWindow* node = window; node; node = node->ParentWindow) {
|
||||
if (node->Name && strcmp(node->Name, "##OverlayScrim") == 0)
|
||||
// Prefix match so both "##OverlayScrim" and suffixed "##OverlayScrim_<id>" blur overlays
|
||||
// (used by nested dialogs and the unified blur-overlay framework) are recognized.
|
||||
if (node->Name && strncmp(node->Name, "##OverlayScrim", 14) == 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -1027,6 +1029,75 @@ inline bool DrawDialogTitleBar(const char* title, bool* p_open, ImU32 accent_col
|
||||
return closeClicked;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Blur-backdrop modal primitives
|
||||
// ============================================================================
|
||||
// Shared building blocks for the "Manage Portfolio"-style overlay (live-blur backdrop, floating
|
||||
// content, segmented section nav, edge-fade scroll). Promoted verbatim from the Market tab so every
|
||||
// modal can adopt the same look. The overlay begin/end (below) drives these.
|
||||
|
||||
// Refcount of open blur-backdrop overlays (nesting-safe) + a 1-frame latch. App::render builds its
|
||||
// effect-suppression guard at the TOP of the frame, before dialogs dispatch, so it must read a
|
||||
// stable "was any blur overlay up last frame" signal rather than this frame's in-progress count.
|
||||
inline int& BlurOverlayOpenCountRef() { static int n = 0; return n; }
|
||||
inline bool& BlurOverlayActiveLastFrameRef() { static bool v = false; return v; }
|
||||
inline void PushBlurOverlayOpen() { ++BlurOverlayOpenCountRef(); }
|
||||
inline void PopBlurOverlayOpen() { if (BlurOverlayOpenCountRef() > 0) --BlurOverlayOpenCountRef(); }
|
||||
inline bool AnyBlurOverlayActive() { return BlurOverlayOpenCountRef() > 0; }
|
||||
inline bool AnyBlurOverlayActiveLastFrame() { return BlurOverlayActiveLastFrameRef(); }
|
||||
// Latch this frame's state for the next frame's guard. Call once at the end of App::render.
|
||||
inline void LatchBlurOverlayActive() { BlurOverlayActiveLastFrameRef() = AnyBlurOverlayActive(); }
|
||||
|
||||
// True during the frames a blur overlay is (re)capturing the live backdrop — the scroll-fade shader
|
||||
// is suppressed then, since the acrylic capture rebinds render state on those frames.
|
||||
inline bool& CapturingBlurBackdropRef() { static bool v = false; return v; }
|
||||
inline bool IsCapturingBlurBackdrop() { return CapturingBlurBackdropRef(); }
|
||||
|
||||
// Right-align the next item(s) of total width `w` within the remaining content region (cursor form).
|
||||
inline void RightAlignX(float w)
|
||||
{
|
||||
float avail = ImGui::GetContentRegionAvail().x;
|
||||
if (avail > w) ImGui::SetCursorPosX(ImGui::GetCursorPosX() + avail - w);
|
||||
}
|
||||
|
||||
// Equal-width segmented control (rounded track + N cells, each a centered label + an active pill) at
|
||||
// screen-space `origin`, spanning `totalW` x `height`. Each cell is a hit-tested InvisibleButton
|
||||
// (Hand cursor on hover), disambiguated by `idBase`. Does NOT move the layout cursor. Returns the
|
||||
// clicked cell index, or -1.
|
||||
inline int SegmentedControl(ImDrawList* dl, ImVec2 origin, float totalW, float height,
|
||||
const char* const* labels, int count, int selected,
|
||||
ImFont* font, const char* idBase, float dp)
|
||||
{
|
||||
int clicked = -1;
|
||||
float cellW = totalW / (float)count;
|
||||
dl->AddRectFilled(origin, ImVec2(origin.x + totalW, origin.y + height),
|
||||
WithAlpha(OnSurface(), 20), height * 0.5f);
|
||||
for (int i = 0; i < count; i++) {
|
||||
ImVec2 cMin(origin.x + i * cellW, origin.y), cMax(cMin.x + cellW, origin.y + height);
|
||||
bool active = (selected == i);
|
||||
bool hov = ImGui::IsMouseHoveringRect(cMin, cMax);
|
||||
if (active)
|
||||
dl->AddRectFilled(ImVec2(cMin.x + 2.0f * dp, cMin.y + 2.0f * dp),
|
||||
ImVec2(cMax.x - 2.0f * dp, cMax.y - 2.0f * dp),
|
||||
WithAlpha(Primary(), 210), (height - 4.0f * dp) * 0.5f);
|
||||
ImVec2 ts = font->CalcTextSizeA(font->LegacySize, FLT_MAX, 0, labels[i]);
|
||||
dl->AddText(font, font->LegacySize,
|
||||
ImVec2(cMin.x + (cellW - ts.x) * 0.5f, cMin.y + (height - ts.y) * 0.5f),
|
||||
active ? IM_COL32(255, 255, 255, 255) : (hov ? OnSurface() : OnSurfaceMedium()),
|
||||
labels[i]);
|
||||
ImGui::PushID(i);
|
||||
ImGui::SetCursorScreenPos(cMin);
|
||||
if (ImGui::InvisibleButton(idBase, ImVec2(cellW, height))) clicked = i;
|
||||
if (ImGui::IsItemHovered()) ImGui::SetMouseCursor(ImGuiMouseCursor_Hand);
|
||||
ImGui::PopID();
|
||||
}
|
||||
return clicked;
|
||||
}
|
||||
|
||||
// The edge-fade scroll child (BeginFadeScrollChild/EndFadeScrollChild) depends on
|
||||
// effects::ScrollFadeShader, whose GL/DX headers must not be pulled into this widely-included base
|
||||
// header — it lives in material/overlay_scroll.h, included only by modal implementations.
|
||||
|
||||
// ============================================================================
|
||||
// Fullscreen Overlay Dialog
|
||||
// ============================================================================
|
||||
|
||||
Reference in New Issue
Block a user