LayoutEditor.cs 1.9 KB

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