LayoutEditor.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #nullable enable
  2. namespace UICatalog.Scenarios;
  3. /// <summary>
  4. /// Provides an editor UI for the Margin, Border, and Padding of a View.
  5. /// </summary>
  6. public class LayoutEditor : EditorBase
  7. {
  8. public LayoutEditor ()
  9. {
  10. Title = "_LayoutEditor";
  11. CanFocus = true;
  12. Initialized += LayoutEditor_Initialized;
  13. }
  14. private PosEditor? _xEditor;
  15. private PosEditor? _yEditor;
  16. private DimEditor? _widthEditor;
  17. private DimEditor? _heightEditor;
  18. protected override void OnViewToEditChanged ()
  19. {
  20. if (_xEditor is { })
  21. {
  22. _xEditor.ViewToEdit = ViewToEdit;
  23. }
  24. if (_yEditor is { })
  25. {
  26. _yEditor.ViewToEdit = ViewToEdit;
  27. }
  28. if (_widthEditor is { })
  29. {
  30. _widthEditor.ViewToEdit = ViewToEdit;
  31. }
  32. if (_heightEditor is { })
  33. {
  34. _heightEditor.ViewToEdit = ViewToEdit;
  35. }
  36. }
  37. private void LayoutEditor_Initialized (object? sender, EventArgs e)
  38. {
  39. _xEditor = new ()
  40. {
  41. Title = "_X",
  42. BorderStyle = LineStyle.None,
  43. Dimension = Dimension.Width
  44. };
  45. _yEditor = new ()
  46. {
  47. Title = "_Y",
  48. BorderStyle = LineStyle.None,
  49. Dimension = Dimension.Height,
  50. X = Pos.Right (_xEditor) + 1
  51. };
  52. _widthEditor = new ()
  53. {
  54. Title = "_Width",
  55. BorderStyle = LineStyle.None,
  56. Dimension = Dimension.Width,
  57. X = Pos.Right (_yEditor) + 1
  58. };
  59. _heightEditor = new ()
  60. {
  61. Title = "_Height",
  62. BorderStyle = LineStyle.None,
  63. Dimension = Dimension.Height,
  64. X = Pos.Right (_widthEditor) + 1
  65. };
  66. Add (_xEditor, _yEditor, _widthEditor, _heightEditor);
  67. }
  68. }