I’m having an issue with a node in my application based largely on the RecordNode example provided. I can recreate the problem by modifying the example and adding the following two lines to the RecordNode constructor:
ListGroup.TopLeftMargin = new SizeF(0, 0);
ListGroup.BottomRightMargin = new SizeF(0, 0);
If I then:
Run the Demo1 example
Create a new document
Drag 2 RecordNodes into the document
Create a link between two RecordItem objects
Position the two RecordNodes side by side with 200 pixels between them
Resize the left RecordNode by dragging the right side
then the logic to calculate the Angle and LinkPoints for the SidewaysPort generate different results than expected and the link draws incorrectly.
It appears that the bounds for the RecordItem objects get calculated incorrectly when the left RecordNode is resized, but get calculated properly if either RecordNode is moved.
Is this the expected behaviour with a margins of (0, 0)? What can I do to recreate the behavior when the margins are the default of (2, 2)?
There does seem to be a glitch here when margins are zero. The link starts at the port and routes inward, not away from the node. (when the link is like this, select the link and the selection handles will show you what has happened.)
I need to use margins of 0 in order to get my node to draw correctly. Can you provide an estimate of how long it will take to fix this? I just need to get back to my client.
OK, here’s the fix. This is just a bug in the example. Replace RecordNode.LayoutChildren with:
// make sure each item's port occupies the same bounds as the item
public override void LayoutChildren(GoObject childchanged) {
if (this.Initializing) return;
GoListGroup lg = this.ListGroup;
float left = lg.Left + lg.TopLeftMargin.Width;
float width = lg.Width - lg.TopLeftMargin.Width - lg.BottomRightMargin.Width;
for (int i = 1; i < this.ItemCount; i++) {
GoObject item = GetItem(i);
GoObject rightp = GetRightPort(i); // just one port per item, the "Right" one
if (item != null && rightp != null) {
RectangleF rect = new RectangleF(left, item.Bounds.Top, width, item.Bounds.Height);
rightp.Bounds = rect;
}
}
}
As a further improvement, you may want to use BoxNodePort instead of SidewaysPort:
public override GoObject CreatePort(bool left, int idx) {
if (left) return null;
if (idx == 0) return null;
GoBoxPort p = new GoBoxPort();
p.Style = GoPortStyle.None;
p.AutoRescales = false;
p.FromSides = MiddleLeft | MiddleRight;
p.ToSides = MiddleLeft | MiddleRight;
return p;
}
if you like that better, you can delete SidewaysPort from the RecordNode file.