1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-11-28 01:20:55 +01:00

Disabled: clicking a disabled item focuses parent window. (#8064)

This commit is contained in:
ocornut 2024-10-16 20:23:33 +02:00
parent 67e5f3505d
commit 83ecc846dc
3 changed files with 18 additions and 4 deletions

View File

@ -74,6 +74,7 @@ Other changes:
window. (#3200) window. (#3200)
- Nav: rectangle highlight not rendered for items with ImGuiItemFlags_NoNav. Can be relevant - Nav: rectangle highlight not rendered for items with ImGuiItemFlags_NoNav. Can be relevant
when e.g activating the item with mouse, then Ctrl+Tabbing back and forth. when e.g activating the item with mouse, then Ctrl+Tabbing back and forth.
- Disabled: clicking a disabled item focuses parent window. (#8064)
- InvisibleButton, Nav: fixed an issue when InvisibleButton() would be navigable into but - InvisibleButton, Nav: fixed an issue when InvisibleButton() would be navigable into but
not display navigation highlight. Properly navigation on it by default. (#8057) not display navigation highlight. Properly navigation on it by default. (#8057)
- InvisibleButton: added ImGuiButtonFlags_EnableNav to enable navigation. (#8057) - InvisibleButton: added ImGuiButtonFlags_EnableNav to enable navigation. (#8057)

View File

@ -29,7 +29,7 @@
// Library Version // Library Version
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM >= 12345') // (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM >= 12345')
#define IMGUI_VERSION "1.91.4 WIP" #define IMGUI_VERSION "1.91.4 WIP"
#define IMGUI_VERSION_NUM 19134 #define IMGUI_VERSION_NUM 19135
#define IMGUI_HAS_TABLE #define IMGUI_HAS_TABLE
/* /*

View File

@ -542,7 +542,8 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
// Mouse handling // Mouse handling
const ImGuiID test_owner_id = (flags & ImGuiButtonFlags_NoTestKeyOwner) ? ImGuiKeyOwner_Any : id; const ImGuiID test_owner_id = (flags & ImGuiButtonFlags_NoTestKeyOwner) ? ImGuiKeyOwner_Any : id;
if (hovered) const bool hovered_disabled = (g.HoveredId == id && g.HoveredIdIsDisabled);
if (hovered || hovered_disabled)
{ {
IM_ASSERT(id != 0); // Lazily check inside rare path. IM_ASSERT(id != 0); // Lazily check inside rare path.
@ -559,7 +560,8 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
} }
// Process initial action // Process initial action
if (!(flags & ImGuiButtonFlags_NoKeyModsAllowed) || (!g.IO.KeyCtrl && !g.IO.KeyShift && !g.IO.KeyAlt)) const bool mods_ok = !(flags & ImGuiButtonFlags_NoKeyModsAllowed) || (!g.IO.KeyCtrl && !g.IO.KeyShift && !g.IO.KeyAlt);
if (mods_ok && !hovered_disabled)
{ {
if (mouse_button_clicked != -1 && g.ActiveId != id) if (mouse_button_clicked != -1 && g.ActiveId != id)
{ {
@ -606,7 +608,7 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
if (!has_repeated_at_least_once) if (!has_repeated_at_least_once)
pressed = true; pressed = true;
if (!(flags & ImGuiButtonFlags_NoNavFocus)) if (!(flags & ImGuiButtonFlags_NoNavFocus))
SetFocusID(id, window); SetFocusID(id, window); // FIXME: Lack of FocusWindow() call here is inconsistent with other paths. Research why.
ClearActiveID(); ClearActiveID();
} }
} }
@ -617,6 +619,17 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
if (g.IO.MouseDownDuration[g.ActiveIdMouseButton] > 0.0f && IsMouseClicked(g.ActiveIdMouseButton, ImGuiInputFlags_Repeat, test_owner_id)) if (g.IO.MouseDownDuration[g.ActiveIdMouseButton] > 0.0f && IsMouseClicked(g.ActiveIdMouseButton, ImGuiInputFlags_Repeat, test_owner_id))
pressed = true; pressed = true;
} }
else if (mods_ok && hovered_disabled)
{
if (mouse_button_clicked != -1 && g.ActiveId != id)
{
// Disabled path still focus
// FIXME-NAV: Could somehow call SetNavID() with a null ID but mouse pos as NavRectRel so nav may be resumed?
// Will do it once we do it for regular click on window-void.
if (flags & (ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnClickReleaseAnywhere | ImGuiButtonFlags_PressedOnClick | ImGuiButtonFlags_PressedOnDoubleClick))
FocusWindow(window, ImGuiFocusRequestFlags_RestoreFocusedChild);
}
}
if (pressed) if (pressed)
g.NavDisableHighlight = true; g.NavDisableHighlight = true;