Skip to content

Commit

Permalink
Fixes #1855. Window and Frame content view without the margin frame. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
BDisp authored Jul 19, 2022
1 parent bcc3034 commit 40b661d
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 71 deletions.
103 changes: 58 additions & 45 deletions Terminal.Gui/Core/Border.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ private void Initialize (Rect frame, Border border, string title = null)
{
ColorScheme = Colors.TopLevel;
Text = title ?? "";
Frame = frame;
if (border == null) {
Border = new Border () {
BorderStyle = BorderStyle.Single,
Expand All @@ -174,26 +173,30 @@ private void Initialize (Rect frame, Border border, string title = null)
} else {
Border = border;
}
AdjustContentView (frame);
}

void AdjustContentView (Rect frame)
{
var borderLength = Border.DrawMarginFrame ? 1 : 0;
var sumPadding = Border.GetSumThickness ();
var wp = new Point ();
var wb = new Size ();
if (frame == Rect.Empty) {
wp.X = borderLength + sumPadding.Left;
wp.Y = borderLength + sumPadding.Top;
wb.Width = borderLength + sumPadding.Right;
wb.Height = borderLength + sumPadding.Bottom;
if (Border.Child == null) {
Border.Child = new ChildContentView (this) {
X = borderLength + sumPadding.Left,
Y = borderLength + sumPadding.Top,
X = wp.X,
Y = wp.Y,
Width = Dim.Fill (wb.Width),
Height = Dim.Fill (wb.Height)
};
} else {
Border.Child.X = borderLength + sumPadding.Left;
Border.Child.Y = borderLength + sumPadding.Top;
Border.Child.X = wp.X;
Border.Child.Y = wp.Y;
Border.Child.Width = Dim.Fill (wb.Width);
Border.Child.Height = Dim.Fill (wb.Height);
}
Expand All @@ -207,7 +210,8 @@ void AdjustContentView (Rect frame)
Border.Child.Frame = cFrame;
}
}
base.Add (Border.Child);
if (Subviews?.Count == 0)
base.Add (Border.Child);
Border.ChildContainer = this;
}

