mirror of
				https://github.com/ocornut/imgui.git
				synced 2025-11-04 01:34:32 +00:00 
			
		
		
		
	Nav: Store key mods associated to a nav request (for range_select) + use io.KeyMods.
+ renamed NavScoringRectScreen > NavScoringRect
This commit is contained in:
		
							
								
								
									
										19
									
								
								imgui.cpp
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								imgui.cpp
									
									
									
									
									
								
							@@ -2226,7 +2226,7 @@ void ImGui::CalcListClipping(int items_count, float items_height, int* out_items
 | 
				
			|||||||
    // We create the union of the ClipRect and the NavScoringRect which at worst should be 1 page away from ClipRect
 | 
					    // We create the union of the ClipRect and the NavScoringRect which at worst should be 1 page away from ClipRect
 | 
				
			||||||
    ImRect unclipped_rect = window->ClipRect;
 | 
					    ImRect unclipped_rect = window->ClipRect;
 | 
				
			||||||
    if (g.NavMoveRequest)
 | 
					    if (g.NavMoveRequest)
 | 
				
			||||||
        unclipped_rect.Add(g.NavScoringRectScreen);
 | 
					        unclipped_rect.Add(g.NavScoringRect);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const ImVec2 pos = window->DC.CursorPos;
 | 
					    const ImVec2 pos = window->DC.CursorPos;
 | 
				
			||||||
    int start = (int)((unclipped_rect.Min.y - pos.y) / items_height);
 | 
					    int start = (int)((unclipped_rect.Min.y - pos.y) / items_height);
 | 
				
			||||||
@@ -3677,7 +3677,7 @@ void ImGui::UpdateHoveredWindowAndCaptureFlags()
 | 
				
			|||||||
    g.IO.WantTextInput = (g.WantTextInputNextFrame != -1) ? (g.WantTextInputNextFrame != 0) : false;
 | 
					    g.IO.WantTextInput = (g.WantTextInputNextFrame != -1) ? (g.WantTextInputNextFrame != 0) : false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static ImGuiKeyModFlags GetMergedKeyModFlags()
 | 
					ImGuiKeyModFlags ImGui::GetMergedKeyModFlags()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    ImGuiContext& g = *GImGui;
 | 
					    ImGuiContext& g = *GImGui;
 | 
				
			||||||
    ImGuiKeyModFlags key_mod_flags = ImGuiKeyModFlags_None;
 | 
					    ImGuiKeyModFlags key_mod_flags = ImGuiKeyModFlags_None;
 | 
				
			||||||
@@ -7988,7 +7988,7 @@ static bool ImGui::NavScoreItem(ImGuiNavMoveResult* result, ImRect cand)
 | 
				
			|||||||
    if (g.NavLayer != window->DC.NavLayerCurrent)
 | 
					    if (g.NavLayer != window->DC.NavLayerCurrent)
 | 
				
			||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const ImRect& curr = g.NavScoringRectScreen; // Current modified source rect (NB: we've applied Max.x = Min.x in NavUpdate() to inhibit the effect of having varied item width)
 | 
					    const ImRect& curr = g.NavScoringRect; // Current modified source rect (NB: we've applied Max.x = Min.x in NavUpdate() to inhibit the effect of having varied item width)
 | 
				
			||||||
    g.NavScoringCount++;
 | 
					    g.NavScoringCount++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // When entering through a NavFlattened border, we consider child window items as fully clipped for scoring
 | 
					    // When entering through a NavFlattened border, we consider child window items as fully clipped for scoring
 | 
				
			||||||
@@ -8569,6 +8569,7 @@ static void ImGui::NavUpdate()
 | 
				
			|||||||
    if (g.NavMoveDir != ImGuiDir_None)
 | 
					    if (g.NavMoveDir != ImGuiDir_None)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        g.NavMoveRequest = true;
 | 
					        g.NavMoveRequest = true;
 | 
				
			||||||
 | 
					        g.NavMoveRequestKeyMods = g.IO.KeyMods;
 | 
				
			||||||
        g.NavMoveDirLast = g.NavMoveDir;
 | 
					        g.NavMoveDirLast = g.NavMoveDir;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (g.NavMoveRequest && g.NavId == 0)
 | 
					    if (g.NavMoveRequest && g.NavId == 0)
 | 
				
			||||||
@@ -8632,11 +8633,11 @@ static void ImGui::NavUpdate()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    // For scoring we use a single segment on the left side our current item bounding box (not touching the edge to avoid box overlap with zero-spaced items)
 | 
					    // For scoring we use a single segment on the left side our current item bounding box (not touching the edge to avoid box overlap with zero-spaced items)
 | 
				
			||||||
    ImRect nav_rect_rel = (g.NavWindow && !g.NavWindow->NavRectRel[g.NavLayer].IsInverted()) ? g.NavWindow->NavRectRel[g.NavLayer] : ImRect(0,0,0,0);
 | 
					    ImRect nav_rect_rel = (g.NavWindow && !g.NavWindow->NavRectRel[g.NavLayer].IsInverted()) ? g.NavWindow->NavRectRel[g.NavLayer] : ImRect(0,0,0,0);
 | 
				
			||||||
    g.NavScoringRectScreen = g.NavWindow ? ImRect(g.NavWindow->Pos + nav_rect_rel.Min, g.NavWindow->Pos + nav_rect_rel.Max) : GetViewportRect();
 | 
					    g.NavScoringRect = g.NavWindow ? ImRect(g.NavWindow->Pos + nav_rect_rel.Min, g.NavWindow->Pos + nav_rect_rel.Max) : GetViewportRect();
 | 
				
			||||||
    g.NavScoringRectScreen.TranslateY(nav_scoring_rect_offset_y);
 | 
					    g.NavScoringRect.TranslateY(nav_scoring_rect_offset_y);
 | 
				
			||||||
    g.NavScoringRectScreen.Min.x = ImMin(g.NavScoringRectScreen.Min.x + 1.0f, g.NavScoringRectScreen.Max.x);
 | 
					    g.NavScoringRect.Min.x = ImMin(g.NavScoringRect.Min.x + 1.0f, g.NavScoringRect.Max.x);
 | 
				
			||||||
    g.NavScoringRectScreen.Max.x = g.NavScoringRectScreen.Min.x;
 | 
					    g.NavScoringRect.Max.x = g.NavScoringRect.Min.x;
 | 
				
			||||||
    IM_ASSERT(!g.NavScoringRectScreen.IsInverted()); // Ensure if we have a finite, non-inverted bounding box here will allows us to remove extraneous ImFabs() calls in NavScoreItem().
 | 
					    IM_ASSERT(!g.NavScoringRect.IsInverted()); // Ensure if we have a finite, non-inverted bounding box here will allows us to remove extraneous ImFabs() calls in NavScoreItem().
 | 
				
			||||||
    //GetForegroundDrawList()->AddRect(g.NavScoringRectScreen.Min, g.NavScoringRectScreen.Max, IM_COL32(255,200,0,255)); // [DEBUG]
 | 
					    //GetForegroundDrawList()->AddRect(g.NavScoringRectScreen.Min, g.NavScoringRectScreen.Max, IM_COL32(255,200,0,255)); // [DEBUG]
 | 
				
			||||||
    g.NavScoringCount = 0;
 | 
					    g.NavScoringCount = 0;
 | 
				
			||||||
#if IMGUI_DEBUG_NAV_RECTS
 | 
					#if IMGUI_DEBUG_NAV_RECTS
 | 
				
			||||||
@@ -8706,7 +8707,7 @@ static void ImGui::NavUpdateMoveResult()
 | 
				
			|||||||
        // Don't set NavJustMovedToId if just landed on the same spot (which may happen with ImGuiNavMoveFlags_AllowCurrentNavId)
 | 
					        // Don't set NavJustMovedToId if just landed on the same spot (which may happen with ImGuiNavMoveFlags_AllowCurrentNavId)
 | 
				
			||||||
        g.NavJustMovedToId = result->ID;
 | 
					        g.NavJustMovedToId = result->ID;
 | 
				
			||||||
        g.NavJustMovedToFocusScopeId = result->FocusScopeId;
 | 
					        g.NavJustMovedToFocusScopeId = result->FocusScopeId;
 | 
				
			||||||
 | 
					        g.NavJustMovedToKeyMods = g.NavMoveRequestKeyMods;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    SetNavIDWithRectRel(result->ID, g.NavLayer, result->FocusScopeId, result->RectRel);
 | 
					    SetNavIDWithRectRel(result->ID, g.NavLayer, result->FocusScopeId, result->RectRel);
 | 
				
			||||||
    g.NavMoveFromClampedRefRect = false;
 | 
					    g.NavMoveFromClampedRefRect = false;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1098,9 +1098,10 @@ struct ImGuiContext
 | 
				
			|||||||
    ImGuiID                 NavJustTabbedId;                    // Just tabbed to this id.
 | 
					    ImGuiID                 NavJustTabbedId;                    // Just tabbed to this id.
 | 
				
			||||||
    ImGuiID                 NavJustMovedToId;                   // Just navigated to this id (result of a successfully MoveRequest).
 | 
					    ImGuiID                 NavJustMovedToId;                   // Just navigated to this id (result of a successfully MoveRequest).
 | 
				
			||||||
    ImGuiID                 NavJustMovedToFocusScopeId;         // Just navigated to this focus scope id (result of a successfully MoveRequest).
 | 
					    ImGuiID                 NavJustMovedToFocusScopeId;         // Just navigated to this focus scope id (result of a successfully MoveRequest).
 | 
				
			||||||
 | 
					    ImGuiKeyModFlags        NavJustMovedToKeyMods;
 | 
				
			||||||
    ImGuiID                 NavNextActivateId;                  // Set by ActivateItem(), queued until next frame.
 | 
					    ImGuiID                 NavNextActivateId;                  // Set by ActivateItem(), queued until next frame.
 | 
				
			||||||
    ImGuiInputSource        NavInputSource;                     // Keyboard or Gamepad mode? THIS WILL ONLY BE None or NavGamepad or NavKeyboard.
 | 
					    ImGuiInputSource        NavInputSource;                     // Keyboard or Gamepad mode? THIS WILL ONLY BE None or NavGamepad or NavKeyboard.
 | 
				
			||||||
    ImRect                  NavScoringRectScreen;               // Rectangle used for scoring, in screen space. Based of window->DC.NavRefRectRel[], modified for directional navigation scoring.
 | 
					    ImRect                  NavScoringRect;                     // Rectangle used for scoring, in screen space. Based of window->DC.NavRefRectRel[], modified for directional navigation scoring.
 | 
				
			||||||
    int                     NavScoringCount;                    // Metrics for debugging
 | 
					    int                     NavScoringCount;                    // Metrics for debugging
 | 
				
			||||||
    ImGuiNavLayer           NavLayer;                           // Layer we are navigating on. For now the system is hard-coded for 0=main contents and 1=menu/title bar, may expose layers later.
 | 
					    ImGuiNavLayer           NavLayer;                           // Layer we are navigating on. For now the system is hard-coded for 0=main contents and 1=menu/title bar, may expose layers later.
 | 
				
			||||||
    int                     NavIdTabCounter;                    // == NavWindow->DC.FocusIdxTabCounter at time of NavId processing
 | 
					    int                     NavIdTabCounter;                    // == NavWindow->DC.FocusIdxTabCounter at time of NavId processing
 | 
				
			||||||
@@ -1117,6 +1118,7 @@ struct ImGuiContext
 | 
				
			|||||||
    bool                    NavMoveRequest;                     // Move request for this frame
 | 
					    bool                    NavMoveRequest;                     // Move request for this frame
 | 
				
			||||||
    ImGuiNavMoveFlags       NavMoveRequestFlags;
 | 
					    ImGuiNavMoveFlags       NavMoveRequestFlags;
 | 
				
			||||||
    ImGuiNavForward         NavMoveRequestForward;              // None / ForwardQueued / ForwardActive (this is used to navigate sibling parent menus from a child menu)
 | 
					    ImGuiNavForward         NavMoveRequestForward;              // None / ForwardQueued / ForwardActive (this is used to navigate sibling parent menus from a child menu)
 | 
				
			||||||
 | 
					    ImGuiKeyModFlags        NavMoveRequestKeyMods;
 | 
				
			||||||
    ImGuiDir                NavMoveDir, NavMoveDirLast;         // Direction of the move request (left/right/up/down), direction of the previous move request
 | 
					    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?
 | 
					    ImGuiDir                NavMoveClipDir;                     // FIXME-NAV: Describe the purpose of this better. Might want to rename?
 | 
				
			||||||
    ImGuiNavMoveResult      NavMoveResultLocal;                 // Best move request candidate within NavWindow
 | 
					    ImGuiNavMoveResult      NavMoveResultLocal;                 // Best move request candidate within NavWindow
 | 
				
			||||||
@@ -1274,8 +1276,9 @@ struct ImGuiContext
 | 
				
			|||||||
        NavWindow = NULL;
 | 
					        NavWindow = NULL;
 | 
				
			||||||
        NavId = NavFocusScopeId = NavActivateId = NavActivateDownId = NavActivatePressedId = NavInputId = 0;
 | 
					        NavId = NavFocusScopeId = NavActivateId = NavActivateDownId = NavActivatePressedId = NavInputId = 0;
 | 
				
			||||||
        NavJustTabbedId = NavJustMovedToId = NavJustMovedToFocusScopeId = NavNextActivateId = 0;
 | 
					        NavJustTabbedId = NavJustMovedToId = NavJustMovedToFocusScopeId = NavNextActivateId = 0;
 | 
				
			||||||
 | 
					        NavJustMovedToKeyMods = ImGuiKeyModFlags_None;
 | 
				
			||||||
        NavInputSource = ImGuiInputSource_None;
 | 
					        NavInputSource = ImGuiInputSource_None;
 | 
				
			||||||
        NavScoringRectScreen = ImRect();
 | 
					        NavScoringRect = ImRect();
 | 
				
			||||||
        NavScoringCount = 0;
 | 
					        NavScoringCount = 0;
 | 
				
			||||||
        NavLayer = ImGuiNavLayer_Main;
 | 
					        NavLayer = ImGuiNavLayer_Main;
 | 
				
			||||||
        NavIdTabCounter = INT_MAX;
 | 
					        NavIdTabCounter = INT_MAX;
 | 
				
			||||||
@@ -1291,6 +1294,7 @@ struct ImGuiContext
 | 
				
			|||||||
        NavMoveRequest = false;
 | 
					        NavMoveRequest = false;
 | 
				
			||||||
        NavMoveRequestFlags = ImGuiNavMoveFlags_None;
 | 
					        NavMoveRequestFlags = ImGuiNavMoveFlags_None;
 | 
				
			||||||
        NavMoveRequestForward = ImGuiNavForward_None;
 | 
					        NavMoveRequestForward = ImGuiNavForward_None;
 | 
				
			||||||
 | 
					        NavMoveRequestKeyMods = ImGuiKeyModFlags_None;
 | 
				
			||||||
        NavMoveDir = NavMoveDirLast = NavMoveClipDir = ImGuiDir_None;
 | 
					        NavMoveDir = NavMoveDirLast = NavMoveClipDir = ImGuiDir_None;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        NavWindowingTarget = NavWindowingTargetAnim = NavWindowingList = NULL;
 | 
					        NavWindowingTarget = NavWindowingTargetAnim = NavWindowingList = NULL;
 | 
				
			||||||
@@ -1777,6 +1781,7 @@ namespace ImGui
 | 
				
			|||||||
    inline bool             IsKeyPressedMap(ImGuiKey key, bool repeat = true)           { ImGuiContext& g = *GImGui; const int key_index = g.IO.KeyMap[key]; return (key_index >= 0) ? IsKeyPressed(key_index, repeat) : false; }
 | 
					    inline bool             IsKeyPressedMap(ImGuiKey key, bool repeat = true)           { ImGuiContext& g = *GImGui; const int key_index = g.IO.KeyMap[key]; return (key_index >= 0) ? IsKeyPressed(key_index, repeat) : false; }
 | 
				
			||||||
    inline bool             IsNavInputDown(ImGuiNavInput n)                             { ImGuiContext& g = *GImGui; return g.IO.NavInputs[n] > 0.0f; }
 | 
					    inline bool             IsNavInputDown(ImGuiNavInput n)                             { ImGuiContext& g = *GImGui; return g.IO.NavInputs[n] > 0.0f; }
 | 
				
			||||||
    inline bool             IsNavInputTest(ImGuiNavInput n, ImGuiInputReadMode rm)      { return (GetNavInputAmount(n, rm) > 0.0f); }
 | 
					    inline bool             IsNavInputTest(ImGuiNavInput n, ImGuiInputReadMode rm)      { return (GetNavInputAmount(n, rm) > 0.0f); }
 | 
				
			||||||
 | 
					    IMGUI_API ImGuiKeyModFlags GetMergedKeyModFlags();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Drag and Drop
 | 
					    // Drag and Drop
 | 
				
			||||||
    IMGUI_API bool          BeginDragDropTargetCustom(const ImRect& bb, ImGuiID id);
 | 
					    IMGUI_API bool          BeginDragDropTargetCustom(const ImRect& bb, ImGuiID id);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3728,14 +3728,16 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
 | 
				
			|||||||
    if (g.ActiveId == id && !g.ActiveIdIsJustActivated && !clear_active_id)
 | 
					    if (g.ActiveId == id && !g.ActiveIdIsJustActivated && !clear_active_id)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        IM_ASSERT(state != NULL);
 | 
					        IM_ASSERT(state != NULL);
 | 
				
			||||||
 | 
					        IM_ASSERT(io.KeyMods == GetMergedKeyModFlags() && "Mismatching io.KeyCtrl/io.KeyShift/io.KeyAlt/io.KeySuper vs io.KeyMods"); // We rarely do this check, but if anything let's do it here.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const int k_mask = (io.KeyShift ? STB_TEXTEDIT_K_SHIFT : 0);
 | 
					        const int k_mask = (io.KeyShift ? STB_TEXTEDIT_K_SHIFT : 0);
 | 
				
			||||||
        const bool is_osx = io.ConfigMacOSXBehaviors;
 | 
					        const bool is_osx = io.ConfigMacOSXBehaviors;
 | 
				
			||||||
        const bool is_shortcut_key = (is_osx ? (io.KeySuper && !io.KeyCtrl) : (io.KeyCtrl && !io.KeySuper)) && !io.KeyAlt && !io.KeyShift; // OS X style: Shortcuts using Cmd/Super instead of Ctrl
 | 
					        const bool is_osx_shift_shortcut = is_osx && (io.KeyMods == (ImGuiKeyModFlags_Super | ImGuiKeyModFlags_Shift));
 | 
				
			||||||
        const bool is_osx_shift_shortcut = is_osx && io.KeySuper && io.KeyShift && !io.KeyCtrl && !io.KeyAlt;
 | 
					 | 
				
			||||||
        const bool is_wordmove_key_down = is_osx ? io.KeyAlt : io.KeyCtrl;                     // OS X style: Text editing cursor movement using Alt instead of Ctrl
 | 
					        const bool is_wordmove_key_down = is_osx ? io.KeyAlt : io.KeyCtrl;                     // OS X style: Text editing cursor movement using Alt instead of Ctrl
 | 
				
			||||||
        const bool is_startend_key_down = is_osx && io.KeySuper && !io.KeyCtrl && !io.KeyAlt;  // OS X style: Line/Text Start and End using Cmd+Arrows instead of Home/End
 | 
					        const bool is_startend_key_down = is_osx && io.KeySuper && !io.KeyCtrl && !io.KeyAlt;  // OS X style: Line/Text Start and End using Cmd+Arrows instead of Home/End
 | 
				
			||||||
        const bool is_ctrl_key_only = io.KeyCtrl && !io.KeyShift && !io.KeyAlt && !io.KeySuper;
 | 
					        const bool is_ctrl_key_only = (io.KeyMods == ImGuiKeyModFlags_Ctrl);
 | 
				
			||||||
        const bool is_shift_key_only = io.KeyShift && !io.KeyCtrl && !io.KeyAlt && !io.KeySuper;
 | 
					        const bool is_shift_key_only = (io.KeyMods == ImGuiKeyModFlags_Shift);
 | 
				
			||||||
 | 
					        const bool is_shortcut_key = g.IO.ConfigMacOSXBehaviors ? (io.KeyMods == ImGuiKeyModFlags_Super) : (io.KeyMods == ImGuiKeyModFlags_Ctrl);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const bool is_cut   = ((is_shortcut_key && IsKeyPressedMap(ImGuiKey_X)) || (is_shift_key_only && IsKeyPressedMap(ImGuiKey_Delete))) && !is_readonly && !is_password && (!is_multiline || state->HasSelection());
 | 
					        const bool is_cut   = ((is_shortcut_key && IsKeyPressedMap(ImGuiKey_X)) || (is_shift_key_only && IsKeyPressedMap(ImGuiKey_Delete))) && !is_readonly && !is_password && (!is_multiline || state->HasSelection());
 | 
				
			||||||
        const bool is_copy  = ((is_shortcut_key && IsKeyPressedMap(ImGuiKey_C)) || (is_ctrl_key_only  && IsKeyPressedMap(ImGuiKey_Insert))) && !is_password && (!is_multiline || state->HasSelection());
 | 
					        const bool is_copy  = ((is_shortcut_key && IsKeyPressedMap(ImGuiKey_C)) || (is_ctrl_key_only  && IsKeyPressedMap(ImGuiKey_Insert))) && !is_password && (!is_multiline || state->HasSelection());
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user