mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-18 14:16:36 +00:00
Internals: Renaming and marking of legacy focus/tabbing system
This commit is contained in:
parent
52334ad8df
commit
02c2d18aa3
40
imgui.cpp
40
imgui.cpp
@ -3080,24 +3080,24 @@ bool ImGui::FocusableItemRegister(ImGuiWindow* window, ImGuiID id)
|
||||
|
||||
// Increment counters
|
||||
const bool is_tab_stop = (window->DC.ItemFlags & (ImGuiItemFlags_NoTabStop | ImGuiItemFlags_Disabled)) == 0;
|
||||
window->DC.FocusCounterAll++;
|
||||
window->DC.FocusCounterRegular++;
|
||||
if (is_tab_stop)
|
||||
window->DC.FocusCounterTab++;
|
||||
window->DC.FocusCounterTabStop++;
|
||||
|
||||
// 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)
|
||||
{
|
||||
g.FocusRequestNextWindow = window;
|
||||
g.FocusRequestNextCounterTab = window->DC.FocusCounterTab + (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.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.
|
||||
}
|
||||
|
||||
// Handle focus requests
|
||||
if (g.FocusRequestCurrWindow == window)
|
||||
{
|
||||
if (window->DC.FocusCounterAll == g.FocusRequestCurrCounterAll)
|
||||
if (window->DC.FocusCounterRegular == g.FocusRequestCurrCounterRegular)
|
||||
return true;
|
||||
if (is_tab_stop && window->DC.FocusCounterTab == g.FocusRequestCurrCounterTab)
|
||||
if (is_tab_stop && window->DC.FocusCounterTabStop == g.FocusRequestCurrCounterTabStop)
|
||||
{
|
||||
g.NavJustTabbedId = id;
|
||||
return true;
|
||||
@ -3113,8 +3113,8 @@ bool ImGui::FocusableItemRegister(ImGuiWindow* window, ImGuiID id)
|
||||
|
||||
void ImGui::FocusableItemUnregister(ImGuiWindow* window)
|
||||
{
|
||||
window->DC.FocusCounterAll--;
|
||||
window->DC.FocusCounterTab--;
|
||||
window->DC.FocusCounterRegular--;
|
||||
window->DC.FocusCounterTabStop--;
|
||||
}
|
||||
|
||||
float ImGui::CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x)
|
||||
@ -3767,26 +3767,26 @@ void ImGui::NewFrame()
|
||||
// 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.FocusRequestNextCounterAll = INT_MAX;
|
||||
g.FocusRequestNextCounterRegular = INT_MAX;
|
||||
if (g.NavId != 0 && g.NavIdTabCounter != INT_MAX)
|
||||
g.FocusRequestNextCounterTab = g.NavIdTabCounter + 1 + (g.IO.KeyShift ? -1 : 1);
|
||||
g.FocusRequestNextCounterTabStop = g.NavIdTabCounter + 1 + (g.IO.KeyShift ? -1 : 1);
|
||||
else
|
||||
g.FocusRequestNextCounterTab = g.IO.KeyShift ? -1 : 0;
|
||||
g.FocusRequestNextCounterTabStop = g.IO.KeyShift ? -1 : 0;
|
||||
}
|
||||
|
||||
// Turn queued focus request into current one
|
||||
g.FocusRequestCurrWindow = NULL;
|
||||
g.FocusRequestCurrCounterAll = g.FocusRequestCurrCounterTab = INT_MAX;
|
||||
g.FocusRequestCurrCounterRegular = g.FocusRequestCurrCounterTabStop = INT_MAX;
|
||||
if (g.FocusRequestNextWindow != NULL)
|
||||
{
|
||||
ImGuiWindow* window = g.FocusRequestNextWindow;
|
||||
g.FocusRequestCurrWindow = window;
|
||||
if (g.FocusRequestNextCounterAll != INT_MAX && window->DC.FocusCounterAll != -1)
|
||||
g.FocusRequestCurrCounterAll = ImModPositive(g.FocusRequestNextCounterAll, window->DC.FocusCounterAll + 1);
|
||||
if (g.FocusRequestNextCounterTab != INT_MAX && window->DC.FocusCounterTab != -1)
|
||||
g.FocusRequestCurrCounterTab = ImModPositive(g.FocusRequestNextCounterTab, window->DC.FocusCounterTab + 1);
|
||||
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.FocusRequestNextCounterAll = g.FocusRequestNextCounterTab = INT_MAX;
|
||||
g.FocusRequestNextCounterRegular = g.FocusRequestNextCounterTabStop = INT_MAX;
|
||||
}
|
||||
|
||||
g.NavIdTabCounter = INT_MAX;
|
||||
@ -5850,7 +5850,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
||||
window->DC.ChildWindows.resize(0);
|
||||
window->DC.LayoutType = ImGuiLayoutType_Vertical;
|
||||
window->DC.ParentLayoutType = parent_window ? parent_window->DC.LayoutType : ImGuiLayoutType_Vertical;
|
||||
window->DC.FocusCounterAll = window->DC.FocusCounterTab = -1;
|
||||
window->DC.FocusCounterRegular = window->DC.FocusCounterTabStop = -1;
|
||||
window->DC.ItemFlags = parent_window ? parent_window->DC.ItemFlags : ImGuiItemFlags_Default_;
|
||||
window->DC.ItemWidth = window->ItemWidthDefault;
|
||||
window->DC.TextWrapPos = -1.0f; // disabled
|
||||
@ -6904,8 +6904,8 @@ void ImGui::SetKeyboardFocusHere(int offset)
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* window = g.CurrentWindow;
|
||||
g.FocusRequestNextWindow = window;
|
||||
g.FocusRequestNextCounterAll = window->DC.FocusCounterAll + 1 + offset;
|
||||
g.FocusRequestNextCounterTab = INT_MAX;
|
||||
g.FocusRequestNextCounterRegular = window->DC.FocusCounterRegular + 1 + offset;
|
||||
g.FocusRequestNextCounterTabStop = INT_MAX;
|
||||
}
|
||||
|
||||
void ImGui::SetItemDefaultFocus()
|
||||
@ -8059,7 +8059,7 @@ static void ImGui::NavProcessItem(ImGuiWindow* window, const ImRect& nav_bb, con
|
||||
g.NavWindow = window; // Always refresh g.NavWindow, because some operations such as FocusItem() don't have a window.
|
||||
g.NavLayer = window->DC.NavLayerCurrent;
|
||||
g.NavIdIsAlive = true;
|
||||
g.NavIdTabCounter = window->DC.FocusCounterTab;
|
||||
g.NavIdTabCounter = window->DC.FocusCounterTabStop;
|
||||
window->NavRectRel[window->DC.NavLayerCurrent] = nav_bb_rel; // Store item bounding box (relative to window position)
|
||||
}
|
||||
}
|
||||
|
@ -1076,13 +1076,13 @@ struct ImGuiContext
|
||||
ImGuiNavMoveResult NavMoveResultLocalVisibleSet; // Best move request candidate within NavWindow that are mostly visible (when using ImGuiNavMoveFlags_AlsoScoreVisibleSet flag)
|
||||
ImGuiNavMoveResult NavMoveResultOther; // Best move request candidate within NavWindow's flattened hierarchy (when using ImGuiWindowFlags_NavFlattened flag)
|
||||
|
||||
// Legacy 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* FocusRequestNextWindow; //
|
||||
int FocusRequestCurrCounterAll; // 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 FocusRequestCurrCounterTab; // Tab item being requested for focus, stored as an index
|
||||
int FocusRequestNextCounterAll; // Stored for next frame
|
||||
int FocusRequestNextCounterTab; // "
|
||||
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; //
|
||||
|
||||
// Range-Select/Multi-Select
|
||||
@ -1243,8 +1243,8 @@ struct ImGuiContext
|
||||
NavMoveDir = NavMoveDirLast = NavMoveClipDir = ImGuiDir_None;
|
||||
|
||||
FocusRequestCurrWindow = FocusRequestNextWindow = NULL;
|
||||
FocusRequestCurrCounterAll = FocusRequestCurrCounterTab = INT_MAX;
|
||||
FocusRequestNextCounterAll = FocusRequestNextCounterTab = INT_MAX;
|
||||
FocusRequestCurrCounterRegular = FocusRequestCurrCounterTabStop = INT_MAX;
|
||||
FocusRequestNextCounterRegular = FocusRequestNextCounterTabStop = INT_MAX;
|
||||
FocusTabPressed = false;
|
||||
|
||||
MultiSelectScopeId = 0;
|
||||
@ -1347,8 +1347,8 @@ struct IMGUI_API ImGuiWindowTempData
|
||||
ImGuiColumns* CurrentColumns; // Current columns set
|
||||
ImGuiLayoutType LayoutType;
|
||||
ImGuiLayoutType ParentLayoutType; // Layout type of parent window at the time of Begin()
|
||||
int FocusCounterAll; // Counter for focus/tabbing system. Start at -1 and increase as assigned via FocusableItemRegister() (FIXME-NAV: Needs redesign)
|
||||
int FocusCounterTab; // (same, but only count widgets which you can Tab through)
|
||||
int FocusCounterRegular; // (Legacy Focus/Tabbing system) Sequential counter, start at -1 and increase as assigned via FocusableItemRegister() (FIXME-NAV: Needs redesign)
|
||||
int FocusCounterTabStop; // (Legacy Focus/Tabbing system) Same, but only count widgets which you can Tab through.
|
||||
|
||||
// Local parameters stacks
|
||||
// We store the current settings outside of the vectors to increase memory locality (reduce cache misses). The vectors are rarely modified. Also it allows us to not heap allocate for short-lived windows which are not using those settings.
|
||||
@ -1387,7 +1387,7 @@ struct IMGUI_API ImGuiWindowTempData
|
||||
StateStorage = NULL;
|
||||
CurrentColumns = NULL;
|
||||
LayoutType = ParentLayoutType = ImGuiLayoutType_Vertical;
|
||||
FocusCounterAll = FocusCounterTab = -1;
|
||||
FocusCounterRegular = FocusCounterTabStop = -1;
|
||||
|
||||
ItemFlags = ImGuiItemFlags_Default_;
|
||||
ItemWidth = 0.0f;
|
||||
|
@ -3458,7 +3458,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
||||
state = &g.InputTextState;
|
||||
|
||||
const bool focus_requested = FocusableItemRegister(window, id);
|
||||
const bool focus_requested_by_code = focus_requested && (g.FocusRequestCurrWindow == window && g.FocusRequestCurrCounterAll == window->DC.FocusCounterAll);
|
||||
const bool focus_requested_by_code = focus_requested && (g.FocusRequestCurrWindow == window && g.FocusRequestCurrCounterRegular == 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