mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-22 03:47:00 +00:00
Internals: Nav: renaming.
This commit is contained in:
parent
06545c4f2a
commit
daf97832f1
40
imgui.cpp
40
imgui.cpp
@ -897,8 +897,8 @@ static void NavUpdateInitResult();
|
||||
static float NavUpdatePageUpPageDown();
|
||||
static inline void NavUpdateAnyRequestFlag();
|
||||
static void NavEndFrame();
|
||||
static bool NavScoreItem(ImGuiNavMoveResult* result, ImRect cand);
|
||||
static void NavApplyItemToResult(ImGuiNavMoveResult* result, ImGuiWindow* window, ImGuiID id, const ImRect& nav_bb_rel);
|
||||
static bool NavScoreItem(ImGuiNavItemData* result, ImRect cand);
|
||||
static void NavApplyItemToResult(ImGuiNavItemData* result, ImGuiWindow* window, ImGuiID id, const ImRect& nav_bb_rel);
|
||||
static void NavProcessItem(ImGuiWindow* window, const ImRect& nav_bb, ImGuiID id);
|
||||
static ImVec2 NavCalcPreferredRefPos();
|
||||
static void NavSaveLastChildNavWindowIntoParent(ImGuiWindow* nav_window);
|
||||
@ -4989,7 +4989,7 @@ bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, b
|
||||
parent_window->DC.CursorPos = child_window->Pos;
|
||||
|
||||
// Process navigation-in immediately so NavInit can run on first frame
|
||||
if (g.NavActivateId == id && !(flags & ImGuiWindowFlags_NavFlattened) && (child_window->DC.NavLayerActiveMask != 0 || child_window->DC.NavHasScroll))
|
||||
if (g.NavActivateId == id && !(flags & ImGuiWindowFlags_NavFlattened) && (child_window->DC.NavLayersActiveMask != 0 || child_window->DC.NavHasScroll))
|
||||
{
|
||||
FocusWindow(child_window);
|
||||
NavInitWindow(child_window, false);
|
||||
@ -5036,13 +5036,13 @@ void ImGui::EndChild()
|
||||
ImGuiWindow* parent_window = g.CurrentWindow;
|
||||
ImRect bb(parent_window->DC.CursorPos, parent_window->DC.CursorPos + sz);
|
||||
ItemSize(sz);
|
||||
if ((window->DC.NavLayerActiveMask != 0 || window->DC.NavHasScroll) && !(window->Flags & ImGuiWindowFlags_NavFlattened))
|
||||
if ((window->DC.NavLayersActiveMask != 0 || window->DC.NavHasScroll) && !(window->Flags & ImGuiWindowFlags_NavFlattened))
|
||||
{
|
||||
ItemAdd(bb, window->ChildId);
|
||||
RenderNavHighlight(bb, window->ChildId);
|
||||
|
||||
// When browsing a window that has no activable items (scroll only) we keep a highlight on the child
|
||||
if (window->DC.NavLayerActiveMask == 0 && window == g.NavWindow)
|
||||
if (window->DC.NavLayersActiveMask == 0 && window == g.NavWindow)
|
||||
RenderNavHighlight(ImRect(bb.Min - ImVec2(2, 2), bb.Max + ImVec2(2, 2)), g.NavId, ImGuiNavHighlightFlags_TypeThin);
|
||||
}
|
||||
else
|
||||
@ -6225,8 +6225,8 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
||||
window->DC.CurrLineTextBaseOffset = window->DC.PrevLineTextBaseOffset = 0.0f;
|
||||
|
||||
window->DC.NavLayerCurrent = ImGuiNavLayer_Main;
|
||||
window->DC.NavLayerActiveMask = window->DC.NavLayerActiveMaskNext;
|
||||
window->DC.NavLayerActiveMaskNext = 0x00;
|
||||
window->DC.NavLayersActiveMask = window->DC.NavLayersActiveMaskNext;
|
||||
window->DC.NavLayersActiveMaskNext = 0x00;
|
||||
window->DC.NavHideHighlightOneFrame = false;
|
||||
window->DC.NavHasScroll = (window->ScrollMax.y > 0.0f);
|
||||
|
||||
@ -7390,7 +7390,7 @@ bool ImGui::ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb_arg)
|
||||
// to reach unclipped widgets. This would work if user had explicit scrolling control (e.g. mapped on a stick).
|
||||
// We intentionally don't check if g.NavWindow != NULL because g.NavAnyRequest should only be set when it is non null.
|
||||
// If we crash on a NULL g.NavWindow we need to fix the bug elsewhere.
|
||||
window->DC.NavLayerActiveMaskNext |= (1 << window->DC.NavLayerCurrent);
|
||||
window->DC.NavLayersActiveMaskNext |= (1 << window->DC.NavLayerCurrent);
|
||||
if (g.NavId == id || g.NavAnyRequest)
|
||||
if (g.NavWindow->RootWindowForNav == window->RootWindowForNav)
|
||||
if (window == g.NavWindow || ((window->Flags | g.NavWindow->Flags) & ImGuiWindowFlags_NavFlattened))
|
||||
@ -8559,13 +8559,13 @@ ImVec2 ImGui::FindBestWindowPosForPopup(ImGuiWindow* window)
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// FIXME-NAV: The existence of SetNavID vs SetFocusID properly needs to be clarified/reworked.
|
||||
void ImGui::SetNavID(ImGuiID id, int nav_layer, ImGuiID focus_scope_id, const ImRect& rect_rel)
|
||||
void ImGui::SetNavID(ImGuiID id, ImGuiNavLayer nav_layer, ImGuiID focus_scope_id, const ImRect& rect_rel)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
IM_ASSERT(g.NavWindow != NULL);
|
||||
IM_ASSERT(nav_layer == ImGuiNavLayer_Main || nav_layer == ImGuiNavLayer_Menu);
|
||||
g.NavId = id;
|
||||
g.NavLayer = (ImGuiNavLayer)nav_layer;
|
||||
g.NavLayer = nav_layer;
|
||||
g.NavFocusScopeId = focus_scope_id;
|
||||
g.NavWindow->NavLastIds[nav_layer] = id;
|
||||
g.NavWindow->NavRectRel[nav_layer] = rect_rel;
|
||||
@ -8628,7 +8628,7 @@ static void inline NavClampRectToVisibleAreaForMoveDir(ImGuiDir move_dir, ImRect
|
||||
}
|
||||
|
||||
// Scoring function for gamepad/keyboard directional navigation. Based on https://gist.github.com/rygorous/6981057
|
||||
static bool ImGui::NavScoreItem(ImGuiNavMoveResult* result, ImRect cand)
|
||||
static bool ImGui::NavScoreItem(ImGuiNavItemData* result, ImRect cand)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* window = g.CurrentWindow;
|
||||
@ -8759,7 +8759,7 @@ static bool ImGui::NavScoreItem(ImGuiNavMoveResult* result, ImRect cand)
|
||||
return new_best;
|
||||
}
|
||||
|
||||
static void ImGui::NavApplyItemToResult(ImGuiNavMoveResult* result, ImGuiWindow* window, ImGuiID id, const ImRect& nav_bb_rel)
|
||||
static void ImGui::NavApplyItemToResult(ImGuiNavItemData* result, ImGuiWindow* window, ImGuiID id, const ImRect& nav_bb_rel)
|
||||
{
|
||||
result->Window = window;
|
||||
result->ID = id;
|
||||
@ -8797,7 +8797,7 @@ static void ImGui::NavProcessItem(ImGuiWindow* window, const ImRect& nav_bb, con
|
||||
// FIXME-NAV: Consider policy for double scoring (scoring from NavScoringRectScreen + scoring from a rect wrapped according to current wrapping policy)
|
||||
if ((g.NavId != id || (g.NavMoveRequestFlags & ImGuiNavMoveFlags_AllowCurrentNavId)) && !(item_flags & (ImGuiItemFlags_Disabled | ImGuiItemFlags_NoNav)))
|
||||
{
|
||||
ImGuiNavMoveResult* result = (window == g.NavWindow) ? &g.NavMoveResultLocal : &g.NavMoveResultOther;
|
||||
ImGuiNavItemData* result = (window == g.NavWindow) ? &g.NavMoveResultLocal : &g.NavMoveResultOther;
|
||||
#if IMGUI_DEBUG_NAV_SCORING
|
||||
// [DEBUG] Score all items in NavWindow at all times
|
||||
if (!g.NavMoveRequest)
|
||||
@ -9210,7 +9210,7 @@ static void ImGui::NavUpdate()
|
||||
// *Fallback* manual-scroll with Nav directional keys when window has no navigable item
|
||||
ImGuiWindow* window = g.NavWindow;
|
||||
const float scroll_speed = IM_ROUND(window->CalcFontSize() * 100 * io.DeltaTime); // We need round the scrolling speed because sub-pixel scroll isn't reliably supported.
|
||||
if (window->DC.NavLayerActiveMask == 0x00 && window->DC.NavHasScroll && g.NavMoveRequest)
|
||||
if (window->DC.NavLayersActiveMask == 0x00 && window->DC.NavHasScroll && g.NavMoveRequest)
|
||||
{
|
||||
if (g.NavMoveDir == ImGuiDir_Left || g.NavMoveDir == ImGuiDir_Right)
|
||||
SetScrollX(window, ImFloor(window->Scroll.x + ((g.NavMoveDir == ImGuiDir_Left) ? -1.0f : +1.0f) * scroll_speed));
|
||||
@ -9302,7 +9302,7 @@ static void ImGui::NavUpdateMoveResult()
|
||||
}
|
||||
|
||||
// Select which result to use
|
||||
ImGuiNavMoveResult* result = (g.NavMoveResultLocal.ID != 0) ? &g.NavMoveResultLocal : &g.NavMoveResultOther;
|
||||
ImGuiNavItemData* result = (g.NavMoveResultLocal.ID != 0) ? &g.NavMoveResultLocal : &g.NavMoveResultOther;
|
||||
|
||||
// PageUp/PageDown behavior first jumps to the bottom/top mostly visible item, _otherwise_ use the result from the previous/next page.
|
||||
if (g.NavMoveRequestFlags & ImGuiNavMoveFlags_AlsoScoreVisibleSet)
|
||||
@ -9369,7 +9369,7 @@ static float ImGui::NavUpdatePageUpPageDown()
|
||||
const bool end_pressed = IsKeyPressed(io.KeyMap[ImGuiKey_End]) && !IsActiveIdUsingKey(ImGuiKey_End);
|
||||
if (page_up_held != page_down_held || home_pressed != end_pressed) // If either (not both) are pressed
|
||||
{
|
||||
if (window->DC.NavLayerActiveMask == 0x00 && window->DC.NavHasScroll)
|
||||
if (window->DC.NavLayersActiveMask == 0x00 && window->DC.NavHasScroll)
|
||||
{
|
||||
// Fallback manual-scroll when window has no navigable item
|
||||
if (IsKeyPressed(io.KeyMap[ImGuiKey_PageUp], true))
|
||||
@ -9633,7 +9633,7 @@ static void ImGui::NavUpdateWindowing()
|
||||
|
||||
// If the window has ONLY a menu layer (no main layer), select it directly
|
||||
// FIXME-NAV: This should be done in NavInit.. or in FocusWindow..
|
||||
if (apply_focus_window->DC.NavLayerActiveMask == (1 << ImGuiNavLayer_Menu))
|
||||
if (apply_focus_window->DC.NavLayersActiveMask == (1 << ImGuiNavLayer_Menu))
|
||||
g.NavLayer = ImGuiNavLayer_Menu;
|
||||
}
|
||||
if (apply_focus_window)
|
||||
@ -9645,7 +9645,7 @@ static void ImGui::NavUpdateWindowing()
|
||||
// Move to parent menu if necessary
|
||||
ImGuiWindow* new_nav_window = g.NavWindow;
|
||||
while (new_nav_window->ParentWindow
|
||||
&& (new_nav_window->DC.NavLayerActiveMask & (1 << ImGuiNavLayer_Menu)) == 0
|
||||
&& (new_nav_window->DC.NavLayersActiveMask & (1 << ImGuiNavLayer_Menu)) == 0
|
||||
&& (new_nav_window->Flags & ImGuiWindowFlags_ChildWindow) != 0
|
||||
&& (new_nav_window->Flags & (ImGuiWindowFlags_Popup | ImGuiWindowFlags_ChildMenu)) == 0)
|
||||
new_nav_window = new_nav_window->ParentWindow;
|
||||
@ -9659,7 +9659,7 @@ static void ImGui::NavUpdateWindowing()
|
||||
g.NavDisableMouseHover = true;
|
||||
|
||||
// Reinitialize navigation when entering menu bar with the Alt key.
|
||||
const ImGuiNavLayer new_nav_layer = (g.NavWindow->DC.NavLayerActiveMask & (1 << ImGuiNavLayer_Menu)) ? (ImGuiNavLayer)((int)g.NavLayer ^ 1) : ImGuiNavLayer_Main;
|
||||
const ImGuiNavLayer new_nav_layer = (g.NavWindow->DC.NavLayersActiveMask & (1 << ImGuiNavLayer_Menu)) ? (ImGuiNavLayer)((int)g.NavLayer ^ 1) : ImGuiNavLayer_Main;
|
||||
if (new_nav_layer == ImGuiNavLayer_Menu)
|
||||
g.NavWindow->NavLastIds[new_nav_layer] = 0;
|
||||
NavRestoreLayer(new_nav_layer);
|
||||
@ -11479,7 +11479,7 @@ void ImGui::DebugNodeWindow(ImGuiWindow* window, const char* label)
|
||||
if (IsItemHovered())
|
||||
GetForegroundDrawList(window)->AddRect(r.Min + window->Pos, r.Max + window->Pos, IM_COL32(255, 255, 0, 255));
|
||||
}
|
||||
BulletText("NavLayerActiveMask: %X, NavLastChildNavWindow: %s", window->DC.NavLayerActiveMask, window->NavLastChildNavWindow ? window->NavLastChildNavWindow->Name : "NULL");
|
||||
BulletText("NavLayersActiveMask: %X, NavLastChildNavWindow: %s", window->DC.NavLayersActiveMask, window->NavLastChildNavWindow ? window->NavLastChildNavWindow->Name : "NULL");
|
||||
if (window->RootWindow != window) { DebugNodeWindow(window->RootWindow, "RootWindow"); }
|
||||
if (window->ParentWindow != NULL) { DebugNodeWindow(window->ParentWindow, "ParentWindow"); }
|
||||
if (window->DC.ChildWindows.Size > 0) { DebugNodeWindowsList(&window->DC.ChildWindows, "ChildWindows"); }
|
||||
|
@ -107,7 +107,7 @@ struct ImGuiGroupData; // Stacked storage data for BeginGroup()/End
|
||||
struct ImGuiInputTextState; // Internal state of the currently focused/edited text input box
|
||||
struct ImGuiLastItemDataBackup; // Backup and restore IsItemHovered() internal data
|
||||
struct ImGuiMenuColumns; // Simple column measurement, currently used for MenuItem() only
|
||||
struct ImGuiNavMoveResult; // Result of a gamepad/keyboard directional navigation move query result
|
||||
struct ImGuiNavItemData; // Result of a gamepad/keyboard directional navigation move query result
|
||||
struct ImGuiMetricsConfig; // Storage for ShowMetricsWindow() and DebugNodeXXX() functions
|
||||
struct ImGuiNextWindowData; // Storage for SetNextWindow** functions
|
||||
struct ImGuiNextItemData; // Storage for SetNextItem** functions
|
||||
@ -1013,18 +1013,18 @@ struct ImGuiPopupData
|
||||
ImGuiPopupData() { memset(this, 0, sizeof(*this)); OpenFrameCount = -1; }
|
||||
};
|
||||
|
||||
struct ImGuiNavMoveResult
|
||||
struct ImGuiNavItemData
|
||||
{
|
||||
ImGuiWindow* Window; // Best candidate window
|
||||
ImGuiID ID; // Best candidate ID
|
||||
ImGuiID FocusScopeId; // Best candidate focus scope ID
|
||||
float DistBox; // Best candidate box distance to current NavId
|
||||
float DistCenter; // Best candidate center distance to current NavId
|
||||
float DistAxial;
|
||||
ImRect RectRel; // Best candidate bounding box in window relative space
|
||||
ImGuiWindow* Window; // Init,Move // Best candidate window (result->ItemWindow->RootWindowForNav == request->Window)
|
||||
ImGuiID ID; // Init,Move // Best candidate item ID
|
||||
ImGuiID FocusScopeId; // Init,Move // Best candidate focus scope ID
|
||||
ImRect RectRel; // Init,Move // Best candidate bounding box in window relative space
|
||||
float DistBox; // Move // Best candidate box distance to current NavId
|
||||
float DistCenter; // Move // Best candidate center distance to current NavId
|
||||
float DistAxial; // Move // Best candidate axial distance to current NavId
|
||||
|
||||
ImGuiNavMoveResult() { Clear(); }
|
||||
void Clear() { Window = NULL; ID = FocusScopeId = 0; DistBox = DistCenter = DistAxial = FLT_MAX; RectRel = ImRect(); }
|
||||
ImGuiNavItemData() { Clear(); }
|
||||
void Clear() { Window = NULL; ID = FocusScopeId = 0; RectRel = ImRect(); DistBox = DistCenter = DistAxial = FLT_MAX; }
|
||||
};
|
||||
|
||||
enum ImGuiNextWindowDataFlags_
|
||||
@ -1419,9 +1419,9 @@ struct ImGuiContext
|
||||
ImGuiKeyModFlags NavMoveRequestKeyMods;
|
||||
ImGuiDir NavMoveDir, NavMoveDirLast; // Direction of the move request (left/right/up/down), direction of the previous move request
|
||||
ImGuiDir NavMoveClipDir; // FIXME-NAV: Describe the purpose of this better. Might want to rename?
|
||||
ImGuiNavMoveResult NavMoveResultLocal; // Best move request candidate within NavWindow
|
||||
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)
|
||||
ImGuiNavItemData NavMoveResultLocal; // Best move request candidate within NavWindow
|
||||
ImGuiNavItemData NavMoveResultLocalVisibleSet; // Best move request candidate within NavWindow that are mostly visible (when using ImGuiNavMoveFlags_AlsoScoreVisibleSet flag)
|
||||
ImGuiNavItemData NavMoveResultOther; // Best move request candidate within NavWindow's flattened hierarchy (when using ImGuiWindowFlags_NavFlattened flag)
|
||||
ImGuiWindow* NavWrapRequestWindow; // Window which requested trying nav wrap-around.
|
||||
ImGuiNavMoveFlags NavWrapRequestFlags; // Wrap-around operation flags.
|
||||
|
||||
@ -1718,8 +1718,8 @@ struct IMGUI_API ImGuiWindowTempData
|
||||
|
||||
// Keyboard/Gamepad navigation
|
||||
ImGuiNavLayer NavLayerCurrent; // Current layer, 0..31 (we currently only use 0..1)
|
||||
int NavLayerActiveMask; // Which layers have been written to (result from previous frame)
|
||||
int NavLayerActiveMaskNext; // Which layers have been written to (accumulator for current frame)
|
||||
short NavLayersActiveMask; // Which layers have been written to (result from previous frame)
|
||||
short NavLayersActiveMaskNext;// Which layers have been written to (accumulator for current frame)
|
||||
ImGuiID NavFocusScopeIdCurrent; // Current focus scope ID while appending
|
||||
bool NavHideHighlightOneFrame;
|
||||
bool NavHasScroll; // Set when scrolling can be used (ScrollMax > 0.0f)
|
||||
@ -2335,7 +2335,7 @@ namespace ImGui
|
||||
IMGUI_API ImVec2 GetNavInputAmount2d(ImGuiNavDirSourceFlags dir_sources, ImGuiInputReadMode mode, float slow_factor = 0.0f, float fast_factor = 0.0f);
|
||||
IMGUI_API int CalcTypematicRepeatAmount(float t0, float t1, float repeat_delay, float repeat_rate);
|
||||
IMGUI_API void ActivateItem(ImGuiID id); // Remotely activate a button, checkbox, tree node etc. given its unique ID. activation is queued and processed on the next frame when the item is encountered again.
|
||||
IMGUI_API void SetNavID(ImGuiID id, int nav_layer, ImGuiID focus_scope_id, const ImRect& rect_rel);
|
||||
IMGUI_API void SetNavID(ImGuiID id, ImGuiNavLayer nav_layer, ImGuiID focus_scope_id, const ImRect& rect_rel);
|
||||
|
||||
// Focus Scope (WIP)
|
||||
// This is generally used to identify a selection set (multiple of which may be in the same window), as selection
|
||||
|
@ -3918,7 +3918,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
||||
return false;
|
||||
}
|
||||
draw_window = g.CurrentWindow; // Child window
|
||||
draw_window->DC.NavLayerActiveMaskNext |= (1 << draw_window->DC.NavLayerCurrent); // This is to ensure that EndChild() will display a navigation highlight so we can "enter" into it.
|
||||
draw_window->DC.NavLayersActiveMaskNext |= (1 << draw_window->DC.NavLayerCurrent); // This is to ensure that EndChild() will display a navigation highlight so we can "enter" into it.
|
||||
draw_window->DC.CursorPos += style.FramePadding;
|
||||
inner_size.x -= draw_window->ScrollbarSizes.x;
|
||||
}
|
||||
@ -6589,7 +6589,7 @@ void ImGui::EndMenuBar()
|
||||
// To do so we claim focus back, restore NavId and then process the movement request for yet another frame.
|
||||
// This involve a one-frame delay which isn't very problematic in this situation. We could remove it by scoring in advance for multiple window (probably not worth the hassle/cost)
|
||||
const ImGuiNavLayer layer = ImGuiNavLayer_Menu;
|
||||
IM_ASSERT(window->DC.NavLayerActiveMaskNext & (1 << layer)); // Sanity check
|
||||
IM_ASSERT(window->DC.NavLayersActiveMaskNext & (1 << layer)); // Sanity check
|
||||
FocusWindow(window);
|
||||
SetNavID(window->NavLastIds[layer], layer, 0, window->NavRectRel[layer]);
|
||||
g.NavDisableHighlight = true; // Hide highlight for the current frame so we don't see the intermediary selection.
|
||||
|
Loading…
Reference in New Issue
Block a user