Skip to content

Commit

Permalink
Merge pull request #160 from tznind/revert-158-tznind-splitcontainer
Browse files Browse the repository at this point in the history
lRevert 158 tznind splitcontainer
  • Loading branch information
tznind committed Feb 24, 2023
2 parents 6be0972 + a068933 commit 44c6978
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 280 deletions.
23 changes: 7 additions & 16 deletions Terminal.Gui/Core/Border.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using NStack;
using System;
using Terminal.Gui.Graphs;

namespace Terminal.Gui {
/// <summary>
Expand Down Expand Up @@ -708,22 +707,14 @@ private void DrawChildBorder (Rect frame, bool fill = true)

// Draw the MarginFrame
if (DrawMarginFrame) {
var rect = Child.ViewToScreen (new Rect (-1, -1, Child.Frame.Width + 2, Child.Frame.Height + 2));
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) {

var lc = new LineCanvas ();

lc.AddLine (rect.Location, rect.Width, Orientation.Horizontal, BorderStyle);
lc.AddLine (rect.Location, rect.Height, Orientation.Vertical, BorderStyle);

lc.AddLine (new Point (rect.X, rect.Y + rect.Height - 1), rect.Width, Orientation.Horizontal, BorderStyle);
lc.AddLine (new Point (rect.X + rect.Width, rect.Y), rect.Height, Orientation.Vertical, BorderStyle);

driver.SetAttribute (new Attribute (Color.Red, Color.BrightYellow));

foreach (var p in lc.GenerateImage(rect)) {
AddRuneAt (driver, p.Key.X, p.Key.Y, p.Value);
}
driver.DrawWindowFrame (rect, 1, 1, 1, 1, BorderStyle != BorderStyle.None, fill, this);
DrawTitle (Child);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Terminal.Gui/Core/Graphs/LineCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public Dictionary<Point,Rune> GenerateImage (Rect inArea)
for (int x = inArea.X; x < inArea.Width; x++) {

var intersects = lines
.Select (l => l.Intersects (inArea.X + x, inArea.Y + y))
.Select (l => l.Intersects (x, y))
.Where (i => i != null)
.ToArray ();

Expand Down
12 changes: 4 additions & 8 deletions Terminal.Gui/Core/View.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
Expand Down Expand Up @@ -1513,10 +1513,8 @@ public virtual void Redraw (Rect bounds)
Driver.SetAttribute (HasFocus ? GetFocusColor () : GetNormalColor ());
}

var boundsAdjustedForBorder = Bounds;
if (!IgnoreBorderPropertyOnRedraw && Border != null) {
Border.DrawContent (this);
boundsAdjustedForBorder = new Rect (bounds.X + 1, bounds.Y + 1, bounds.Width - 2, bounds.Height - 2);
} else if (ustring.IsNullOrEmpty (TextFormatter.Text) &&
(GetType ().IsNestedPublic && !IsOverridden (this, "Redraw") || GetType ().Name == "View") &&
(!NeedDisplay.IsEmpty || ChildNeedsDisplay || LayoutNeeded)) {
Expand All @@ -1533,20 +1531,18 @@ public virtual void Redraw (Rect bounds)
if (TextFormatter != null) {
TextFormatter.NeedsFormat = true;
}

TextFormatter?.Draw (ViewToScreen (Bounds), HasFocus ? GetFocusColor () : GetNormalColor (),
HasFocus ? ColorScheme.HotFocus : GetHotNormalColor (),

containerBounds);
}

// Invoke DrawContentEvent
OnDrawContent (boundsAdjustedForBorder);
OnDrawContent (bounds);

if (subviews != null) {
foreach (var view in subviews) {
if (!view.NeedDisplay.IsEmpty || view.ChildNeedsDisplay || view.LayoutNeeded) {
if (view.Frame.IntersectsWith (clipRect) && (view.Frame.IntersectsWith (boundsAdjustedForBorder) || boundsAdjustedForBorder.X < 0 || bounds.Y < 0)) {
if (view.Frame.IntersectsWith (clipRect) && (view.Frame.IntersectsWith (bounds) || bounds.X < 0 || bounds.Y < 0)) {
if (view.LayoutNeeded)
view.LayoutSubviews ();

Expand All @@ -1566,7 +1562,7 @@ public virtual void Redraw (Rect bounds)
}

// Invoke DrawContentCompleteEvent
OnDrawContentComplete (boundsAdjustedForBorder);
OnDrawContentComplete (bounds);

ClearLayoutNeeded ();
ClearNeedsDisplay ();
Expand Down
18 changes: 9 additions & 9 deletions Terminal.Gui/Views/FrameView.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
//
// Authors:
// Miguel de Icaza (miguel@gnome.org)
//
Expand Down Expand Up @@ -252,27 +252,27 @@ public override void Redraw (Rect bounds)
lc.AddLine (new Point (bounds.Width - 1, bounds.Height - 1), -bounds.Height + 1, Orientation.Vertical, Border.BorderStyle);
}

//foreach (var subview in contentView.Subviews) {
// lc.AddLine (new Point (subview.Frame.X + 1, subview.Frame.Y + 1), subview.Frame.Width - 1, Orientation.Horizontal, subview.Border.BorderStyle);
// lc.AddLine (new Point (subview.Frame.X + 1, subview.Frame.Y + 1), subview.Frame.Height - 1, Orientation.Vertical, subview.Border.BorderStyle);
foreach (var subview in contentView.Subviews) {
lc.AddLine (new Point (subview.Frame.X + 1, subview.Frame.Y + 1), subview.Frame.Width - 1, Orientation.Horizontal, subview.Border.BorderStyle);
lc.AddLine (new Point (subview.Frame.X + 1, subview.Frame.Y + 1), subview.Frame.Height - 1, Orientation.Vertical, subview.Border.BorderStyle);

// lc.AddLine (new Point (subview.Frame.X + subview.Frame.Width, subview.Frame.Y + subview.Frame.Height), -subview.Frame.Width + 1, Orientation.Horizontal, subview.Border.BorderStyle);
// lc.AddLine (new Point (subview.Frame.X + subview.Frame.Width, subview.Frame.Y + subview.Frame.Height), -subview.Frame.Height + 1, Orientation.Vertical, subview.Border.BorderStyle);
lc.AddLine (new Point (subview.Frame.X + subview.Frame.Width, subview.Frame.Y + subview.Frame.Height), -subview.Frame.Width + 1, Orientation.Horizontal, subview.Border.BorderStyle);
lc.AddLine (new Point (subview.Frame.X + subview.Frame.Width, subview.Frame.Y + subview.Frame.Height), -subview.Frame.Height + 1, Orientation.Vertical, subview.Border.BorderStyle);

//}
}

Driver.SetAttribute (ColorScheme.Normal);

foreach(var p in lc.GenerateImage (bounds)) {
AddRune (p.Key.X, p.Key.Y, p.Value);
}



// Redraw the lines so that focus/drag symbol renders
foreach (var subview in contentView.Subviews) {
// line.DrawSplitterSymbol ();
}


// Draw Titles over Border
foreach (var subview in contentView.Subviews) {
// TODO: Use reflection to see if subview has a Title property
Expand Down
149 changes: 64 additions & 85 deletions UICatalog/Scenarios/TileViewExperiment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,104 +27,83 @@ public override void Setup ()

Application.Top.Add (menu);

var frame1 = new FrameView () {
var frame = new FrameView () {
X = 0,
Y = 1,
Width = 15, //Dim.Fill (),
Height = 15, //Dim.Fill (),
//IgnoreBorderPropertyOnRedraw = true

Width = Dim.Fill (),
Height = Dim.Fill (),
IgnoreBorderPropertyOnRedraw = true
};
frame1.Border.BorderStyle = BorderStyle.Double;
frame.Border.BorderStyle = BorderStyle.Double;

var frame2 = new FrameView () {
X = 0,
Y = Pos.Bottom (frame1) + 1,
Width = 15, //Dim.Fill (),
Height = 15, //Dim.Fill (),
//IgnoreBorderPropertyOnRedraw = true
Application.Top.Add (frame);

var view1 = new FrameView () {
Title = "View 1",
Text = "View1 30%/50% Single",
X = -1,
Y = -1,
Width = Dim.Percent (30),
Height = Dim.Percent (50),
ColorScheme = Colors.ColorSchemes ["Dialog"],
Border = new Border () { BorderStyle = BorderStyle.Single }
};
frame2.Border.BorderStyle = BorderStyle.Single;

//ConsoleDriver.Diagnostics ^= ConsoleDriver.DiagnosticFlags.FrameRuler;
frame.Add (view1);

Application.Top.Add (frame1);
//var view12splitter = new SplitterEventArgs

var view1 = new TextField () {
//Title = "View 1",
Text = "View1 30%/50% Single",
X = 0,
Y = 0,
Width = 14, //Dim.Percent (30) - 5,
Height = 14, //Dim.Percent (50) - 5,
ColorScheme = Colors.ColorSchemes ["Dialog"],
Border = new Border () {
BorderStyle = BorderStyle.Single,
//BorderThickness = new Thickness (1),
DrawMarginFrame = true,
Padding = new Thickness(1),
BorderBrush = Color.BrightMagenta,
Title = "Border Title"
}
var view2 = new FrameView () {
Title = "View 2",
Text = "View2 right of view1, 30%/70% Single.",
X = Pos.Right (view1) - 1,
Y = -1,
Width = Dim.Percent (30),
Height = Dim.Percent (70),
ColorScheme = Colors.ColorSchemes ["Error"],
Border = new Border () { BorderStyle = BorderStyle.Single }
};

frame1.Add (view1);
frame2.Add (view1);
frame.Add (view2);

var view3 = new FrameView () {
Title = "View 3",
Text = "View3 right of View2 Fill/Fill Single",
X = Pos.Right (view2) - 1,
Y = -1,
Width = Dim.Fill (-1),
Height = Dim.Fill (-1),
ColorScheme = Colors.ColorSchemes ["Menu"],
Border = new Border () { BorderStyle = BorderStyle.Single }
};

//var view12splitter = new SplitterEventArgs
frame.Add (view3);

var view4 = new FrameView () {
Title = "View 4",
Text = "View4 below View2 view2.Width/5 Single",
X = Pos.Left (view2),
Y = Pos.Bottom (view2) - 1,
Width = view2.Width,
Height = 5,
ColorScheme = Colors.ColorSchemes ["TopLevel"],
Border = new Border () { BorderStyle = BorderStyle.Single }
};

frame.Add (view4);

var view5 = new FrameView () {
Title = "View 5",
Text = "View5 below View4 view4.Width/5 Double",
X = Pos.Left (view2),
Y = Pos.Bottom (view4) - 1,
Width = view4.Width,
Height = 5,
ColorScheme = Colors.ColorSchemes ["TopLevel"],
Border = new Border () { BorderStyle = BorderStyle.Double }
};

//var view2 = new FrameView () {
// Title = "View 2",
// Text = "View2 right of view1, 30%/70% Single.",
// X = Pos.Right (view1) - 1,
// Y = -1,
// Width = Dim.Percent (30),
// Height = Dim.Percent (70),
// ColorScheme = Colors.ColorSchemes ["Error"],
// Border = new Border () { BorderStyle = BorderStyle.Single }
//};

//frame.Add (view2);

//var view3 = new FrameView () {
// Title = "View 3",
// Text = "View3 right of View2 Fill/Fill Single",
// X = Pos.Right (view2) - 1,
// Y = -1,
// Width = Dim.Fill (-1),
// Height = Dim.Fill (-1),
// ColorScheme = Colors.ColorSchemes ["Menu"],
// Border = new Border () { BorderStyle = BorderStyle.Single }
//};

//frame.Add (view3);

//var view4 = new FrameView () {
// Title = "View 4",
// Text = "View4 below View2 view2.Width/5 Single",
// X = Pos.Left (view2),
// Y = Pos.Bottom (view2) - 1,
// Width = view2.Width,
// Height = 5,
// ColorScheme = Colors.ColorSchemes ["TopLevel"],
// Border = new Border () { BorderStyle = BorderStyle.Single }
//};

//frame.Add (view4);

//var view5 = new FrameView () {
// Title = "View 5",
// Text = "View5 below View4 view4.Width/5 Double",
// X = Pos.Left (view2),
// Y = Pos.Bottom (view4) - 1,
// Width = view4.Width,
// Height = 5,
// ColorScheme = Colors.ColorSchemes ["TopLevel"],
// Border = new Border () { BorderStyle = BorderStyle.Double }
//};

//frame.Add (view5);
frame.Add (view5);
}
}
}
15 changes: 8 additions & 7 deletions UnitTests/Core/LineCanvasTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,14 @@ private View GetCanvas (out LineCanvas canvas, int offsetX = 0, int offsetY = 0)

var canvasCopy = canvas = new LineCanvas ();
v.DrawContentComplete += (r) => {
foreach (var p in canvasCopy.GenerateImage (v.Bounds)) {
v.AddRune (
offsetX + p.Key.X,
offsetY + p.Key.Y,
p.Value);
}
};
foreach(var p in canvasCopy.GenerateImage(v.Bounds))
{
v.AddRune(
offsetX + p.Key.X,
offsetY + p.Key.Y,
p.Value);
}
};

return v;
}
Expand Down
Loading

0 comments on commit 44c6978

Please sign in to comment.