public DragableContainer(Vector2 size, DragableControl controlInContainer = null, string name = null) { this.Size = size; if (namesInUse.Contains(name)) throw new Exception("WARNING: CONFLICTING CONTAINER NAMES!"); if (!string.IsNullOrWhiteSpace(name)) namesInUse.Add(name); this.name = name; this.controlInContainer = controlInContainer; SetDragableControl(controlInContainer); myID = id++; }
/// <summary> /// Sets the dragable control to be contained. /// </summary> /// <param name="controlToSet">The new control to be contained in this container.</param> /// <returns>The old control contained.</returns> public DragableControl SetDragableControl(DragableControl controlToSet) { //Console.WriteLine("OLD: {1} NEW: {0}", controlToSet.Item.name, this.controlInContainer.Item.name); // if given nothing, dont set anything. if (controlToSet == null) return null; // should this even EVER happen? if (controlToSet == controlInContainer) { controlToSet.Location = Vector2.Zero; return null; //return controlToSet; } DragableControl controlToReplace = controlInContainer; // Clear this container. // Clear the continar this came from. // this assumes the parent is the dragable container! if (controlToSet.parent != null) controlToSet.parent.Clear(); Clear(); // All controls should be centered in their container... controlInContainer = controlToSet; controlInContainer.Location = Vector2.Zero; controlInContainer.Alignment = ControlAlignment.Center; //controlInContainer.parent = this; Add(controlInContainer); if (controlToReplace != null) controlToReplace.parent = null; return controlToReplace; // parent for controlToReplace is still this. // controlToReplace is no longer in this container. }
public override void Clear() { controlInContainer = null; base.Clear(); }