PanelControl.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //-----------------------------------------------------------------------------
  2. // PanelControl.cs
  3. //
  4. // Microsoft XNA Community Game Platform
  5. // Copyright (C) Microsoft Corporation. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. using Microsoft.Xna.Framework;
  8. namespace UserInterfaceSample.Controls
  9. {
  10. public class PanelControl : Control
  11. {
  12. // Position child components in a column, with the given spacing between components
  13. public void LayoutColumn(float xMargin, float yMargin, float ySpacing)
  14. {
  15. float y = yMargin;
  16. for (int i = 0; i < ChildCount; i++)
  17. {
  18. Control child = this[i];
  19. child.Position = new Vector2 { X = xMargin, Y = y };
  20. y += child.Size.Y + ySpacing;
  21. }
  22. InvalidateAutoSize();
  23. }
  24. // Position child components in a row, with the given spacing between components
  25. public void LayoutRow(float xMargin, float yMargin, float xSpacing)
  26. {
  27. float x = xMargin;
  28. for (int i = 0; i < ChildCount; i++)
  29. {
  30. Control child = this[i];
  31. child.Position = new Vector2 { X = x, Y = yMargin };
  32. x += child.Size.X + xSpacing;
  33. }
  34. InvalidateAutoSize();
  35. }
  36. }
  37. }