Nav: Minor tweaks also toward removing processing from ItemAdd()

This commit is contained in:
omar 2017-10-06 14:51:15 -07:00
parent d16309ca77
commit c3105919ba
2 changed files with 9 additions and 3 deletions

View File

@ -2233,7 +2233,7 @@ bool ImGui::ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb_arg)
// (b) So that we can scroll up/down past clipped items. This adds a small O(N) cost to regular navigation requests unfortunately, but it is still limited to one window. // (b) So that we can scroll up/down past clipped items. This adds a small O(N) cost to regular navigation requests unfortunately, but it is still limited to one window.
// it may not scale very well for windows with ten of thousands of item, but at least NavMoveRequest is only set on user interaction, aka maximum once a frame. // it may not scale very well for windows with ten of thousands of item, but at least NavMoveRequest is only set on user interaction, aka maximum once a frame.
// We could early out with `if (is_clipped && !g.NavInitDefaultRequest) return false;` but when we wouldn't be able to reach unclipped widgets. This would work if user had explicit scrolling control (e.g. mapped on a stick) // We could early out with `if (is_clipped && !g.NavInitDefaultRequest) return false;` but when we wouldn't be able to reach unclipped widgets. This would work if user had explicit scrolling control (e.g. mapped on a stick)
window->DC.NavLayerActiveMaskNext |= (1 << window->DC.NavLayerCurrent); window->DC.NavLayerActiveMaskNext |= window->DC.NavLayerCurrentMask;
if (g.NavWindow == window->RootNavWindow) if (g.NavWindow == window->RootNavWindow)
if (g.NavId == id || g.NavMoveRequest || g.NavInitDefaultRequest || IMGUI_DEBUG_NAV) if (g.NavId == id || g.NavMoveRequest || g.NavInitDefaultRequest || IMGUI_DEBUG_NAV)
NavProcessItem(window, nav_bb_arg ? *nav_bb_arg : bb, id); NavProcessItem(window, nav_bb_arg ? *nav_bb_arg : bb, id);
@ -5377,9 +5377,10 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
if (!(flags & ImGuiWindowFlags_NoTitleBar)) if (!(flags & ImGuiWindowFlags_NoTitleBar))
{ {
// Close & collapse button are on layer 1 (same as menus) and don't default focus // Close & collapse button are on layer 1 (same as menus) and don't default focus
const ImGuiItemFlags backup_item_options = window->DC.ItemFlags; const ImGuiItemFlags item_flags_backup = window->DC.ItemFlags;
window->DC.ItemFlags |= ImGuiItemFlags_NoNavDefaultFocus; window->DC.ItemFlags |= ImGuiItemFlags_NoNavDefaultFocus;
window->DC.NavLayerCurrent++; window->DC.NavLayerCurrent++;
window->DC.NavLayerCurrentMask <<= 1;
// Collapse button // Collapse button
if (!(flags & ImGuiWindowFlags_NoCollapse)) if (!(flags & ImGuiWindowFlags_NoCollapse))
@ -5403,7 +5404,8 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
} }
window->DC.NavLayerCurrent--; window->DC.NavLayerCurrent--;
window->DC.ItemFlags = backup_item_options; window->DC.NavLayerCurrentMask >>= 1;
window->DC.ItemFlags = item_flags_backup;
// Title text (FIXME: refactor text alignment facilities along with RenderText helpers) // Title text (FIXME: refactor text alignment facilities along with RenderText helpers)
const ImVec2 text_size = CalcTextSize(name, NULL, true); const ImVec2 text_size = CalcTextSize(name, NULL, true);
@ -10093,6 +10095,7 @@ bool ImGui::BeginMenuBar()
window->DC.CursorPos = ImVec2(rect.Min.x + window->DC.MenuBarOffsetX, rect.Min.y);// + g.Style.FramePadding.y); window->DC.CursorPos = ImVec2(rect.Min.x + window->DC.MenuBarOffsetX, rect.Min.y);// + g.Style.FramePadding.y);
window->DC.LayoutType = ImGuiLayoutType_Horizontal; window->DC.LayoutType = ImGuiLayoutType_Horizontal;
window->DC.NavLayerCurrent++; window->DC.NavLayerCurrent++;
window->DC.NavLayerCurrentMask <<= 1;
window->DC.MenuBarAppending = true; window->DC.MenuBarAppending = true;
AlignFirstTextHeightToWidgets(); AlignFirstTextHeightToWidgets();
return true; return true;
@ -10134,6 +10137,7 @@ void ImGui::EndMenuBar()
EndGroup(); EndGroup();
window->DC.LayoutType = ImGuiLayoutType_Vertical; window->DC.LayoutType = ImGuiLayoutType_Vertical;
window->DC.NavLayerCurrent--; window->DC.NavLayerCurrent--;
window->DC.NavLayerCurrentMask >>= 1;
window->DC.MenuBarAppending = false; window->DC.MenuBarAppending = false;
} }

View File

@ -683,6 +683,7 @@ struct IMGUI_API ImGuiDrawContext
bool LastItemRectHoveredRect; bool LastItemRectHoveredRect;
bool NavHasScroll; // Set when scrolling can be used (ScrollMax > 0.0f) bool NavHasScroll; // Set when scrolling can be used (ScrollMax > 0.0f)
int NavLayerCurrent; // Current layer, 0..31 (we currently only use 0..1) int NavLayerCurrent; // Current layer, 0..31 (we currently only use 0..1)
int NavLayerCurrentMask; // = (1 << NavLayerCurrent) used by ItemAdd prior to clipping.
int NavLayerActiveMask; // Which layer have been written to (result from previous frame) int NavLayerActiveMask; // Which layer have been written to (result from previous frame)
int NavLayerActiveMaskNext; // Which layer have been written to (buffer for current frame) int NavLayerActiveMaskNext; // Which layer have been written to (buffer for current frame)
bool MenuBarAppending; // FIXME: Remove this bool MenuBarAppending; // FIXME: Remove this
@ -730,6 +731,7 @@ struct IMGUI_API ImGuiDrawContext
NavHasScroll = false; NavHasScroll = false;
NavLayerActiveMask = NavLayerActiveMaskNext = 0x00; NavLayerActiveMask = NavLayerActiveMaskNext = 0x00;
NavLayerCurrent = 0; NavLayerCurrent = 0;
NavLayerCurrentMask = 1 << 0;
MenuBarAppending = false; MenuBarAppending = false;
MenuBarOffsetX = 0.0f; MenuBarOffsetX = 0.0f;
StateStorage = NULL; StateStorage = NULL;