LayoutEditor.cs 1.9 KB

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