private void PopulateWithFakeData() { PanelControl newList = new PanelControl(); Random rng = new Random(); for (int i = 0; i < 50; i++) { long score = 10000 - i * 10; TimeSpan time = TimeSpan.FromSeconds(rng.Next(60, 3600)); newList.AddChild(CreateLeaderboardEntryControl("player" + i.ToString(), score, time)); } newList.LayoutColumn(0, 0, 0); if (resultListControl != null) { RemoveChild(resultListControl); } resultListControl = newList; AddChild(resultListControl); LayoutColumn(0, 0, 0); }
/// <summary> /// Called after a child control is removed from this control. The default behavior is to call InvalidateAutoSize(). /// </summary> protected virtual void OnChildRemoved(int index, Control child) { InvalidateAutoSize(); }
/// <summary> /// Remove the given control from this control's list of children. /// </summary> public void RemoveChild(Control child) { if(child.Parent != this) throw new InvalidOperationException(); RemoveChildAt(children.IndexOf(child)); }
public void AddChild(Control child, int index) { if (child.Parent != null) { child.Parent.RemoveChild(child); } child.Parent = this; if (children == null) { children = new List<Control>(); } children.Insert(index, child); OnChildAdded(index, child); }
public void AddChild(Control child) { if (child.Parent != null) { child.Parent.RemoveChild(child); } AddChild(child, ChildCount); }
// Call this method once per frame on the root of your control heirarchy to draw all the controls. // See ControlScreen for an example. public static void BatchDraw(Control control, GraphicsDevice device, SpriteBatch spriteBatch, Vector2 offset, GameTime gameTime) { if (control != null && control.Visible) { spriteBatch.Begin(); control.Draw(new DrawContext { Device = device, SpriteBatch = spriteBatch, DrawOffset = offset + control.Position, GameTime = gameTime }); spriteBatch.End(); } }