diff --git a/Terminal.Gui/Core/Frame.cs b/Terminal.Gui/Core/Frame.cs index 56ce4caa5..3ceb56768 100644 --- a/Terminal.Gui/Core/Frame.cs +++ b/Terminal.Gui/Core/Frame.cs @@ -102,7 +102,7 @@ namespace Terminal.Gui { var prevClip = SetClip (Frame); var screenBounds = ViewToScreen (Frame); - Thickness.Draw (screenBounds, (string)Data); + Thickness.Draw (screenBounds, (string)(Data != null ? Data : string.Empty)); //OnDrawContent (bounds); diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs index 33706fe1c..d5a1bc79e 100644 --- a/Terminal.Gui/Core/View.cs +++ b/Terminal.Gui/Core/View.cs @@ -620,7 +620,6 @@ namespace Terminal.Gui { return new Rect (default, frameRelativeBounds.Size); } set { - throw new InvalidOperationException ("It makes no sense to explicitly set Bounds."); Frame = new Rect (Frame.Location, value.Size + new Size (Margin.Thickness.Right, Margin.Thickness.Bottom) + new Size (BorderFrame.Thickness.Right, BorderFrame.Thickness.Bottom) @@ -792,7 +791,7 @@ namespace Terminal.Gui { /// will not fit. public bool SetMinWidthHeight () { - if (GetMinimumBounds (out Size size)) { + if (IsInitialized && GetMinimumBounds (out Size size)) { Bounds = new Rect (Bounds.Location, size); return true; } @@ -932,7 +931,6 @@ namespace Terminal.Gui { TabIndex = -1; TabStop = false; LayoutStyle = layoutStyle; - // BUGBUG: CalcRect doesn't account for line wrapping Border = border; Text = text; @@ -3259,6 +3257,7 @@ namespace Terminal.Gui { // TODO: Figure out why ScrollView and other tests fail if this call is put here // instead of the constructor. // OnSizeChanged (); + InitializeFrames (); } else { //throw new InvalidOperationException ("The view is already initialized."); diff --git a/Terminal.Gui/Core/Window.cs b/Terminal.Gui/Core/Window.cs index cba895495..4e7c57e26 100644 --- a/Terminal.Gui/Core/Window.cs +++ b/Terminal.Gui/Core/Window.cs @@ -70,7 +70,7 @@ namespace Terminal.Gui { /// public Window (Rect frame, ustring title = null, int padding = 0, Border border = null) : base (frame) { - Initialize (title, frame, padding, border); + SetInitialProperties (title, frame, padding, border); } /// @@ -86,7 +86,7 @@ namespace Terminal.Gui { /// public Window (ustring title = null, int padding = 0, Border border = null) : base () { - Initialize (title, Rect.Empty, padding, border); + SetInitialProperties (title, Rect.Empty, padding, border); } /// @@ -98,23 +98,35 @@ namespace Terminal.Gui { ///[SerializableConfigurationProperty (Scope = typeof (ThemeScope)), JsonConverter (typeof (JsonStringEnumConverter))] public static BorderStyle DefaultBorderStyle { get; set; } = BorderStyle.Single; - void Initialize (ustring title, Rect frame, int padding = 0, Border border = null) + void SetInitialProperties (ustring title, Rect frame, int padding = 0, Border border = null) { CanFocus = true; ColorScheme = Colors.Base; if (title == null) title = ustring.Empty; Title = title; + if (border == null) { + // TODO: v2 this is a hack until Border gets refactored Border = new Border () { BorderStyle = DefaultBorderStyle, Padding = new Thickness (padding), - //Title = title }; } else { Border = border; } } + public override void BeginInit () + { + base.BeginInit (); + BorderFrame.Thickness = new Thickness (2); + BorderFrame.BorderStyle = Border.BorderStyle; + BorderFrame.ColorScheme = ColorScheme; + BorderFrame.Data = "BorderFrame"; + + Padding.Thickness = Border.Padding; + } + /// public override void Add (View view) { @@ -139,77 +151,6 @@ namespace Terminal.Gui { } - ///// - //public override void RemoveAll () - //{ - // contentView.RemoveAll (); - //} - - ///// - //public override void Redraw (Rect bounds) - //{ - // var padding = Border.GetSumThickness (); - // var scrRect = ViewToScreen (new Rect (0, 0, Frame.Width, Frame.Height)); - - // if (!NeedDisplay.IsEmpty || ChildNeedsDisplay || LayoutNeeded) { - // Driver.SetAttribute (GetNormalColor ()); - // Clear (); - // contentView.SetNeedsDisplay (); - // } - // var savedClip = contentView.ClipToBounds (); - - // // Redraw our contentView - // // DONE: smartly constrict contentView.Bounds to just be what intersects with the 'bounds' we were passed - // contentView.Redraw (!NeedDisplay.IsEmpty || ChildNeedsDisplay || LayoutNeeded ? contentView.Bounds : bounds); - // Driver.Clip = savedClip; - - // ClearLayoutNeeded (); - // ClearNeedsDisplay (); - - // Driver.SetAttribute (GetNormalColor ()); - // //Driver.DrawWindowFrame (scrRect, padding.Left + borderLength, padding.Top + borderLength, padding.Right + borderLength, padding.Bottom + borderLength, - // // Border.BorderStyle != BorderStyle.None, fill: true, Border.BorderStyle); - // Border.DrawContent (this, false); - // if (HasFocus) - // Driver.SetAttribute (ColorScheme.HotNormal); - // if (Border.DrawMarginFrame) - // Driver.DrawWindowTitle (scrRect, Title, padding.Left, padding.Top, padding.Right, padding.Bottom); - // Driver.SetAttribute (GetNormalColor ()); - //} - - ///// - //public override void OnCanFocusChanged () - //{ - // if (contentView != null) { - // contentView.CanFocus = CanFocus; - // } - // base.OnCanFocusChanged (); - //} - - ///// - ///// The text displayed by the . - ///// - //public override ustring Text { - // get => contentView?.Text; - // set { - // base.Text = value; - // if (contentView != null) { - // contentView.Text = value; - // } - // } - //} - - ///// - ///// Controls the text-alignment property of the label, changing it will redisplay the . - ///// - ///// The text alignment. - //public override TextAlignment TextAlignment { - // get => contentView.TextAlignment; - // set { - // base.TextAlignment = contentView.TextAlignment = value; - // } - //} - /// /// Event arguments for change events. /// diff --git a/Terminal.Gui/Views/FrameView.cs b/Terminal.Gui/Views/FrameView.cs index c5806d3b5..357f3f46d 100644 --- a/Terminal.Gui/Views/FrameView.cs +++ b/Terminal.Gui/Views/FrameView.cs @@ -56,7 +56,7 @@ namespace Terminal.Gui { /// The . public FrameView (Rect frame, ustring title = null, View [] views = null, Border border = null) : base (frame) { - Initialize (frame, title, views, border); + SetInitialProperties (frame, title, views, border); } /// @@ -66,7 +66,7 @@ namespace Terminal.Gui { /// The . public FrameView (ustring title, Border border = null) { - Initialize (Rect.Empty, title, null, border); + SetInitialProperties (Rect.Empty, title, null, border); } /// @@ -83,7 +83,7 @@ namespace Terminal.Gui { [SerializableConfigurationProperty (Scope = typeof (ThemeScope)), JsonConverter (typeof (JsonStringEnumConverter))] public static BorderStyle DefaultBorderStyle { get; set; } = BorderStyle.Single; - void Initialize (Rect frame, ustring title, View [] views = null, Border border = null) + void SetInitialProperties (Rect frame, ustring title, View [] views = null, Border border = null) { this.Title = title; if (border == null) { @@ -99,13 +99,15 @@ namespace Terminal.Gui { } } - - - void DrawFrame () + public override void BeginInit () { - DrawFrame (new Rect (0, 0, Frame.Width, Frame.Height), 0, fill: true); - } + base.BeginInit (); + BorderFrame.Thickness = new Thickness (2); + BorderFrame.BorderStyle = Border.BorderStyle; + BorderFrame.ColorScheme = ColorScheme; + BorderFrame.Data = "BorderFrame"; + } /// public override bool OnEnter (View view)