mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-22 11:57: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.
|
// 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)
|
// (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.TabFocusRequestNextWindow = 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.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
|
// 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;
|
return true;
|
||||||
if (is_tab_stop && window->DC.FocusCounterTabStop == g.FocusRequestCurrCounterTabStop)
|
if (is_tab_stop && window->DC.FocusCounterTabStop == g.TabFocusRequestCurrCounterTabStop)
|
||||||
{
|
{
|
||||||
g.NavJustTabbedId = id;
|
g.NavJustTabbedId = id;
|
||||||
return true;
|
return true;
|
||||||
@ -3768,32 +3768,32 @@ void ImGui::UpdateTabFocus()
|
|||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
|
|
||||||
// Pressing TAB activate widget focus
|
// Pressing TAB activate widget focus
|
||||||
g.FocusTabPressed = (g.NavWindow && g.NavWindow->Active && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs) && !g.IO.KeyCtrl && IsKeyPressedMap(ImGuiKey_Tab));
|
g.TabFocusPressed = (g.NavWindow && g.NavWindow->Active && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs) && !g.IO.KeyCtrl && IsKeyPressedMap(ImGuiKey_Tab));
|
||||||
if (g.ActiveId == 0 && g.FocusTabPressed)
|
if (g.ActiveId == 0 && g.TabFocusPressed)
|
||||||
{
|
{
|
||||||
// Note that SetKeyboardFocusHere() sets the Next fields mid-frame. To be consistent we also
|
// 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.
|
// manipulate the Next fields even, even though they will be turned into Curr fields by the code below.
|
||||||
g.FocusRequestNextWindow = g.NavWindow;
|
g.TabFocusRequestNextWindow = g.NavWindow;
|
||||||
g.FocusRequestNextCounterRegular = INT_MAX;
|
g.TabFocusRequestNextCounterRegular = INT_MAX;
|
||||||
if (g.NavId != 0 && g.NavIdTabCounter != 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
|
else
|
||||||
g.FocusRequestNextCounterTabStop = g.IO.KeyShift ? -1 : 0;
|
g.TabFocusRequestNextCounterTabStop = g.IO.KeyShift ? -1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Turn queued focus request into current one
|
// Turn queued focus request into current one
|
||||||
g.FocusRequestCurrWindow = NULL;
|
g.TabFocusRequestCurrWindow = NULL;
|
||||||
g.FocusRequestCurrCounterRegular = g.FocusRequestCurrCounterTabStop = INT_MAX;
|
g.TabFocusRequestCurrCounterRegular = g.TabFocusRequestCurrCounterTabStop = INT_MAX;
|
||||||
if (g.FocusRequestNextWindow != NULL)
|
if (g.TabFocusRequestNextWindow != NULL)
|
||||||
{
|
{
|
||||||
ImGuiWindow* window = g.FocusRequestNextWindow;
|
ImGuiWindow* window = g.TabFocusRequestNextWindow;
|
||||||
g.FocusRequestCurrWindow = window;
|
g.TabFocusRequestCurrWindow = window;
|
||||||
if (g.FocusRequestNextCounterRegular != INT_MAX && window->DC.FocusCounterRegular != -1)
|
if (g.TabFocusRequestNextCounterRegular != INT_MAX && window->DC.FocusCounterRegular != -1)
|
||||||
g.FocusRequestCurrCounterRegular = ImModPositive(g.FocusRequestNextCounterRegular, window->DC.FocusCounterRegular + 1);
|
g.TabFocusRequestCurrCounterRegular = ImModPositive(g.TabFocusRequestNextCounterRegular, window->DC.FocusCounterRegular + 1);
|
||||||
if (g.FocusRequestNextCounterTabStop != INT_MAX && window->DC.FocusCounterTabStop != -1)
|
if (g.TabFocusRequestNextCounterTabStop != INT_MAX && window->DC.FocusCounterTabStop != -1)
|
||||||
g.FocusRequestCurrCounterTabStop = ImModPositive(g.FocusRequestNextCounterTabStop, window->DC.FocusCounterTabStop + 1);
|
g.TabFocusRequestCurrCounterTabStop = ImModPositive(g.TabFocusRequestNextCounterTabStop, window->DC.FocusCounterTabStop + 1);
|
||||||
g.FocusRequestNextWindow = NULL;
|
g.TabFocusRequestNextWindow = NULL;
|
||||||
g.FocusRequestNextCounterRegular = g.FocusRequestNextCounterTabStop = INT_MAX;
|
g.TabFocusRequestNextCounterRegular = g.TabFocusRequestNextCounterTabStop = INT_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
g.NavIdTabCounter = 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;
|
window->Collapsed = !window->Collapsed;
|
||||||
MarkIniSettingsDirty(window);
|
MarkIniSettingsDirty(window);
|
||||||
FocusWindow(window);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -6222,7 +6221,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
|||||||
if (want_focus)
|
if (want_focus)
|
||||||
{
|
{
|
||||||
FocusWindow(window);
|
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
|
// Title bar
|
||||||
@ -6924,9 +6923,9 @@ void ImGui::SetKeyboardFocusHere(int offset)
|
|||||||
IM_ASSERT(offset >= -1); // -1 is allowed but not below
|
IM_ASSERT(offset >= -1); // -1 is allowed but not below
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
ImGuiWindow* window = g.CurrentWindow;
|
ImGuiWindow* window = g.CurrentWindow;
|
||||||
g.FocusRequestNextWindow = window;
|
g.TabFocusRequestNextWindow = window;
|
||||||
g.FocusRequestNextCounterRegular = window->DC.FocusCounterRegular + 1 + offset;
|
g.TabFocusRequestNextCounterRegular = window->DC.FocusCounterRegular + 1 + offset;
|
||||||
g.FocusRequestNextCounterTabStop = INT_MAX;
|
g.TabFocusRequestNextCounterTabStop = INT_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui::SetItemDefaultFocus()
|
void ImGui::SetItemDefaultFocus()
|
||||||
|
@ -1422,13 +1422,13 @@ struct ImGuiContext
|
|||||||
bool NavWindowingToggleLayer;
|
bool NavWindowingToggleLayer;
|
||||||
|
|
||||||
// Legacy Focus/Tabbing system (older than Nav, active even if Nav is disabled, misnamed. FIXME-NAV: This needs a redesign!)
|
// Legacy Focus/Tabbing system (older than Nav, active even if Nav is disabled, misnamed. FIXME-NAV: This needs a redesign!)
|
||||||
ImGuiWindow* FocusRequestCurrWindow; //
|
ImGuiWindow* TabFocusRequestCurrWindow; //
|
||||||
ImGuiWindow* FocusRequestNextWindow; //
|
ImGuiWindow* TabFocusRequestNextWindow; //
|
||||||
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 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 FocusRequestCurrCounterTabStop; // Tab item being requested for focus, stored as an index
|
int TabFocusRequestCurrCounterTabStop; // Tab item being requested for focus, stored as an index
|
||||||
int FocusRequestNextCounterRegular; // Stored for next frame
|
int TabFocusRequestNextCounterRegular; // Stored for next frame
|
||||||
int FocusRequestNextCounterTabStop; // "
|
int TabFocusRequestNextCounterTabStop; // "
|
||||||
bool FocusTabPressed; //
|
bool TabFocusPressed; //
|
||||||
|
|
||||||
// Render
|
// Render
|
||||||
float DimBgRatio; // 0.0..1.0 animation when fading in a dimming background (for modal window and CTRL+TAB list)
|
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;
|
NavWindowingTimer = NavWindowingHighlightAlpha = 0.0f;
|
||||||
NavWindowingToggleLayer = false;
|
NavWindowingToggleLayer = false;
|
||||||
|
|
||||||
FocusRequestCurrWindow = FocusRequestNextWindow = NULL;
|
TabFocusRequestCurrWindow = TabFocusRequestNextWindow = NULL;
|
||||||
FocusRequestCurrCounterRegular = FocusRequestCurrCounterTabStop = INT_MAX;
|
TabFocusRequestCurrCounterRegular = TabFocusRequestCurrCounterTabStop = INT_MAX;
|
||||||
FocusRequestNextCounterRegular = FocusRequestNextCounterTabStop = INT_MAX;
|
TabFocusRequestNextCounterRegular = TabFocusRequestNextCounterTabStop = INT_MAX;
|
||||||
FocusTabPressed = false;
|
TabFocusPressed = false;
|
||||||
|
|
||||||
DimBgRatio = 0.0f;
|
DimBgRatio = 0.0f;
|
||||||
MouseCursor = ImGuiMouseCursor_Arrow;
|
MouseCursor = ImGuiMouseCursor_Arrow;
|
||||||
|
@ -3927,7 +3927,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
|||||||
ImGuiInputTextState* state = GetInputTextState(id);
|
ImGuiInputTextState* state = GetInputTextState(id);
|
||||||
|
|
||||||
const bool focus_requested = FocusableItemRegister(window, 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 focus_requested_by_tab = focus_requested && !focus_requested_by_code;
|
||||||
|
|
||||||
const bool user_clicked = hovered && io.MouseClicked[0];
|
const bool user_clicked = hovered && io.MouseClicked[0];
|
||||||
|
Loading…
Reference in New Issue
Block a user