mirror of
https://github.com/ocornut/imgui.git
synced 2024-12-12 20:19:02 +08:00
Nav: Comments
This commit is contained in:
parent
5a9ebeca9e
commit
cf3b21179b
@ -2035,7 +2035,6 @@ static float NavScoreItemDistInterval(float a0, float a1, float b0, float b1)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Scoring function for directional navigation. Based on https://gist.github.com/rygorous/6981057
|
// Scoring function for directional navigation. Based on https://gist.github.com/rygorous/6981057
|
||||||
// FIXME-NAVIGATION: Pretty rough. Also may want to handle the degenerate case that we have commented out.
|
|
||||||
static bool NavScoreItem(ImRect cand)
|
static bool NavScoreItem(ImRect cand)
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
@ -2043,7 +2042,7 @@ static bool NavScoreItem(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 lots of items with varied width)
|
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)
|
||||||
|
|
||||||
// We perform scoring on items bounding box clipped by their parent window on the other axis (clipping on our movement axis would give us equal scores for all clipped items)
|
// We perform scoring on items bounding box clipped by their parent window on the other axis (clipping on our movement axis would give us equal scores for all clipped items)
|
||||||
if (g.NavMoveDir == ImGuiDir_Left || g.NavMoveDir == ImGuiDir_Right)
|
if (g.NavMoveDir == ImGuiDir_Left || g.NavMoveDir == ImGuiDir_Right)
|
||||||
@ -2058,7 +2057,7 @@ static bool NavScoreItem(ImRect cand)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Compute distance between boxes
|
// Compute distance between boxes
|
||||||
// FIXME-NAVIGATION: Introducing various biases toward typical imgui uses cases, but we don't have any rigorous proof of their side-effect..
|
// FIXME-NAVIGATION: Introducing biases for vertical navigation, needs to be removed.
|
||||||
float dbx = NavScoreItemDistInterval(cand.Min.x, cand.Max.x, curr.Min.x, curr.Max.x);
|
float dbx = NavScoreItemDistInterval(cand.Min.x, cand.Max.x, curr.Min.x, curr.Max.x);
|
||||||
float dby = NavScoreItemDistInterval(ImLerp(cand.Min.y, cand.Max.y, 0.2f), ImLerp(cand.Min.y, cand.Max.y, 0.8f), ImLerp(curr.Min.y, curr.Max.y, 0.2f), ImLerp(curr.Min.y, curr.Max.y, 0.8f)); // Scale down on Y to keep using box-distance for vertically touching items
|
float dby = NavScoreItemDistInterval(ImLerp(cand.Min.y, cand.Max.y, 0.2f), ImLerp(cand.Min.y, cand.Max.y, 0.8f), ImLerp(curr.Min.y, curr.Max.y, 0.2f), ImLerp(curr.Min.y, curr.Max.y, 0.8f)); // Scale down on Y to keep using box-distance for vertically touching items
|
||||||
if (dby && dbx)
|
if (dby && dbx)
|
||||||
@ -2127,7 +2126,7 @@ static bool NavScoreItem(ImRect cand)
|
|||||||
}
|
}
|
||||||
else if (dist_center == g.NavMoveResultDistCenter)
|
else if (dist_center == g.NavMoveResultDistCenter)
|
||||||
{
|
{
|
||||||
// Still tied! we need to be extra-careful to make sure everything gets linked properly. We consistently break ties by symbolically moving "later" buttons
|
// Still tied! we need to be extra-careful to make sure everything gets linked properly. We consistently break ties by symbolically moving "later" items
|
||||||
// (with higher index) to the right/downwards by an infinitesimal amount since we the current "best" button already (so it must have a lower index),
|
// (with higher index) to the right/downwards by an infinitesimal amount since we the current "best" button already (so it must have a lower index),
|
||||||
// this is fairly easy. This rule ensures that all buttons with dx==dy==0 will end up being linked in order of appearance along the x axis.
|
// this is fairly easy. This rule ensures that all buttons with dx==dy==0 will end up being linked in order of appearance along the x axis.
|
||||||
if (((g.NavMoveDir == ImGuiDir_Up || g.NavMoveDir == ImGuiDir_Down) ? dby : dbx) < 0.0f) // moving bj to the right/down decreases distance
|
if (((g.NavMoveDir == ImGuiDir_Up || g.NavMoveDir == ImGuiDir_Down) ? dby : dbx) < 0.0f) // moving bj to the right/down decreases distance
|
||||||
@ -2167,7 +2166,7 @@ void ImGui::RenderNavHighlight(const ImRect& bb, ImGuiID id)
|
|||||||
|
|
||||||
// Declare item bounding box for clipping and interaction.
|
// Declare item bounding box for clipping and interaction.
|
||||||
// Note that the size can be different than the one provided to ItemSize(). Typically, widgets that spread over available surface
|
// Note that the size can be different than the one provided to ItemSize(). Typically, widgets that spread over available surface
|
||||||
// declares their minimum size requirement to ItemSize() and then use a larger region for drawing/interaction, which is passed to ItemAdd().
|
// declare their minimum size requirement to ItemSize() and then use a larger region for drawing/interaction, which is passed to ItemAdd().
|
||||||
bool ImGui::ItemAdd(const ImRect& bb, const ImGuiID* id, const ImRect* nav_bb_arg)
|
bool ImGui::ItemAdd(const ImRect& bb, const ImGuiID* id, const ImRect* nav_bb_arg)
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
|
Loading…
Reference in New Issue
Block a user