mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 08:50:25 +01:00
Add support for rounded corners
This commit is contained in:
@@ -97,6 +97,7 @@ namespace Terminal.Gui.Graphs {
|
||||
|
||||
var runeType = GetRuneTypeForIntersects (intersects);
|
||||
var useDouble = intersects.Any (i => i.Line.Style == BorderStyle.Double && i.Line.Length != 0);
|
||||
var useRounded = intersects.Any (i => i.Line.Style == BorderStyle.Rounded && i.Line.Length != 0);
|
||||
|
||||
switch (runeType) {
|
||||
case IntersectionRuneType.None:
|
||||
@@ -104,13 +105,13 @@ namespace Terminal.Gui.Graphs {
|
||||
case IntersectionRuneType.Dot:
|
||||
return (Rune)'.';
|
||||
case IntersectionRuneType.ULCorner:
|
||||
return useDouble ? driver.ULDCorner : driver.ULCorner;
|
||||
return useDouble ? driver.ULDCorner : useRounded ? driver.ULRCorner : driver.ULCorner;
|
||||
case IntersectionRuneType.URCorner:
|
||||
return useDouble ? driver.URDCorner : driver.URCorner;
|
||||
return useDouble ? driver.URDCorner : useRounded ? driver.URRCorner : driver.URCorner;
|
||||
case IntersectionRuneType.LLCorner:
|
||||
return useDouble ? driver.LLDCorner : driver.LLCorner;
|
||||
return useDouble ? driver.LLDCorner : useRounded ? driver.LLRCorner : driver.LLCorner;
|
||||
case IntersectionRuneType.LRCorner:
|
||||
return useDouble ? driver.LRDCorner : driver.LRCorner;
|
||||
return useDouble ? driver.LRDCorner : useRounded ? driver.LRRCorner : driver.LRCorner;
|
||||
case IntersectionRuneType.TopTee:
|
||||
return useDouble ? '╦' : driver.TopTee;
|
||||
case IntersectionRuneType.BottomTee:
|
||||
|
||||
@@ -156,6 +156,41 @@ namespace Terminal.Gui.Core {
|
||||
TestHelpers.AssertDriverContentsAre (looksLike, output);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Demonstrates when <see cref="BorderStyle.Rounded"/> corners are used. Notice how
|
||||
/// not all lines declare rounded. If there are 1+ lines intersecting and a corner is
|
||||
/// to be used then if any of them are rounded a rounded corner is used.
|
||||
/// </summary>
|
||||
[Fact, AutoInitShutdown]
|
||||
public void TestLineCanvas_Window_Rounded ()
|
||||
{
|
||||
var v = GetCanvas (out var canvas);
|
||||
|
||||
// outer box
|
||||
canvas.AddLine (new Point (0, 0), 9, Orientation.Horizontal, BorderStyle.Rounded);
|
||||
|
||||
// BorderStyle.Single is ignored because corner overlaps with the above line which is Rounded
|
||||
// this results in a rounded corner being used.
|
||||
canvas.AddLine (new Point (9, 0), 4, Orientation.Vertical, BorderStyle.Single);
|
||||
canvas.AddLine (new Point (9, 4), -9, Orientation.Horizontal, BorderStyle.Rounded);
|
||||
canvas.AddLine (new Point (0, 4), -4, Orientation.Vertical, BorderStyle.Single);
|
||||
|
||||
// These lines say rounded but they will result in the T sections which are never rounded.
|
||||
canvas.AddLine (new Point (5, 0), 4, Orientation.Vertical, BorderStyle.Rounded);
|
||||
canvas.AddLine (new Point (0, 2), 9, Orientation.Horizontal, BorderStyle.Rounded);
|
||||
|
||||
v.Redraw (v.Bounds);
|
||||
|
||||
string looksLike =
|
||||
@"
|
||||
╭────┬───╮
|
||||
│ │ │
|
||||
├────┼───┤
|
||||
│ │ │
|
||||
╰────┴───╯";
|
||||
TestHelpers.AssertDriverContentsAre (looksLike, output);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void TestLineCanvas_Window_Double ()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user