imgui-node-editor icon indicating copy to clipboard operation
imgui-node-editor copied to clipboard

Margin to the node Rect for overlapping pins

Open TiberiusFaber opened this issue 2 years ago • 2 comments

We would need to apply margins to the node Rect in order to display the pins overlapping on the node itself. Outer pins could be drawn by applying horizontal and vertical layout, but these methods don't allow overlap. We have managed to find a workaround to the left most pins by adding padding, that seems to modify the position of the background node rect, but the right pins will always be either inside the node, or fall out of it. To achieve what we need it would be good to have a margin property, that could shrink the node and its borders by a given amount so we would have the desired visual results.

void ed::Node::Draw(ImDrawList* drawList, DrawFlags flags)
{
    auto& editorStyle = Editor->GetStyle();
    ImRect margin = editorStyle.NodeMargin;
    const ImRect bounds = ImRect(
        m_Bounds.Min.x + margin.Min.x,
        m_Bounds.Min.y + margin.Min.y,
        m_Bounds.Max.x - margin.Max.x,
        m_Bounds.Max.y - margin.Max.y
    );

...
        drawList->AddRectFilled(
            bounds.Min,
            bounds.Max,
            m_Color, 
            m_Rounding);

...
 DrawBorder(drawList, bounds, m_BorderColor, m_BorderWidth);

...
}

TiberiusFaber avatar Jul 27 '23 09:07 TiberiusFaber

With this code we can have the desired result as you can see in the next gif: widgets-example_d_qHoZwKGuBY

TiberiusFaber avatar Jul 27 '23 09:07 TiberiusFaber

Do I understand correctly that you want to use BeginHorizontal/Vertical to layout pins on the edge of the node?

For this case margin sound like good enhancement.

thedmd avatar Sep 01 '23 14:09 thedmd