mirror of
https://github.com/ocornut/imgui.git
synced 2025-01-30 11:37:29 +01: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
|
// Increment counters
|
||||||
const bool is_tab_stop = (window->DC.ItemFlags & (ImGuiItemFlags_NoTabStop | ImGuiItemFlags_Disabled)) == 0;
|
const bool is_tab_stop = (window->DC.ItemFlags & (ImGuiItemFlags_NoTabStop | ImGuiItemFlags_Disabled)) == 0;
|
||||||
window->DC.FocusCounterAll++;
|
window->DC.FocusCounterRegular++;
|
||||||
if (is_tab_stop)
|
if (is_tab_stop)
|
||||||
window->DC.FocusCounterTab++;
|
window->DC.FocusCounterTabStop++;
|
||||||
|
|
||||||
// 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.FocusTabPressed && !IsActiveIdUsingKey(ImGuiKey_Tab) && g.FocusRequestNextWindow == NULL)
|
||||||
{
|
{
|
||||||
g.FocusRequestNextWindow = window;
|
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
|
// Handle focus requests
|
||||||
if (g.FocusRequestCurrWindow == window)
|
if (g.FocusRequestCurrWindow == window)
|
||||||
{
|
{
|
||||||
if (window->DC.FocusCounterAll == g.FocusRequestCurrCounterAll)
|
if (window->DC.FocusCounterRegular == g.FocusRequestCurrCounterRegular)
|
||||||
return true;
|
return true;
|
||||||
if (is_tab_stop && window->DC.FocusCounterTab == g.FocusRequestCurrCounterTab)
|
if (is_tab_stop && window->DC.FocusCounterTabStop == g.FocusRequestCurrCounterTabStop)
|
||||||
{
|
{
|
||||||
g.NavJustTabbedId = id;
|
g.NavJustTabbedId = id;
|
||||||
return true;
|
return true;
|
||||||
@ -3113,8 +3113,8 @@ bool ImGui::FocusableItemRegister(ImGuiWindow* window, ImGuiID id)
|
|||||||
|
|
||||||
void ImGui::FocusableItemUnregister(ImGuiWindow* window)
|
void ImGui::FocusableItemUnregister(ImGuiWindow* window)
|
||||||
{
|
{
|
||||||
window->DC.FocusCounterAll--;
|
window->DC.FocusCounterRegular--;
|
||||||
window->DC.FocusCounterTab--;
|
window->DC.FocusCounterTabStop--;
|
||||||
}
|
}
|
||||||
|
|
||||||
float ImGui::CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x)
|
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
|
// 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.FocusRequestNextWindow = g.NavWindow;
|
||||||
g.FocusRequestNextCounterAll = INT_MAX;
|
g.FocusRequestNextCounterRegular = INT_MAX;
|
||||||
if (g.NavId != 0 && g.NavIdTabCounter != 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
|
else
|
||||||
g.FocusRequestNextCounterTab = g.IO.KeyShift ? -1 : 0;
|
g.FocusRequestNextCounterTabStop = g.IO.KeyShift ? -1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Turn queued focus request into current one
|
// Turn queued focus request into current one
|
||||||
g.FocusRequestCurrWindow = NULL;
|
g.FocusRequestCurrWindow = NULL;
|
||||||
g.FocusRequestCurrCounterAll = g.FocusRequestCurrCounterTab = INT_MAX;
|
g.FocusRequestCurrCounterRegular = g.FocusRequestCurrCounterTabStop = INT_MAX;
|
||||||
if (g.FocusRequestNextWindow != NULL)
|
if (g.FocusRequestNextWindow != NULL)
|
||||||
{
|
{
|
||||||
ImGuiWindow* window = g.FocusRequestNextWindow;
|
ImGuiWindow* window = g.FocusRequestNextWindow;
|
||||||
g.FocusRequestCurrWindow = window;
|
g.FocusRequestCurrWindow = window;
|
||||||
if (g.FocusRequestNextCounterAll != INT_MAX && window->DC.FocusCounterAll != -1)
|
if (g.FocusRequestNextCounterRegular != INT_MAX && window->DC.FocusCounterRegular != -1)
|
||||||
g.FocusRequestCurrCounterAll = ImModPositive(g.FocusRequestNextCounterAll, window->DC.FocusCounterAll + 1);
|
g.FocusRequestCurrCounterRegular = ImModPositive(g.FocusRequestNextCounterRegular, window->DC.FocusCounterRegular + 1);
|
||||||
if (g.FocusRequestNextCounterTab != INT_MAX && window->DC.FocusCounterTab != -1)
|
if (g.FocusRequestNextCounterTabStop != INT_MAX && window->DC.FocusCounterTabStop != -1)
|
||||||
g.FocusRequestCurrCounterTab = ImModPositive(g.FocusRequestNextCounterTab, window->DC.FocusCounterTab + 1);
|
g.FocusRequestCurrCounterTabStop = ImModPositive(g.FocusRequestNextCounterTabStop, window->DC.FocusCounterTabStop + 1);
|
||||||
g.FocusRequestNextWindow = NULL;
|
g.FocusRequestNextWindow = NULL;
|
||||||
g.FocusRequestNextCounterAll = g.FocusRequestNextCounterTab = INT_MAX;
|
g.FocusRequestNextCounterRegular = g.FocusRequestNextCounterTabStop = INT_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
g.NavIdTabCounter = 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.ChildWindows.resize(0);
|
||||||
window->DC.LayoutType = ImGuiLayoutType_Vertical;
|
window->DC.LayoutType = ImGuiLayoutType_Vertical;
|
||||||
window->DC.ParentLayoutType = parent_window ? parent_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.ItemFlags = parent_window ? parent_window->DC.ItemFlags : ImGuiItemFlags_Default_;
|
||||||
window->DC.ItemWidth = window->ItemWidthDefault;
|
window->DC.ItemWidth = window->ItemWidthDefault;
|
||||||
window->DC.TextWrapPos = -1.0f; // disabled
|
window->DC.TextWrapPos = -1.0f; // disabled
|
||||||
@ -6904,8 +6904,8 @@ void ImGui::SetKeyboardFocusHere(int offset)
|
|||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
ImGuiWindow* window = g.CurrentWindow;
|
ImGuiWindow* window = g.CurrentWindow;
|
||||||
g.FocusRequestNextWindow = window;
|
g.FocusRequestNextWindow = window;
|
||||||
g.FocusRequestNextCounterAll = window->DC.FocusCounterAll + 1 + offset;
|
g.FocusRequestNextCounterRegular = window->DC.FocusCounterRegular + 1 + offset;
|
||||||
g.FocusRequestNextCounterTab = INT_MAX;
|
g.FocusRequestNextCounterTabStop = INT_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui::SetItemDefaultFocus()
|
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.NavWindow = window; // Always refresh g.NavWindow, because some operations such as FocusItem() don't have a window.
|
||||||
g.NavLayer = window->DC.NavLayerCurrent;
|
g.NavLayer = window->DC.NavLayerCurrent;
|
||||||
g.NavIdIsAlive = true;
|
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)
|
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 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)
|
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* FocusRequestCurrWindow; //
|
||||||
ImGuiWindow* FocusRequestNextWindow; //
|
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 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 FocusRequestCurrCounterTab; // Tab item being requested for focus, stored as an index
|
int FocusRequestCurrCounterTabStop; // Tab item being requested for focus, stored as an index
|
||||||
int FocusRequestNextCounterAll; // Stored for next frame
|
int FocusRequestNextCounterRegular; // Stored for next frame
|
||||||
int FocusRequestNextCounterTab; // "
|
int FocusRequestNextCounterTabStop; // "
|
||||||
bool FocusTabPressed; //
|
bool FocusTabPressed; //
|
||||||
|
|
||||||
// Range-Select/Multi-Select
|
// Range-Select/Multi-Select
|
||||||
@ -1243,8 +1243,8 @@ struct ImGuiContext
|
|||||||
NavMoveDir = NavMoveDirLast = NavMoveClipDir = ImGuiDir_None;
|
NavMoveDir = NavMoveDirLast = NavMoveClipDir = ImGuiDir_None;
|
||||||
|
|
||||||
FocusRequestCurrWindow = FocusRequestNextWindow = NULL;
|
FocusRequestCurrWindow = FocusRequestNextWindow = NULL;
|
||||||
FocusRequestCurrCounterAll = FocusRequestCurrCounterTab = INT_MAX;
|
FocusRequestCurrCounterRegular = FocusRequestCurrCounterTabStop = INT_MAX;
|
||||||
FocusRequestNextCounterAll = FocusRequestNextCounterTab = INT_MAX;
|
FocusRequestNextCounterRegular = FocusRequestNextCounterTabStop = INT_MAX;
|
||||||
FocusTabPressed = false;
|
FocusTabPressed = false;
|
||||||
|
|
||||||
MultiSelectScopeId = 0;
|
MultiSelectScopeId = 0;
|
||||||
@ -1347,8 +1347,8 @@ struct IMGUI_API ImGuiWindowTempData
|
|||||||
ImGuiColumns* CurrentColumns; // Current columns set
|
ImGuiColumns* CurrentColumns; // Current columns set
|
||||||
ImGuiLayoutType LayoutType;
|
ImGuiLayoutType LayoutType;
|
||||||
ImGuiLayoutType ParentLayoutType; // Layout type of parent window at the time of Begin()
|
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 FocusCounterRegular; // (Legacy Focus/Tabbing system) Sequential counter, 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 FocusCounterTabStop; // (Legacy Focus/Tabbing system) Same, but only count widgets which you can Tab through.
|
||||||
|
|
||||||
// Local parameters stacks
|
// 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.
|
// 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;
|
StateStorage = NULL;
|
||||||
CurrentColumns = NULL;
|
CurrentColumns = NULL;
|
||||||
LayoutType = ParentLayoutType = ImGuiLayoutType_Vertical;
|
LayoutType = ParentLayoutType = ImGuiLayoutType_Vertical;
|
||||||
FocusCounterAll = FocusCounterTab = -1;
|
FocusCounterRegular = FocusCounterTabStop = -1;
|
||||||
|
|
||||||
ItemFlags = ImGuiItemFlags_Default_;
|
ItemFlags = ImGuiItemFlags_Default_;
|
||||||
ItemWidth = 0.0f;
|
ItemWidth = 0.0f;
|
||||||
|
@ -3458,7 +3458,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
|||||||
state = &g.InputTextState;
|
state = &g.InputTextState;
|
||||||
|
|
||||||
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.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 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…
x
Reference in New Issue
Block a user