thedmd / imgui-node-editor

Node Editor built using Dear ImGui
MIT License
3.73k stars 551 forks source link

Margin to the node Rect for overlapping pins #247

Open TiberiusFaber opened 1 year ago

TiberiusFaber commented 1 year ago

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 commented 1 year ago

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

thedmd commented 1 year ago

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.