I want to move the label of GoSimpleNode to any position. I have read that there is a constraint that enforced in setting GoObject.Bound or GoGroup.LayoutChildren. Can I disallow this constraints??
GoIconicNode has a “DraggableLabel” property that you can set to true.
Check the “Processor” sample for a use of that.
It may be easier to emulate a GoSimpleNode with the Processor node and ports than to add
draggable labels to GoSimpleNode.
ok… I haven’t spent a lot of time on this, but here is the DraggableLabel code from GoIconicNode pasted into a GoSimpleNode override.
[Serializable]
public class GoSimpleNodeWithDraggableLabel : GoSimpleNode
{
protected override GoText CreateLabel(string name) {
GoText l = base.CreateLabel(name);
l.Selectable = this.DraggableLabel;
return l;
}
public override void LayoutChildren(GoObject childchanged) {
if (this.Initializing) return;
GoObject icon = this.Icon;
if (icon == null) return;
if (this.Orientation == Orientation.Horizontal) {
if (this.InPort != null)
this.InPort.SetSpotLocation(MiddleRight, icon, MiddleLeft);
if (this.OutPort != null)
this.OutPort.SetSpotLocation(MiddleLeft, icon, MiddleRight);
}
else {
if (this.InPort != null)
this.InPort.SetSpotLocation(MiddleBottom, icon, MiddleTop);
if (this.OutPort != null)
this.OutPort.SetSpotLocation(MiddleTop, icon, MiddleBottom);
}
GoText label = this.Label;
if (label != null) {
// if DraggableLabel is true, let the user drag it around without moving
// any other children of this node
if (this.DraggableLabel && childchanged == label) {
// remember where the label now is relative to the icon
myLabelOffset = new SizeF(label.Left - icon.Left, label.Top - icon.Top);
return; // don't position port or anything else
}
else if (myLabelOffset.Width > -99999) { // place it relative to the icon
label.Position = new PointF(icon.Left + myLabelOffset.Width, icon.Top + myLabelOffset.Height);
}
else { // put the label below the icon
label.SetSpotLocation(MiddleTop, icon, MiddleBottom);
}
}
}
/// <summary>
/// Gets or sets whether the user can drag the label around independently of the node.
/// </summary>
/// <value>
/// Initially this value is false--the label is always positioned by
/// <see cref="LayoutChildren"/> and users cannot move the
/// label without moving the whole node.
/// </value>
public virtual bool DraggableLabel {
get { return myDraggableLabel; }
set {
bool old = myDraggableLabel;
if (old != value) {
myDraggableLabel = value;
Changed(ChangedDraggableLabel, 0, old, NullRect, 0, value, NullRect);
if (!this.Initializing && this.Label != null)
this.Label.Selectable = value;
}
}
}
/// <summary>
/// Gets or sets the relative position of the <see cref="Label"/>'s position
/// compared to the <see cref="Icon"/>'s position.
/// </summary>
/// <value>
/// A very large negative offset causes <see cref="LayoutChildren"/> to
/// ignore this value, resulting in the <see cref="Label"/> being
/// placed underneath the <see cref="Icon"/>.
/// </value>
/// <remarks>
/// This is automatically updated if the <see cref="DraggableLabel"/> is
/// true and the user drags the label around.
/// </remarks>
public virtual SizeF LabelOffset {
get { return myLabelOffset; }
set {
SizeF old = myLabelOffset;
if (old != value) {
myLabelOffset = value;
Changed(ChangedLabelOffset, 0, null, MakeRect(old), 0, null, MakeRect(value));
if (!this.Initializing) {
LayoutChildren(null);
}
}
}
}
public override void ChangeValue(GoChangedEventArgs e, bool undo) {
switch (e.SubHint) {
case ChangedDraggableLabel:
this.DraggableLabel = (bool)e.GetValue(undo);
return;
default:
base.ChangeValue(e, undo);
return;
}
}
public const int ChangedDraggableLabel = 2651;
public const int ChangedLabelOffset = 2655;
private bool myDraggableLabel = false;
private SizeF myLabelOffset = new SizeF(-99999, -99999); // used when Width > -99999
}