Container.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. using NStack;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Xml.Linq;
  6. using Terminal.Gui.Graphs;
  7. namespace Terminal.Gui {
  8. public class Frame : View {
  9. public Frame ()
  10. {
  11. IgnoreBorderPropertyOnRedraw = true;
  12. }
  13. public virtual void OnDrawSubViews (Rect clipRect)
  14. {
  15. // if (Subviews == null) {
  16. // return;
  17. // }
  18. // foreach (var view in Subviews) {
  19. // // BUGBUG: v2 - shouldn't this be !view.LayoutNeeded? Why draw if layout is going to happen and we'll just draw again?
  20. // if (view.LayoutNeeded) {
  21. // view.LayoutSubviews ();
  22. // }
  23. // if ((view.Visible && !view.NeedDisplay.IsEmpty && view.Frame.Width > 0 && view.Frame.Height > 0) || view.ChildNeedsDisplay) {
  24. // view.Redraw (view.Bounds);
  25. // view.NeedDisplay = Rect.Empty;
  26. // // BUGBUG - v2 why does this need to be set to false?
  27. // // Shouldn't it be set when the subviews draw?
  28. // view.ChildNeedsDisplay = false;
  29. // }
  30. // }
  31. }
  32. public override void OnDrawContent (Rect viewport)
  33. {
  34. if (!ustring.IsNullOrEmpty (TextFormatter.Text)) {
  35. Clear (viewport);
  36. SetChildNeedsDisplay ();
  37. // Draw any Text
  38. if (TextFormatter != null) {
  39. TextFormatter.NeedsFormat = true;
  40. Rect containerBounds = GetContainerBounds ();
  41. TextFormatter?.Draw (ViewToScreen (viewport), HasFocus ? ColorScheme.Focus : GetNormalColor (),
  42. HasFocus ? ColorScheme.HotFocus : Enabled ? ColorScheme.HotNormal : ColorScheme.Disabled,
  43. containerBounds);
  44. }
  45. }
  46. }
  47. public override void Redraw (Rect bounds)
  48. {
  49. //OnDrawContent (bounds);
  50. //OnDrawSubViews (bounds);
  51. //OnDrawContentComplete (bounds);
  52. if (ColorScheme != null) {
  53. Driver.SetAttribute (ColorScheme.Normal);
  54. }
  55. Thickness.Draw (Frame, (string)Data);
  56. //OnDrawContent (bounds);
  57. //if (Text != null) {
  58. // Thickness?.Draw (Frame, $"{Text} {DiagnosticsLabel?.Text}");
  59. //}
  60. if (BorderStyle != BorderStyle.None) {
  61. var lc = new LineCanvas ();
  62. lc.AddLine (Frame.Location, Frame.Width - 1, Orientation.Horizontal, BorderStyle);
  63. lc.AddLine (Frame.Location, Frame.Height - 1, Orientation.Vertical, BorderStyle);
  64. lc.AddLine (new Point (Frame.X, Frame.Y + Frame.Height - 1), Frame.Width - 1, Orientation.Horizontal, BorderStyle);
  65. lc.AddLine (new Point (Frame.X + Frame.Width - 1, Frame.Y), Frame.Height - 1, Orientation.Vertical, BorderStyle);
  66. foreach (var p in lc.GenerateImage (Frame)) {
  67. Driver.Move (p.Key.X, p.Key.Y);
  68. Driver.AddRune (p.Value);
  69. }
  70. if (!ustring.IsNullOrEmpty (Title)) {
  71. Driver.DrawWindowTitle (Frame, Title, 0, 0, 0, 0);
  72. }
  73. }
  74. }
  75. //public Label DiagnosticsLabel { get; set; }
  76. // TODO: v2 = This is teporary; need to also enable (or not) simple way of setting
  77. // other border properties
  78. // TOOD: v2 - Missing 3D effect
  79. public BorderStyle BorderStyle { get; set; } = BorderStyle.None;
  80. public Thickness Thickness { get; set; }
  81. // TODO: v2 - This is confusing. It is a read-only property and actually only returns a size, so
  82. // should not be a Rect. However, it may make sense to keep it a Rect and support negative Location
  83. // for scrolling. Still noodling this.
  84. /// <summary>
  85. /// Gets the rectangle that describes the inner area of the frame. The Location is always 0, 0.
  86. /// </summary>
  87. public new Rect Bounds {
  88. get {
  89. if (Thickness != null) {
  90. new Rect (Point.Empty, Frame.Size);
  91. }
  92. // Return the frame-relative bounds
  93. return Thickness.GetInnerRect (new Rect (Point.Empty, Frame.Size));
  94. }
  95. set {
  96. throw new InvalidOperationException ("It makes no sense to explicitly set Bounds.");
  97. }
  98. }
  99. //public override void OnDrawContent (Rect viewport)
  100. //{
  101. // // do nothing
  102. //}
  103. //public override void Redraw (Rect bounds)
  104. //{
  105. // if (ColorScheme != null) {
  106. // Driver.SetAttribute (HasFocus ? ColorScheme.Focus : ColorScheme.Normal);
  107. // }
  108. // //if (Text != null) {
  109. // // Thickness?.Draw (Frame, $"{Text} {DiagnosticsLabel?.Text}");
  110. // //}
  111. // if (BorderStyle != BorderStyle.None) {
  112. // var lc = new LineCanvas ();
  113. // lc.AddLine (Frame.Location, Frame.Width - 1, Orientation.Horizontal, BorderStyle);
  114. // lc.AddLine (Frame.Location, Frame.Height - 1, Orientation.Vertical, BorderStyle);
  115. // lc.AddLine (new Point (Frame.X, Frame.Y + Frame.Height - 1), Frame.Width - 1, Orientation.Horizontal, BorderStyle);
  116. // lc.AddLine (new Point (Frame.X + Frame.Width - 1, Frame.Y), Frame.Height - 1, Orientation.Vertical, BorderStyle);
  117. // foreach (var p in lc.GenerateImage (Frame)) {
  118. // Driver.Move (p.Key.X, p.Key.Y);
  119. // Driver.AddRune (p.Value);
  120. // }
  121. // if (!ustring.IsNullOrEmpty (Title)) {
  122. // Driver.DrawWindowTitle (Frame, Title, 0, 0, 0, 0);
  123. // }
  124. // }
  125. // base.Redraw (bounds);
  126. //}
  127. }
  128. }