Expand Down Expand Up @@ -249,7 +253,7 @@ public override void Redraw (Rect bounds)
{
if (!NeedDisplay.IsEmpty) {
Driver.SetAttribute (GetNormalColor ());
Border.DrawContent ();
Clear ();
}
var savedClip = Border.Child.ClipToBounds ();
Border.Child.Redraw (Border.Child.Bounds);
Expand All @@ -258,10 +262,13 @@ public override void Redraw (Rect bounds)
ClearLayoutNeeded ();
ClearNeedsDisplay ();

if (Border.BorderStyle != BorderStyle.None) {
Driver.SetAttribute (GetNormalColor ());
Border.DrawTitle (this, this.Frame);
}
Driver.SetAttribute (GetNormalColor ());
Border.DrawContent (this, false);
if (HasFocus)
Driver.SetAttribute (ColorScheme.HotNormal);
if (Border.DrawMarginFrame)
Border.DrawTitle (this, Frame);
Driver.SetAttribute (GetNormalColor ());

// Checks if there are any SuperView view which intersect with this window.
if (SuperView != null) {
Expand Down Expand Up @@ -541,24 +548,26 @@ public void DrawFullContent ()
driver.SetAttribute (savedAttribute);

// Draw margin frame
if (Parent?.Border != null) {
var sumPadding = GetSumThickness ();
borderRect = new Rect () {
X = scrRect.X + sumPadding.Left,
Y = scrRect.Y + sumPadding.Top,
Width = Math.Max (scrRect.Width - sumPadding.Right - sumPadding.Left, 0),
Height = Math.Max (scrRect.Height - sumPadding.Bottom - sumPadding.Top, 0)
};
} else {
borderRect = new Rect () {
X = borderRect.X + padding.Left,
Y = borderRect.Y + padding.Top,
Width = Math.Max (borderRect.Width - padding.Right - padding.Left, 0),
Height = Math.Max (borderRect.Height - padding.Bottom - padding.Top, 0)
};
}
if (borderRect.Width > 0 && borderRect.Height > 0) {
driver.DrawWindowFrame (borderRect, 1, 1, 1, 1, BorderStyle != BorderStyle.None, fill: true, this);
if (DrawMarginFrame) {
if (Parent?.Border != null) {
var sumPadding = GetSumThickness ();
borderRect = new Rect () {
X = scrRect.X + sumPadding.Left,
Y = scrRect.Y + sumPadding.Top,
Width = Math.Max (scrRect.Width - sumPadding.Right - sumPadding.Left, 0),
Height = Math.Max (scrRect.Height - sumPadding.Bottom - sumPadding.Top, 0)
};
} else {
borderRect = new Rect () {
X = borderRect.X + padding.Left,
Y = borderRect.Y + padding.Top,
Width = Math.Max (borderRect.Width - padding.Right - padding.Left, 0),
Height = Math.Max (borderRect.Height - padding.Bottom - padding.Top, 0)
};
}
if (borderRect.Width > 0 && borderRect.Height > 0) {
driver.DrawWindowFrame (borderRect, 1, 1, 1, 1, BorderStyle != BorderStyle.None, fill: true, this);
}
}
}

Expand Down Expand Up @@ -659,14 +668,16 @@ private void DrawChildBorder (Rect frame, bool fill = true)
driver.SetAttribute (savedAttribute);

// Draw the MarginFrame
var rect = new Rect () {
X = frame.X - drawMarginFrame,
Y = frame.Y - drawMarginFrame,
Width = frame.Width + (2 * drawMarginFrame),
Height = frame.Height + (2 * drawMarginFrame)
};
if (rect.Width > 0 && rect.Height > 0) {
driver.DrawWindowFrame (rect, 1, 1, 1, 1, BorderStyle != BorderStyle.None, fill, this);
if (DrawMarginFrame) {
var rect = new Rect () {
X = frame.X - drawMarginFrame,
Y = frame.Y - drawMarginFrame,
Width = frame.Width + (2 * drawMarginFrame),
Height = frame.Height + (2 * drawMarginFrame)
};
if (rect.Width > 0 && rect.Height > 0) {
driver.DrawWindowFrame (rect, 1, 1, 1, 1, BorderStyle != BorderStyle.None, fill, this);
}
}

if (Effect3D) {
Expand Down Expand Up @@ -811,14 +822,16 @@ private void DrawParentBorder (Rect frame, bool fill = true)
driver.SetAttribute (savedAttribute);

// Draw the MarginFrame
var rect = new Rect () {
X = frame.X + sumThickness.Left,
Y = frame.Y + sumThickness.Top,
Width = Math.Max (frame.Width - sumThickness.Right - sumThickness.Left, 0),
Height = Math.Max (frame.Height - sumThickness.Bottom - sumThickness.Top, 0)
};
if (rect.Width > 0 && rect.Height > 0) {
driver.DrawWindowFrame (rect, 1, 1, 1, 1, BorderStyle != BorderStyle.None, fill, this);
if (DrawMarginFrame) {
var rect = new Rect () {
X = frame.X + sumThickness.Left,
Y = frame.Y + sumThickness.Top,
Width = Math.Max (frame.Width - sumThickness.Right - sumThickness.Left, 0),
Height = Math.Max (frame.Height - sumThickness.Bottom - sumThickness.Top, 0)
};
if (rect.Width > 0 && rect.Height > 0) {
driver.DrawWindowFrame (rect, 1, 1, 1, 1, BorderStyle != BorderStyle.None, fill, this);
}
}

if (Effect3D) {
Expand Down
32 changes: 18 additions & 14 deletions Terminal.Gui/Core/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ void Border_BorderChanged (Border border)
AdjustContentView (frame);
}


/// <summary>
/// ContentView is an internal implementation detail of Window. It is used to host Views added with <see cref="Add(View)"/>.
/// Its ONLY reason for being is to provide a simple way for Window to expose to those SubViews that the Window's Bounds
Expand Down Expand Up @@ -186,26 +185,30 @@ void Initialize (ustring title, Rect frame, int padding = 0, Border border = nul
} else {
Border = border;
}
AdjustContentView (frame);
}

void AdjustContentView (Rect frame)
{
var borderLength = Border.DrawMarginFrame ? 1 : 0;
var sumPadding = Border.GetSumThickness ();
var wp = new Point ();
var wb = new Size ();
if (frame == Rect.Empty) {
wp.X = borderLength + sumPadding.Left;
wp.Y = borderLength + sumPadding.Top;
wb.Width = borderLength + sumPadding.Right;
wb.Height = borderLength + sumPadding.Bottom;
if (contentView == null) {
contentView = new ContentView (this) {
X = borderLength + sumPadding.Left,
Y = borderLength + sumPadding.Top,
X = wp.X,
Y = wp.Y,
Width = Dim.Fill (wb.Width),
Height = Dim.Fill (wb.Height)
};
} else {
contentView.X = borderLength + sumPadding.Left;
contentView.Y = borderLength + sumPadding.Top;
contentView.X = wp.X;
contentView.Y = wp.Y;
contentView.Width = Dim.Fill (wb.Width);
contentView.Height = Dim.Fill (wb.Height);
}
Expand All @@ -219,7 +222,8 @@ void AdjustContentView (Rect frame)
contentView.Frame = cFrame;
}
}
base.Add (contentView);
if (Subviews?.Count == 0)
base.Add (contentView);
Border.Child = contentView;
}

Expand Down Expand Up @@ -289,15 +293,15 @@ public override void Redraw (Rect bounds)

ClearLayoutNeeded ();
ClearNeedsDisplay ();
if (Border.BorderStyle != BorderStyle.None) {
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);

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 ());

// Checks if there are any SuperView view which intersect with this window.
Expand Down
26 changes: 14 additions & 12 deletions Terminal.Gui/Views/FrameView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,23 @@ void AdjustContentView (Rect frame, View [] views = null)
{
var borderLength = Border.DrawMarginFrame ? 1 : 0;
var sumPadding = Border.GetSumThickness ();
var wp = new Point ();
var wb = new Size ();
if (frame == Rect.Empty) {
wp.X = borderLength + sumPadding.Left;
wp.Y = borderLength + sumPadding.Top;
wb.Width = borderLength + sumPadding.Right;
wb.Height = borderLength + sumPadding.Bottom;
if (contentView == null) {
contentView = new ContentView () {
X = borderLength + sumPadding.Left,
Y = borderLength + sumPadding.Top,
X = wp.X,
Y = wp.Y,
Width = Dim.Fill (wb.Width),
Height = Dim.Fill (wb.Height)
};
} else {
contentView.X = borderLength + sumPadding.Left;
contentView.Y = borderLength + sumPadding.Top;
contentView.X = wp.X;
contentView.Y = wp.Y;
contentView.Width = Dim.Fill (wb.Width);
contentView.Height = Dim.Fill (wb.Height);
}
Expand Down Expand Up @@ -225,15 +228,14 @@ public override void Redraw (Rect bounds)
Driver.Clip = savedClip;

ClearNeedsDisplay ();
if (Border.BorderStyle != BorderStyle.None) {
Driver.SetAttribute (GetNormalColor ());
//Driver.DrawWindowFrame (scrRect, padding + 1, padding + 1, padding + 1, padding + 1, border: true, fill: false);
Border.DrawContent (this, false);
if (HasFocus)
Driver.SetAttribute (ColorScheme.HotNormal);
//Driver.DrawWindowTitle (scrRect, Title, padding, padding, padding, padding);

Driver.SetAttribute (GetNormalColor ());
//Driver.DrawWindowFrame (scrRect, padding + 1, padding + 1, padding + 1, padding + 1, border: true, fill: false);
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 ());
}

Expand Down

0 comments on commit 40b661d

Please sign in to comment.