mirror of
https://github.com/Drezil/imgui.git
synced 2025-04-16 08:04:00 +00:00
Tweak BeginMenu() code
This commit is contained in:
parent
733e079081
commit
7847100ad8
19
imgui.cpp
19
imgui.cpp
@ -3104,15 +3104,6 @@ static void ClosePopupToLevel(int remaining)
|
|||||||
g.OpenedPopupStack.resize(remaining);
|
g.OpenedPopupStack.resize(remaining);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ClosePopup(const char* str_id) // not exposed because 'id' scope is misleading
|
|
||||||
{
|
|
||||||
ImGuiState& g = *GImGui;
|
|
||||||
ImGuiWindow* window = GetCurrentWindow();
|
|
||||||
const ImGuiID id = window->GetID(str_id);
|
|
||||||
if (IsPopupOpen(id))
|
|
||||||
ClosePopupToLevel((int)g.CurrentPopupStack.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close the popup we have begin-ed into.
|
// Close the popup we have begin-ed into.
|
||||||
void ImGui::CloseCurrentPopup()
|
void ImGui::CloseCurrentPopup()
|
||||||
{
|
{
|
||||||
@ -7690,7 +7681,7 @@ bool ImGui::BeginMenu(const char* label, bool enabled)
|
|||||||
if (menuset_opened)
|
if (menuset_opened)
|
||||||
g.FocusedWindow = backed_focused_window;
|
g.FocusedWindow = backed_focused_window;
|
||||||
|
|
||||||
bool want_open = false;
|
bool want_open = false, want_close = false;
|
||||||
if (window->Flags & (ImGuiWindowFlags_Popup|ImGuiWindowFlags_ChildMenu))
|
if (window->Flags & (ImGuiWindowFlags_Popup|ImGuiWindowFlags_ChildMenu))
|
||||||
{
|
{
|
||||||
// Implement http://bjk5.com/post/44698559168/breaking-down-amazons-mega-dropdown to avoid using timers so menus feel more reactive.
|
// Implement http://bjk5.com/post/44698559168/breaking-down-amazons-mega-dropdown to avoid using timers so menus feel more reactive.
|
||||||
@ -7712,18 +7703,20 @@ bool ImGui::BeginMenu(const char* label, bool enabled)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opened && !hovered && g.HoveredWindow == window && g.HoveredIdPreviousFrame != 0 && g.HoveredIdPreviousFrame != id && !moving_within_opened_triangle)
|
want_close = (opened && !hovered && g.HoveredWindow == window && g.HoveredIdPreviousFrame != 0 && g.HoveredIdPreviousFrame != id && !moving_within_opened_triangle);
|
||||||
ClosePopup(label);
|
|
||||||
want_open = (!opened && hovered && !moving_within_opened_triangle) || (!opened && hovered && pressed);
|
want_open = (!opened && hovered && !moving_within_opened_triangle) || (!opened && hovered && pressed);
|
||||||
}
|
}
|
||||||
else if (opened && pressed && menuset_opened) // menu-bar: click open menu to close
|
else if (opened && pressed && menuset_opened) // menu-bar: click open menu to close
|
||||||
{
|
{
|
||||||
ClosePopup(label);
|
want_close = true;
|
||||||
want_open = opened = false;
|
want_open = opened = false;
|
||||||
}
|
}
|
||||||
else if (pressed || (hovered && menuset_opened && !opened)) // menu-bar: first click to open, then hover to open others
|
else if (pressed || (hovered && menuset_opened && !opened)) // menu-bar: first click to open, then hover to open others
|
||||||
want_open = true;
|
want_open = true;
|
||||||
|
|
||||||
|
if (want_close && IsPopupOpen(id))
|
||||||
|
ClosePopupToLevel((int)GImGui->CurrentPopupStack.size());
|
||||||
|
|
||||||
if (!opened && want_open && g.OpenedPopupStack.size() > g.CurrentPopupStack.size())
|
if (!opened && want_open && g.OpenedPopupStack.size() > g.CurrentPopupStack.size())
|
||||||
{
|
{
|
||||||
// Don't recycle same menu level in the same frame, first close the other menu and yield for a frame.
|
// Don't recycle same menu level in the same frame, first close the other menu and yield for a frame.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user