1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-09-24 03:28:33 +02:00

Nav: Internals: Renamed SetActiveIDNoNav -> SetActiveID() and old SetActiveID() -> SetFocusID(), both functions needs to be called when both are desirabled. (#787)

May break code relying on imgui_internal.h, relying on nav and not calling ButtonBehavior().
This commit is contained in:
omar 2017-10-13 13:23:21 +02:00
parent 8b095e483b
commit 0371219222
2 changed files with 23 additions and 23 deletions

View File

@ -1960,7 +1960,7 @@ static void SetNavIDAndMoveMouse(ImGuiID id, int nav_layer, const ImRect& rect_r
g.NavDisableMouseHover = true;
}
void ImGui::SetActiveIDNoNav(ImGuiID id, ImGuiWindow* window)
void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window)
{
ImGuiContext& g = *GImGui;
g.ActiveIdIsJustActivated = (g.ActiveId != id);
@ -1975,22 +1975,18 @@ void ImGui::SetActiveIDNoNav(ImGuiID id, ImGuiWindow* window)
}
}
void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window)
// Assume that SetFocusID() is called in the context where its NavLayer is the current window nav layer.
void ImGui::SetFocusID(ImGuiID id, ImGuiWindow* window)
{
IM_ASSERT(id != 0);
ImGuiContext& g = *GImGui;
SetActiveIDNoNav(id, window);
if (id)
{
g.NavId = id;
// Assume that SetActiveID() is called in the context where its NavLayer is the current layer, which is the case everywhere we call it.
g.NavLayer = window->DC.NavLayerCurrent;
window->NavLastIds[window->DC.NavLayerCurrent] = id;
if (g.ActiveIdSource == ImGuiInputSource_Nav)
g.NavDisableMouseHover = true;
else
g.NavDisableHighlight = true;
}
g.NavId = id;
g.NavLayer = window->DC.NavLayerCurrent;
window->NavLastIds[window->DC.NavLayerCurrent] = id;
if (g.ActiveIdSource == ImGuiInputSource_Nav)
g.NavDisableMouseHover = true;
else
g.NavDisableHighlight = true;
}
void ImGui::ClearActiveID()
@ -3535,7 +3531,7 @@ void ImGui::EndFrame()
{
g.MovedWindow = g.HoveredWindow;
g.MovedWindowMoveId = g.HoveredWindow->MoveId;
SetActiveIDNoNav(g.MovedWindowMoveId, g.HoveredRootWindow);
SetActiveID(g.MovedWindowMoveId, g.HoveredRootWindow);
}
}
else if (g.NavWindow != NULL && GetFrontMostModalRootWindow() == NULL)
@ -4616,7 +4612,7 @@ static bool BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, b
{
ImGui::FocusWindow(child_window);
NavInitWindow(child_window, false);
ImGui::SetActiveIDNoNav(id+1, child_window); // Steal ActiveId with a dummy id so that key-press won't activate child item
ImGui::SetActiveID(id+1, child_window); // Steal ActiveId with a dummy id so that key-press won't activate child item
g.ActiveIdSource = ImGuiInputSource_Nav;
}
@ -6718,10 +6714,9 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
// FIXME-NAVIGATION: We don't honor those different behaviors.
if ((flags & ImGuiButtonFlags_PressedOnClickRelease) && g.IO.MouseClicked[0])
{
if (flags & ImGuiButtonFlags_NoNavOverride)
SetActiveIDNoNav(id, window);
else
SetActiveID(id, window); // Hold on ID
SetActiveID(id, window);
if (!(flags & ImGuiButtonFlags_NoNavOverride))
SetFocusID(id, window);
FocusWindow(window);
g.ActiveIdClickOffset = g.IO.MousePos - bb.Min;
}
@ -6764,6 +6759,7 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
// Set active id so it can be queried by user via IsItemActive(), equivalent of holding the mouse button.
g.NavActivateId = id; // This is so SetActiveId assign a Nav source
SetActiveID(id, window);
SetFocusID(id, window);
g.ActiveIdAllowNavDirFlags = (1 << ImGuiDir_Left) | (1 << ImGuiDir_Right) | (1 << ImGuiDir_Up) | (1 << ImGuiDir_Down);
}
}
@ -7607,7 +7603,7 @@ bool ImGui::InputScalarAsWidgetReplacement(const ImRect& aabb, const char* label
// Our replacement widget will override the focus ID (registered previously to allow for a TAB focus to happen)
// On the first frame, g.ScalarAsInputTextId == 0, then on subsequent frames it becomes == id
SetActiveIDNoNav(g.ScalarAsInputTextId, window);
SetActiveID(g.ScalarAsInputTextId, window);
g.ActiveIdAllowNavDirFlags = (1 << ImGuiDir_Up) | (1 << ImGuiDir_Down);
SetHoveredID(0);
FocusableItemUnregister(window);
@ -7876,6 +7872,7 @@ bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, c
if (tab_focus_requested || (hovered && g.IO.MouseClicked[0]) || g.NavActivateId == id || g.NavInputId == id)
{
SetActiveID(id, window);
SetFocusID(id, window);
FocusWindow(window);
if (tab_focus_requested || g.IO.KeyCtrl || g.NavInputId == id)
{
@ -7927,6 +7924,7 @@ bool ImGui::VSliderFloat(const char* label, const ImVec2& size, float* v, float
if ((hovered && g.IO.MouseClicked[0]) || g.NavActivateId == id || g.NavInputId == id)
{
SetActiveID(id, window);
SetFocusID(id, window);
FocusWindow(window);
}
@ -8177,6 +8175,7 @@ bool ImGui::DragFloat(const char* label, float* v, float v_speed, float v_min, f
if (tab_focus_requested || (hovered && (g.IO.MouseClicked[0] || g.IO.MouseDoubleClicked[0])) || g.NavActivateId == id || g.NavInputId == id)
{
SetActiveID(id, window);
SetFocusID(id, window);
FocusWindow(window);
if (tab_focus_requested || g.IO.KeyCtrl || g.IO.MouseDoubleClicked[0] || g.NavInputId == id)
{
@ -9032,6 +9031,7 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2
select_all = true;
}
SetActiveID(id, window);
SetFocusID(id, window);
FocusWindow(window);
if (!is_multiline)
g.ActiveIdAllowNavDirFlags = ((1 << ImGuiDir_Up) | (1 << ImGuiDir_Down));

View File

@ -865,7 +865,7 @@ namespace ImGui
IMGUI_API void EndFrame(); // Ends the ImGui frame. Automatically called by Render()! you most likely don't need to ever call that yourself directly. If you don't need to render you can call EndFrame() but you'll have wasted CPU already. If you don't need to render, don't create any windows instead!
IMGUI_API void SetActiveID(ImGuiID id, ImGuiWindow* window);
IMGUI_API void SetActiveIDNoNav(ImGuiID id, ImGuiWindow* window);
IMGUI_API void SetFocusID(ImGuiID id, ImGuiWindow* window);
IMGUI_API void ClearActiveID();
IMGUI_API void SetHoveredID(ImGuiID id);
IMGUI_API void KeepAliveID(ImGuiID id);