mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-02 01:03:29 +01:00
Draws a minimum full border.
This commit is contained in:
@@ -198,7 +198,9 @@ namespace Terminal.Gui {
|
||||
|
||||
}
|
||||
|
||||
if (Id == "Border" && canDrawBorder && Thickness.Top > 0 && maxTitleWidth > 0 && !string.IsNullOrEmpty (Parent?.Title)) {
|
||||
if (Id == "Border" && canDrawBorder && Thickness.Top > 0 && maxTitleWidth > 0 && !string.IsNullOrEmpty (Parent?.Title)
|
||||
&& borderBounds.Height > 1) {
|
||||
|
||||
var prevAttr = Driver.GetAttribute ();
|
||||
if (ColorScheme != null) {
|
||||
Driver.SetAttribute (HasFocus ? GetHotNormalColor () : GetNormalColor ());
|
||||
@@ -212,10 +214,10 @@ namespace Terminal.Gui {
|
||||
if (Id == "Border" && canDrawBorder && BorderStyle != LineStyle.None) {
|
||||
LineCanvas lc = Parent?.LineCanvas;
|
||||
|
||||
var drawTop = Thickness.Top > 0 && Frame.Width > 1 && Frame.Height > 1;
|
||||
var drawTop = Thickness.Top > 0 && Frame.Width > 1 && Frame.Height > 0;
|
||||
var drawLeft = Thickness.Left > 0 && (Frame.Height > 1 || Thickness.Top == 0);
|
||||
var drawBottom = Thickness.Bottom > 0 && Frame.Width > 1;
|
||||
var drawRight = Thickness.Right > 0 && (Frame.Height > 1 || Thickness.Top == 0);
|
||||
var drawBottom = Thickness.Bottom > 0 && Frame.Width > 1 && Frame.Height > 1;
|
||||
var drawRight = Thickness.Right > 0 && ((Frame.Width > 1 && Frame.Height > 1) || Thickness.Top == 0);
|
||||
|
||||
var prevAttr = Driver.GetAttribute ();
|
||||
if (ColorScheme != null) {
|
||||
@@ -227,7 +229,7 @@ namespace Terminal.Gui {
|
||||
if (drawTop) {
|
||||
// ╔╡Title╞═════╗
|
||||
// ╔╡╞═════╗
|
||||
if (borderBounds.Width < 4 || string.IsNullOrEmpty (Parent?.Title)) {
|
||||
if (borderBounds.Width < 4 || borderBounds.Height == 1 || string.IsNullOrEmpty (Parent?.Title)) {
|
||||
// ╔╡╞╗ should be ╔══╗
|
||||
lc.AddLine (new Point (borderBounds.Location.X, titleY), borderBounds.Width, Orientation.Horizontal, BorderStyle, Driver.GetAttribute ());
|
||||
} else {
|
||||
@@ -246,15 +248,17 @@ namespace Terminal.Gui {
|
||||
lc.AddLine (new Point (borderBounds.X + 1, topTitleLineY + 2), Math.Min (borderBounds.Width - 2, maxTitleWidth + 2), Orientation.Horizontal, BorderStyle, Driver.GetAttribute ());
|
||||
}
|
||||
|
||||
// ╔╡Title╞═════╗
|
||||
// Add a short horiz line for ╔╡
|
||||
lc.AddLine (new Point (borderBounds.Location.X, titleY), 2, Orientation.Horizontal, BorderStyle, Driver.GetAttribute ());
|
||||
// Add a vert line for ╔╡
|
||||
lc.AddLine (new Point (borderBounds.X + 1, topTitleLineY), titleBarsLength, Orientation.Vertical, LineStyle.Single, Driver.GetAttribute ());
|
||||
// Add a vert line for ╞
|
||||
lc.AddLine (new Point (borderBounds.X + 1 + Math.Min (borderBounds.Width - 2, maxTitleWidth + 2) - 1, topTitleLineY), titleBarsLength, Orientation.Vertical, LineStyle.Single, Driver.GetAttribute ());
|
||||
// Add the right hand line for ╞═════╗
|
||||
lc.AddLine (new Point (borderBounds.X + 1 + Math.Min (borderBounds.Width - 2, maxTitleWidth + 2) - 1, titleY), borderBounds.Width - Math.Min (borderBounds.Width - 2, maxTitleWidth + 2), Orientation.Horizontal, BorderStyle, Driver.GetAttribute ());
|
||||
if (borderBounds.Height > 1) {
|
||||
// ╔╡Title╞═════╗
|
||||
// Add a short horiz line for ╔╡
|
||||
lc.AddLine (new Point (borderBounds.Location.X, titleY), 2, Orientation.Horizontal, BorderStyle, Driver.GetAttribute ());
|
||||
// Add a vert line for ╔╡
|
||||
lc.AddLine (new Point (borderBounds.X + 1, topTitleLineY), titleBarsLength, Orientation.Vertical, LineStyle.Single, Driver.GetAttribute ());
|
||||
// Add a vert line for ╞
|
||||
lc.AddLine (new Point (borderBounds.X + 1 + Math.Min (borderBounds.Width - 2, maxTitleWidth + 2) - 1, topTitleLineY), titleBarsLength, Orientation.Vertical, LineStyle.Single, Driver.GetAttribute ());
|
||||
// Add the right hand line for ╞═════╗
|
||||
lc.AddLine (new Point (borderBounds.X + 1 + Math.Min (borderBounds.Width - 2, maxTitleWidth + 2) - 1, titleY), borderBounds.Width - Math.Min (borderBounds.Width - 2, maxTitleWidth + 2), Orientation.Horizontal, BorderStyle, Driver.GetAttribute ());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (drawLeft) {
|
||||
|
||||
@@ -334,6 +334,89 @@ t ", output);
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre ("", output);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void Draw_Minimum_Full_Border_Width_One_Height_One ()
|
||||
{
|
||||
var label = new Label () { Width = 1, Height = 1, BorderStyle = LineStyle.Single };
|
||||
Application.Top.Add (label);
|
||||
Application.Begin (Application.Top);
|
||||
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
┌┐
|
||||
└┘", output);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void Draw_Minimum_Full_Border_Width_One_Height_One_Without_Bottom ()
|
||||
{
|
||||
var label = new Label () { Width = 1, Height = 1, BorderStyle = LineStyle.Single };
|
||||
label.Border.Thickness = new Thickness (1, 1, 1, 0);
|
||||
Application.Top.Add (label);
|
||||
Application.Begin (Application.Top);
|
||||
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
──", output);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void Draw_Minimum_Full_Border_Width_One_Height_One_Without_Top ()
|
||||
{
|
||||
var label = new Label () { Width = 1, Height = 1, BorderStyle = LineStyle.Single };
|
||||
label.Border.Thickness = new Thickness (1, 0, 1, 1);
|
||||
Application.Top.Add (label);
|
||||
Application.Begin (Application.Top);
|
||||
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
││", output);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void Test_Label_Full_Border ()
|
||||
{
|
||||
var label = new Label () { Text = "Test", Width = 4, Height = 1, BorderStyle = LineStyle.Single };
|
||||
Application.Top.Add (label);
|
||||
Application.Begin (Application.Top);
|
||||
|
||||
Assert.Equal (new Rect (0, 0, 6, 3), label.Frame);
|
||||
Assert.Equal (new Rect (0, 0, 4, 1), label.Bounds);
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
┌────┐
|
||||
│Test│
|
||||
└────┘", output);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void Test_Label_Without_Top_Border ()
|
||||
{
|
||||
var label = new Label () { Text = "Test", Width = 4, Height = 1, BorderStyle = LineStyle.Single };
|
||||
label.Border.Thickness = new Thickness (1, 0, 1, 1);
|
||||
Application.Top.Add (label);
|
||||
|
||||
Assert.Equal (new Rect (0, 0, 6, 2), label.Frame);
|
||||
Assert.Equal (new Rect (0, 0, 4, 1), label.Bounds);
|
||||
Application.Begin (Application.Top);
|
||||
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
│Test│
|
||||
└────┘", output);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void Test_Label_With_Top_Margin_Without_Top_Border ()
|
||||
{
|
||||
var label = new Label () { Text = "Test", Width = 4, Height = 1, BorderStyle = LineStyle.Single };
|
||||
label.Margin.Thickness = new Thickness (0, 1, 0, 0);
|
||||
label.Border.Thickness = new Thickness (1, 0, 1, 1);
|
||||
Application.Top.Add (label);
|
||||
|
||||
Assert.Equal (new Rect (0, 0, 6, 3), label.Frame);
|
||||
Assert.Equal (new Rect (0, 0, 4, 1), label.Bounds);
|
||||
Application.Begin (Application.Top);
|
||||
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
│Test│
|
||||
└────┘", output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user