mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-22 03:47:00 +00:00
Internals: rename legagy tab focus fields to TabFocusXXXX for clarity + removed one unnecessary FocusWindow() call.
This commit is contained in:
parent
d94644261d
commit
352f64697c
55
imgui.cpp
55
imgui.cpp
@ -3251,18 +3251,18 @@ bool ImGui::FocusableItemRegister(ImGuiWindow* window, ImGuiID id)
|
||||
|
||||
// Process TAB/Shift-TAB to tab *OUT* of the currently focused item.
|
||||
// (Note that we can always TAB out of a widget that doesn't allow tabbing in)
|
||||
if (g.ActiveId == id && g.FocusTabPressed && !IsActiveIdUsingKey(ImGuiKey_Tab) && g.FocusRequestNextWindow == NULL)
|
||||
if (g.ActiveId == id && g.TabFocusPressed && !IsActiveIdUsingKey(ImGuiKey_Tab) && g.TabFocusRequestNextWindow == NULL)
|
||||
{
|
||||
g.FocusRequestNextWindow = window;
|
||||
g.FocusRequestNextCounterTabStop = window->DC.FocusCounterTabStop + (g.IO.KeyShift ? (is_tab_stop ? -1 : 0) : +1); // Modulo on index will be applied at the end of frame once we've got the total counter of items.
|
||||
g.TabFocusRequestNextWindow = window;
|
||||
g.TabFocusRequestNextCounterTabStop = window->DC.FocusCounterTabStop + (g.IO.KeyShift ? (is_tab_stop ? -1 : 0) : +1); // Modulo on index will be applied at the end of frame once we've got the total counter of items.
|
||||
}
|
||||
|
||||
// Handle focus requests
|
||||
if (g.FocusRequestCurrWindow == window)
|
||||
if (g.TabFocusRequestCurrWindow == window)
|
||||
{
|
||||
if (window->DC.FocusCounterRegular == g.FocusRequestCurrCounterRegular)
|
||||
if (window->DC.FocusCounterRegular == g.TabFocusRequestCurrCounterRegular)
|
||||
return true;
|
||||
if (is_tab_stop && window->DC.FocusCounterTabStop == g.FocusRequestCurrCounterTabStop)
|
||||
if (is_tab_stop && window->DC.FocusCounterTabStop == g.TabFocusRequestCurrCounterTabStop)
|
||||
{
|
||||
g.NavJustTabbedId = id;
|
||||
return true;
|
||||
@ -3768,32 +3768,32 @@ void ImGui::UpdateTabFocus()
|
||||
ImGuiContext& g = *GImGui;
|
||||
|
||||
// Pressing TAB activate widget focus
|
||||
g.FocusTabPressed = (g.NavWindow && g.NavWindow->Active && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs) && !g.IO.KeyCtrl && IsKeyPressedMap(ImGuiKey_Tab));
|
||||
if (g.ActiveId == 0 && g.FocusTabPressed)
|
||||
g.TabFocusPressed = (g.NavWindow && g.NavWindow->Active && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs) && !g.IO.KeyCtrl && IsKeyPressedMap(ImGuiKey_Tab));
|
||||
if (g.ActiveId == 0 && g.TabFocusPressed)
|
||||
{
|
||||
// Note that SetKeyboardFocusHere() sets the Next fields mid-frame. To be consistent we also
|
||||
// manipulate the Next fields even, even though they will be turned into Curr fields by the code below.
|
||||
g.FocusRequestNextWindow = g.NavWindow;
|
||||
g.FocusRequestNextCounterRegular = INT_MAX;
|
||||
g.TabFocusRequestNextWindow = g.NavWindow;
|
||||
g.TabFocusRequestNextCounterRegular = INT_MAX;
|
||||
if (g.NavId != 0 && g.NavIdTabCounter != INT_MAX)
|
||||
g.FocusRequestNextCounterTabStop = g.NavIdTabCounter + 1 + (g.IO.KeyShift ? -1 : 1);
|
||||
g.TabFocusRequestNextCounterTabStop = g.NavIdTabCounter + 1 + (g.IO.KeyShift ? -1 : 1);
|
||||
else
|
||||
g.FocusRequestNextCounterTabStop = g.IO.KeyShift ? -1 : 0;
|
||||
g.TabFocusRequestNextCounterTabStop = g.IO.KeyShift ? -1 : 0;
|
||||
}
|
||||
|
||||
// Turn queued focus request into current one
|
||||
g.FocusRequestCurrWindow = NULL;
|
||||
g.FocusRequestCurrCounterRegular = g.FocusRequestCurrCounterTabStop = INT_MAX;
|
||||
if (g.FocusRequestNextWindow != NULL)
|
||||
g.TabFocusRequestCurrWindow = NULL;
|
||||
g.TabFocusRequestCurrCounterRegular = g.TabFocusRequestCurrCounterTabStop = INT_MAX;
|
||||
if (g.TabFocusRequestNextWindow != NULL)
|
||||
{
|
||||
ImGuiWindow* window = g.FocusRequestNextWindow;
|
||||
g.FocusRequestCurrWindow = window;
|
||||
if (g.FocusRequestNextCounterRegular != INT_MAX && window->DC.FocusCounterRegular != -1)
|
||||
g.FocusRequestCurrCounterRegular = ImModPositive(g.FocusRequestNextCounterRegular, window->DC.FocusCounterRegular + 1);
|
||||
if (g.FocusRequestNextCounterTabStop != INT_MAX && window->DC.FocusCounterTabStop != -1)
|
||||
g.FocusRequestCurrCounterTabStop = ImModPositive(g.FocusRequestNextCounterTabStop, window->DC.FocusCounterTabStop + 1);
|
||||
g.FocusRequestNextWindow = NULL;
|
||||
g.FocusRequestNextCounterRegular = g.FocusRequestNextCounterTabStop = INT_MAX;
|
||||
ImGuiWindow* window = g.TabFocusRequestNextWindow;
|
||||
g.TabFocusRequestCurrWindow = window;
|
||||
if (g.TabFocusRequestNextCounterRegular != INT_MAX && window->DC.FocusCounterRegular != -1)
|
||||
g.TabFocusRequestCurrCounterRegular = ImModPositive(g.TabFocusRequestNextCounterRegular, window->DC.FocusCounterRegular + 1);
|
||||
if (g.TabFocusRequestNextCounterTabStop != INT_MAX && window->DC.FocusCounterTabStop != -1)
|
||||
g.TabFocusRequestCurrCounterTabStop = ImModPositive(g.TabFocusRequestNextCounterTabStop, window->DC.FocusCounterTabStop + 1);
|
||||
g.TabFocusRequestNextWindow = NULL;
|
||||
g.TabFocusRequestNextCounterRegular = g.TabFocusRequestNextCounterTabStop = INT_MAX;
|
||||
}
|
||||
|
||||
g.NavIdTabCounter = INT_MAX;
|
||||
@ -5886,7 +5886,6 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
||||
{
|
||||
window->Collapsed = !window->Collapsed;
|
||||
MarkIniSettingsDirty(window);
|
||||
FocusWindow(window);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -6222,7 +6221,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
||||
if (want_focus)
|
||||
{
|
||||
FocusWindow(window);
|
||||
NavInitWindow(window, false);
|
||||
NavInitWindow(window, false); // <-- this is in the way for us to be able to defer and sort reappearing FocusWindow() calls
|
||||
}
|
||||
|
||||
// Title bar
|
||||
@ -6924,9 +6923,9 @@ void ImGui::SetKeyboardFocusHere(int offset)
|
||||
IM_ASSERT(offset >= -1); // -1 is allowed but not below
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* window = g.CurrentWindow;
|
||||
g.FocusRequestNextWindow = window;
|
||||
g.FocusRequestNextCounterRegular = window->DC.FocusCounterRegular + 1 + offset;
|
||||
g.FocusRequestNextCounterTabStop = INT_MAX;
|
||||
g.TabFocusRequestNextWindow = window;
|
||||
g.TabFocusRequestNextCounterRegular = window->DC.FocusCounterRegular + 1 + offset;
|
||||
g.TabFocusRequestNextCounterTabStop = INT_MAX;
|
||||
}
|
||||
|
||||
void ImGui::SetItemDefaultFocus()
|
||||
|
@ -1422,13 +1422,13 @@ struct ImGuiContext
|
||||
bool NavWindowingToggleLayer;
|
||||
|
||||
// Legacy Focus/Tabbing system (older than Nav, active even if Nav is disabled, misnamed. FIXME-NAV: This needs a redesign!)
|
||||
ImGuiWindow* FocusRequestCurrWindow; //
|
||||
ImGuiWindow* FocusRequestNextWindow; //
|
||||
int FocusRequestCurrCounterRegular; // Any item being requested for focus, stored as an index (we on layout to be stable between the frame pressing TAB and the next frame, semi-ouch)
|
||||
int FocusRequestCurrCounterTabStop; // Tab item being requested for focus, stored as an index
|
||||
int FocusRequestNextCounterRegular; // Stored for next frame
|
||||
int FocusRequestNextCounterTabStop; // "
|
||||
bool FocusTabPressed; //
|
||||
ImGuiWindow* TabFocusRequestCurrWindow; //
|
||||
ImGuiWindow* TabFocusRequestNextWindow; //
|
||||
int TabFocusRequestCurrCounterRegular; // Any item being requested for focus, stored as an index (we on layout to be stable between the frame pressing TAB and the next frame, semi-ouch)
|
||||
int TabFocusRequestCurrCounterTabStop; // Tab item being requested for focus, stored as an index
|
||||
int TabFocusRequestNextCounterRegular; // Stored for next frame
|
||||
int TabFocusRequestNextCounterTabStop; // "
|
||||
bool TabFocusPressed; //
|
||||
|
||||
// Render
|
||||
float DimBgRatio; // 0.0..1.0 animation when fading in a dimming background (for modal window and CTRL+TAB list)
|
||||
@ -1611,10 +1611,10 @@ struct ImGuiContext
|
||||
NavWindowingTimer = NavWindowingHighlightAlpha = 0.0f;
|
||||
NavWindowingToggleLayer = false;
|
||||
|
||||
FocusRequestCurrWindow = FocusRequestNextWindow = NULL;
|
||||
FocusRequestCurrCounterRegular = FocusRequestCurrCounterTabStop = INT_MAX;
|
||||
FocusRequestNextCounterRegular = FocusRequestNextCounterTabStop = INT_MAX;
|
||||
FocusTabPressed = false;
|
||||
TabFocusRequestCurrWindow = TabFocusRequestNextWindow = NULL;
|
||||
TabFocusRequestCurrCounterRegular = TabFocusRequestCurrCounterTabStop = INT_MAX;
|
||||
TabFocusRequestNextCounterRegular = TabFocusRequestNextCounterTabStop = INT_MAX;
|
||||
TabFocusPressed = false;
|
||||
|
||||
DimBgRatio = 0.0f;
|
||||
MouseCursor = ImGuiMouseCursor_Arrow;
|
||||
|
@ -3927,7 +3927,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
||||
ImGuiInputTextState* state = GetInputTextState(id);
|
||||
|
||||
const bool focus_requested = FocusableItemRegister(window, id);
|
||||
const bool focus_requested_by_code = focus_requested && (g.FocusRequestCurrWindow == window && g.FocusRequestCurrCounterRegular == window->DC.FocusCounterRegular);
|
||||
const bool focus_requested_by_code = focus_requested && (g.TabFocusRequestCurrWindow == window && g.TabFocusRequestCurrCounterRegular == window->DC.FocusCounterRegular);
|
||||
const bool focus_requested_by_tab = focus_requested && !focus_requested_by_code;
|
||||
|
||||
const bool user_clicked = hovered && io.MouseClicked[0];
|
||||
|
Loading…
Reference in New Issue
Block a user