Skip to content

Commit

Permalink
--fixup fix an issue with mini-map interaction and node/link hovering
Browse files Browse the repository at this point in the history
Mini-map interaction and node/link/pin hovering interaction would clobber state related to one another.
Since minimap is drawn on top, disable hovering behavior when the mouse is over the minimap AND an node/link/pin.
  • Loading branch information
briancairl committed May 11, 2021
1 parent 521d3f2 commit 2e56e81
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions imnodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace ImNodes
{
namespace
{

// [SECTION] bezier curve helpers

struct BezierCurve
Expand Down Expand Up @@ -615,6 +616,8 @@ void BeginLinkCreation(ImNodesEditorContext& editor, const int hovered_pin_idx)
GImNodes->ImNodesUIState |= ImNodesUIState_LinkStarted;
}

static inline bool IsMiniMapHovered();

void BeginCanvasInteraction(ImNodesEditorContext& editor)
{
const bool any_ui_element_hovered =
Expand All @@ -632,7 +635,7 @@ void BeginCanvasInteraction(ImNodesEditorContext& editor)
const bool started_panning = GImNodes->AltMouseClicked;

// Handle mini-map interactions
if (ImGui::IsMouseHoveringRect(GImNodes->MiniMapRectScreenSpace.Min, GImNodes->MiniMapRectScreenSpace.Max))
if (IsMiniMapHovered())
{
if (started_panning)
{
Expand Down Expand Up @@ -1658,6 +1661,17 @@ void Shutdown(ImNodesContext* ctx) { EditorContextFree(ctx->DefaultEditorCtx); }

// [SECTION] minimap

static inline bool IsMiniMapActive()
{
return GImNodes->MiniMapRectScreenSpace.GetWidth() > 0.f;
}

static inline bool IsMiniMapHovered()
{
return IsMiniMapActive() &&
ImGui::IsMouseHoveringRect(GImNodes->MiniMapRectScreenSpace.Min, GImNodes->MiniMapRectScreenSpace.Max);
}

static inline ImRect ToMiniMapRect(const float minimap_size_fraction, const ImRect& editor_rect, const ImNodesMiniMapLocation location)
{
const ImVec2 editor_size(editor_rect.Max - editor_rect.Min);
Expand Down Expand Up @@ -1810,13 +1824,10 @@ static void MiniMapUpdate()
{
ImNodesEditorContext& editor = EditorContextGet();

const ImRect& mini_map_rect = GImNodes->MiniMapRectScreenSpace;

ImU32 mini_map_background;

// NOTE: use normal background when panning (typically opaque)
if (editor.ClickInteraction.Type != ImNodesClickInteractionType_MiniMapPanning &&
ImGui::IsMouseHoveringRect(mini_map_rect.Min, mini_map_rect.Max))
if (editor.ClickInteraction.Type != ImNodesClickInteractionType_MiniMapPanning && IsMiniMapHovered())
{
mini_map_background = GImNodes->Style.Colors[ImNodesCol_MiniMapBackgroundHovered];
}
Expand All @@ -1831,6 +1842,8 @@ static void MiniMapUpdate()
0.5f * (editor_rect.Min.x + editor_rect.Max.x),
0.5f * (editor_rect.Min.y + editor_rect.Max.y));

const ImRect& mini_map_rect = GImNodes->MiniMapRectScreenSpace;

const ImVec2 mini_map_center(
0.5f * (mini_map_rect.Min.x + mini_map_rect.Max.x),
0.5f * (mini_map_rect.Min.y + mini_map_rect.Max.y));
Expand Down Expand Up @@ -2157,7 +2170,10 @@ void EndNodeEditor()
// Detect which UI element is being hovered over. Detection is done in a hierarchical fashion,
// because a UI element being hovered excludes any other as being hovered over.

if (MouseInCanvas())
// Don't do hovering detection for nodes/links/pins when interacting with the mini-map, since
// its an *overlay* with its own interaction behavior and must have precedence during mouse interaction

if (MouseInCanvas() && !IsMiniMapHovered())
{
// Pins needs some special care. We need to check the depth stack to see which pins are
// being occluded by other nodes.
Expand Down Expand Up @@ -2212,7 +2228,7 @@ void EndNodeEditor()
}

// Mini-map rect will be set with non-zero width if MiniMap(...) was called
if (GImNodes->MiniMapRectScreenSpace.GetWidth() > 0.f)
if (IsMiniMapActive())
{
MiniMapUpdate();
}
Expand Down

0 comments on commit 2e56e81

Please sign in to comment.