mirror of
https://github.com/ocornut/imgui.git
synced 2024-11-27 16:29:02 +08:00
Nav: Forwarded (wrap/loop) request don't mistakenly wreck reference pos.
Amend 6656553
This commit is contained in:
parent
430c05991c
commit
bcfc1ad8f6
26
imgui.cpp
26
imgui.cpp
@ -10671,7 +10671,7 @@ void ImGui::SetFocusID(ImGuiID id, ImGuiWindow* window)
|
|||||||
NavClearPreferredPosForAxis(ImGuiAxis_Y);
|
NavClearPreferredPosForAxis(ImGuiAxis_Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGuiDir ImGetDirQuadrantFromDelta(float dx, float dy)
|
static ImGuiDir ImGetDirQuadrantFromDelta(float dx, float dy)
|
||||||
{
|
{
|
||||||
if (ImFabs(dx) > ImFabs(dy))
|
if (ImFabs(dx) > ImFabs(dy))
|
||||||
return (dx > 0.0f) ? ImGuiDir_Right : ImGuiDir_Left;
|
return (dx > 0.0f) ? ImGuiDir_Right : ImGuiDir_Left;
|
||||||
@ -11044,7 +11044,8 @@ void ImGui::NavMoveRequestTryWrapping(ImGuiWindow* window, ImGuiNavMoveFlags wra
|
|||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
IM_ASSERT((wrap_flags & ImGuiNavMoveFlags_WrapMask_ ) != 0 && (wrap_flags & ~ImGuiNavMoveFlags_WrapMask_) == 0); // Call with _WrapX, _WrapY, _LoopX, _LoopY
|
IM_ASSERT((wrap_flags & ImGuiNavMoveFlags_WrapMask_ ) != 0 && (wrap_flags & ~ImGuiNavMoveFlags_WrapMask_) == 0); // Call with _WrapX, _WrapY, _LoopX, _LoopY
|
||||||
|
|
||||||
// In theory we should test for NavMoveRequestButNoResultYet() but there's no point doing it, NavEndFrame() will do the same test
|
// In theory we should test for NavMoveRequestButNoResultYet() but there's no point doing it:
|
||||||
|
// as NavEndFrame() will do the same test. It will end up calling NavUpdateCreateWrappingRequest().
|
||||||
if (g.NavWindow == window && g.NavMoveScoringItems && g.NavLayer == ImGuiNavLayer_Main)
|
if (g.NavWindow == window && g.NavMoveScoringItems && g.NavLayer == ImGuiNavLayer_Main)
|
||||||
g.NavMoveFlags = (g.NavMoveFlags & ~ImGuiNavMoveFlags_WrapMask_) | wrap_flags;
|
g.NavMoveFlags = (g.NavMoveFlags & ~ImGuiNavMoveFlags_WrapMask_) | wrap_flags;
|
||||||
}
|
}
|
||||||
@ -11369,7 +11370,7 @@ void ImGui::NavInitRequestApplyResult()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Bias scoring rect ahead of scoring + update preferred pos (if missing) using source position
|
// Bias scoring rect ahead of scoring + update preferred pos (if missing) using source position
|
||||||
static void NavBiasScoringRect(ImRect& r, ImVec2& preferred_pos_rel, ImGuiDir move_dir)
|
static void NavBiasScoringRect(ImRect& r, ImVec2& preferred_pos_rel, ImGuiDir move_dir, ImGuiNavMoveFlags move_flags)
|
||||||
{
|
{
|
||||||
// Bias initial rect
|
// Bias initial rect
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
@ -11378,15 +11379,18 @@ static void NavBiasScoringRect(ImRect& r, ImVec2& preferred_pos_rel, ImGuiDir mo
|
|||||||
// Initialize bias on departure if we don't have any. So mouse-click + arrow will record bias.
|
// Initialize bias on departure if we don't have any. So mouse-click + arrow will record bias.
|
||||||
// - We default to L/U bias, so moving down from a large source item into several columns will land on left-most column.
|
// - We default to L/U bias, so moving down from a large source item into several columns will land on left-most column.
|
||||||
// - But each successful move sets new bias on one axis, only cleared when using mouse.
|
// - But each successful move sets new bias on one axis, only cleared when using mouse.
|
||||||
if (preferred_pos_rel.x == FLT_MAX)
|
if ((move_flags & ImGuiNavMoveFlags_Forwarded) == 0)
|
||||||
preferred_pos_rel.x = ImMin(r.Min.x + 1.0f, r.Max.x) - rel_to_abs_offset.x;
|
{
|
||||||
if (preferred_pos_rel.y == FLT_MAX)
|
if (preferred_pos_rel.x == FLT_MAX)
|
||||||
preferred_pos_rel.y = r.GetCenter().y - rel_to_abs_offset.y;
|
preferred_pos_rel.x = ImMin(r.Min.x + 1.0f, r.Max.x) - rel_to_abs_offset.x;
|
||||||
|
if (preferred_pos_rel.y == FLT_MAX)
|
||||||
|
preferred_pos_rel.y = r.GetCenter().y - rel_to_abs_offset.y;
|
||||||
|
}
|
||||||
|
|
||||||
// Apply general bias on the other axis
|
// Apply general bias on the other axis
|
||||||
if (move_dir == ImGuiDir_Up || move_dir == ImGuiDir_Down)
|
if ((move_dir == ImGuiDir_Up || move_dir == ImGuiDir_Down) && preferred_pos_rel.x != FLT_MAX)
|
||||||
r.Min.x = r.Max.x = preferred_pos_rel.x + rel_to_abs_offset.x;
|
r.Min.x = r.Max.x = preferred_pos_rel.x + rel_to_abs_offset.x;
|
||||||
else
|
else if ((move_dir == ImGuiDir_Left || move_dir == ImGuiDir_Right) && preferred_pos_rel.y != FLT_MAX)
|
||||||
r.Min.y = r.Max.y = preferred_pos_rel.y + rel_to_abs_offset.y;
|
r.Min.y = r.Max.y = preferred_pos_rel.y + rel_to_abs_offset.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -11497,7 +11501,7 @@ void ImGui::NavUpdateCreateMoveRequest()
|
|||||||
scoring_rect = WindowRectRelToAbs(window, nav_rect_rel);
|
scoring_rect = WindowRectRelToAbs(window, nav_rect_rel);
|
||||||
scoring_rect.TranslateY(scoring_rect_offset_y);
|
scoring_rect.TranslateY(scoring_rect_offset_y);
|
||||||
if (g.NavMoveSubmitted)
|
if (g.NavMoveSubmitted)
|
||||||
NavBiasScoringRect(scoring_rect, window->RootWindowForNav->NavPreferredScoringPosRel[g.NavLayer], g.NavMoveDir);
|
NavBiasScoringRect(scoring_rect, window->RootWindowForNav->NavPreferredScoringPosRel[g.NavLayer], g.NavMoveDir, g.NavMoveFlags);
|
||||||
IM_ASSERT(!scoring_rect.IsInverted()); // Ensure if we have a finite, non-inverted bounding box here will allow us to remove extraneous ImFabs() calls in NavScoreItem().
|
IM_ASSERT(!scoring_rect.IsInverted()); // Ensure if we have a finite, non-inverted bounding box here will allow us to remove extraneous ImFabs() calls in NavScoreItem().
|
||||||
//GetForegroundDrawList()->AddRect(scoring_rect.Min, scoring_rect.Max, IM_COL32(255,200,0,255)); // [DEBUG]
|
//GetForegroundDrawList()->AddRect(scoring_rect.Min, scoring_rect.Max, IM_COL32(255,200,0,255)); // [DEBUG]
|
||||||
//if (!g.NavScoringNoClipRect.IsInverted()) { GetForegroundDrawList()->AddRect(g.NavScoringNoClipRect.Min, g.NavScoringNoClipRect.Max, IM_COL32(255, 200, 0, 255)); } // [DEBUG]
|
//if (!g.NavScoringNoClipRect.IsInverted()) { GetForegroundDrawList()->AddRect(g.NavScoringNoClipRect.Min, g.NavScoringNoClipRect.Max, IM_COL32(255, 200, 0, 255)); } // [DEBUG]
|
||||||
@ -11785,7 +11789,9 @@ static void ImGui::NavUpdateCreateWrappingRequest()
|
|||||||
bool do_forward = false;
|
bool do_forward = false;
|
||||||
ImRect bb_rel = window->NavRectRel[g.NavLayer];
|
ImRect bb_rel = window->NavRectRel[g.NavLayer];
|
||||||
ImGuiDir clip_dir = g.NavMoveDir;
|
ImGuiDir clip_dir = g.NavMoveDir;
|
||||||
|
|
||||||
const ImGuiNavMoveFlags move_flags = g.NavMoveFlags;
|
const ImGuiNavMoveFlags move_flags = g.NavMoveFlags;
|
||||||
|
//const ImGuiAxis move_axis = (g.NavMoveDir == ImGuiDir_Up || g.NavMoveDir == ImGuiDir_Down) ? ImGuiAxis_Y : ImGuiAxis_X;
|
||||||
if (g.NavMoveDir == ImGuiDir_Left && (move_flags & (ImGuiNavMoveFlags_WrapX | ImGuiNavMoveFlags_LoopX)))
|
if (g.NavMoveDir == ImGuiDir_Left && (move_flags & (ImGuiNavMoveFlags_WrapX | ImGuiNavMoveFlags_LoopX)))
|
||||||
{
|
{
|
||||||
bb_rel.Min.x = bb_rel.Max.x = window->ContentSize.x + window->WindowPadding.x;
|
bb_rel.Min.x = bb_rel.Max.x = window->ContentSize.x + window->WindowPadding.x;
|
||||||
|
6
imgui.h
6
imgui.h
@ -21,9 +21,9 @@
|
|||||||
// please post in https://github.com/ocornut/imgui/discussions if you cannot find a solution in resources above.
|
// please post in https://github.com/ocornut/imgui/discussions if you cannot find a solution in resources above.
|
||||||
|
|
||||||
// Library Version
|
// Library Version
|
||||||
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM > 12345')
|
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM >= 12345')
|
||||||
#define IMGUI_VERSION "1.89.6 WIP"
|
#define IMGUI_VERSION "1.89.6 WIP"
|
||||||
#define IMGUI_VERSION_NUM 18956
|
#define IMGUI_VERSION_NUM 18957
|
||||||
#define IMGUI_HAS_TABLE
|
#define IMGUI_HAS_TABLE
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -479,7 +479,6 @@ IMGUI_API bool ImTriangleContainsPoint(const ImVec2& a, const ImVec2& b, c
|
|||||||
IMGUI_API ImVec2 ImTriangleClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p);
|
IMGUI_API ImVec2 ImTriangleClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p);
|
||||||
IMGUI_API void ImTriangleBarycentricCoords(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p, float& out_u, float& out_v, float& out_w);
|
IMGUI_API void ImTriangleBarycentricCoords(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& p, float& out_u, float& out_v, float& out_w);
|
||||||
inline float ImTriangleArea(const ImVec2& a, const ImVec2& b, const ImVec2& c) { return ImFabs((a.x * (b.y - c.y)) + (b.x * (c.y - a.y)) + (c.x * (a.y - b.y))) * 0.5f; }
|
inline float ImTriangleArea(const ImVec2& a, const ImVec2& b, const ImVec2& c) { return ImFabs((a.x * (b.y - c.y)) + (b.x * (c.y - a.y)) + (c.x * (a.y - b.y))) * 0.5f; }
|
||||||
IMGUI_API ImGuiDir ImGetDirQuadrantFromDelta(float dx, float dy);
|
|
||||||
|
|
||||||
// Helper: ImVec1 (1D vector)
|
// Helper: ImVec1 (1D vector)
|
||||||
// (this odd construct is used to facilitate the transition between 1D and 2D, and the maintenance of some branches/patches)
|
// (this odd construct is used to facilitate the transition between 1D and 2D, and the maintenance of some branches/patches)
|
||||||
|
Loading…
Reference in New Issue
Block a user