Skip to content

Commit

Permalink
Change _lines field to Lines property.
Browse files Browse the repository at this point in the history
  • Loading branch information
BDisp committed Nov 14, 2023
1 parent 69a7f17 commit ab6c5f3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
29 changes: 16 additions & 13 deletions Terminal.Gui/Drawing/LineCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ private void ConfigurationManager_Applied (object? sender, ConfigurationManagerE
}
}

private List<StraightLine> _lines = new List<StraightLine> ();
/// <summary>
/// Get or sets a list of <see cref="StraightLine"/> lines.
/// </summary>
public List<StraightLine> Lines { get; internal set; } = new List<StraightLine> ();

Dictionary<IntersectionRuneType, IntersectionRuneResolver> runeResolvers = new Dictionary<IntersectionRuneType, IntersectionRuneResolver> {
{IntersectionRuneType.ULCorner,new ULIntersectionRuneResolver()},
Expand Down Expand Up @@ -122,7 +125,7 @@ private void ConfigurationManager_Applied (object? sender, ConfigurationManagerE
public void AddLine (Point start, int length, Orientation orientation, LineStyle style, Attribute? attribute = default)
{
_cachedBounds = Rect.Empty;
_lines.Add (new StraightLine (start, length, orientation, style, attribute));
Lines.Add (new StraightLine (start, length, orientation, style, attribute));
}

/// <summary>
Expand All @@ -132,7 +135,7 @@ public void AddLine (Point start, int length, Orientation orientation, LineStyle
public void AddLine (StraightLine line)
{
_cachedBounds = Rect.Empty;
_lines.Add (line);
Lines.Add (line);
}

/// <summary>
Expand All @@ -141,9 +144,9 @@ public void AddLine (StraightLine line)
/// <returns></returns>
public StraightLine RemoveLastLine()
{
var l = _lines.LastOrDefault ();
var l = Lines.LastOrDefault ();
if(l != null) {
_lines.Remove(l);
Lines.Remove(l);
}

return l!;
Expand All @@ -155,7 +158,7 @@ public StraightLine RemoveLastLine()
public void Clear ()
{
_cachedBounds = Rect.Empty;
_lines.Clear ();
Lines.Clear ();
}

/// <summary>
Expand All @@ -177,14 +180,14 @@ public void ClearCache ()
public Rect Bounds {
get {
if (_cachedBounds.IsEmpty) {
if (_lines.Count == 0) {
if (Lines.Count == 0) {
return _cachedBounds;
}

Rect bounds = _lines [0].Bounds;
Rect bounds = Lines [0].Bounds;

for (var i = 1; i < _lines.Count; i++) {
var line = _lines [i];
for (var i = 1; i < Lines.Count; i++) {
var line = Lines [i];
var lineBounds = line.Bounds;
bounds = Rect.Union (bounds, lineBounds);
}
Expand Down Expand Up @@ -220,7 +223,7 @@ public Dictionary<Point, Rune> GetMap (Rect inArea)
for (int y = inArea.Y; y < inArea.Y + inArea.Height; y++) {
for (int x = inArea.X; x < inArea.X + inArea.Width; x++) {

var intersects = _lines
var intersects = Lines
.Select (l => l.Intersects (x, y))
.Where (i => i != null)
.ToArray ();
Expand Down Expand Up @@ -250,7 +253,7 @@ public Dictionary<Point, Cell> GetCellMap ()
for (int y = Bounds.Y; y < Bounds.Y + Bounds.Height; y++) {
for (int x = Bounds.X; x < Bounds.X + Bounds.Width; x++) {

var intersects = _lines
var intersects = Lines
.Select (l => l.Intersects (x, y))
.Where (i => i != null)
.ToArray ();
Expand Down Expand Up @@ -721,7 +724,7 @@ private bool Exactly (HashSet<IntersectionType> intersects, params IntersectionT
/// <param name="lineCanvas"></param>
public void Merge (LineCanvas lineCanvas)
{
foreach (var line in lineCanvas._lines) {
foreach (var line in lineCanvas.Lines) {
AddLine (line);
}
}
Expand Down
3 changes: 3 additions & 0 deletions Terminal.Gui/Views/TabView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,12 @@ public override void OnDrawContent (Rect contentArea)
// How much space do we need to leave at the bottom to show the tabs
int spaceAtBottom = Math.Max (0, GetTabHeight (false) - 1);
int startAtY = Math.Max (0, GetTabHeight (true) - 1);
var lc = new LineCanvas () { Lines = new List<StraightLine> (LineCanvas.Lines) };

DrawFrame (new Rect (0, startAtY, Bounds.Width,
Math.Max (Bounds.Height - spaceAtBottom - startAtY, 0)), LineStyle.Single);

LineCanvas.Lines = lc.Lines;
}

if (Tabs.Any ()) {
Expand Down
1 change: 1 addition & 0 deletions UICatalog/Scenarios/TabViewExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public override void Setup ()
Y = 0,
Width = 60,
Height = 20,
BorderStyle = LineStyle.Single
};

tabView.AddTab (new Tab ("Tab1", new Label ("hodor!")), false);
Expand Down

0 comments on commit ab6c5f3

Please sign in to comment.