Skip to content

Commit 9697f9d

Browse files
committed
Merge branch 'develop' of tig:gui-cs/Terminal.Gui into develop
2 parents 59d164a + daf8512 commit 9697f9d

File tree

11 files changed

+107
-28
lines changed

11 files changed

+107
-28
lines changed

Terminal.Gui/ConsoleDrivers/WindowsDriver.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ MouseEvent ToDriverMouse (WindowsConsole.MouseEventRecord mouseEvent)
11251125
} else if (mouseEvent.EventFlags == WindowsConsole.EventFlags.MouseMoved) {
11261126
if (mouseEvent.MousePosition.X != pointMove.X || mouseEvent.MousePosition.Y != pointMove.Y) {
11271127
mouseFlag = MouseFlags.ReportMousePosition;
1128-
pointMove = new Point ();
1128+
pointMove = new Point (mouseEvent.MousePosition.X, mouseEvent.MousePosition.Y);
11291129
} else {
11301130
mouseFlag = 0;
11311131
}

Terminal.Gui/Core/Border.cs

+86-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using NStack;
2+
using System;
23

34
namespace Terminal.Gui {
45
/// <summary>
@@ -138,7 +139,7 @@ void Border_BorderChanged (Border border)
138139
/// <summary>
139140
/// Initializes with default null values.
140141
/// </summary>
141-
public ToplevelContainer () : this (null, null) { }
142+
public ToplevelContainer () : this (null, string.Empty) { }
142143

143144
/// <summary>
144145
/// Initializes a <see cref="ToplevelContainer"/> with a <see cref="LayoutStyle.Computed"/>
@@ -147,7 +148,7 @@ public ToplevelContainer () : this (null, null) { }
147148
/// <param name="title">The title.</param>
148149
public ToplevelContainer (Border border, string title = null)
149150
{
150-
Initialize (Rect.Empty, border, title);
151+
Initialize (Rect.Empty, border, title ?? string.Empty);
151152
}
152153

153154
/// <summary>
@@ -158,17 +159,17 @@ public ToplevelContainer (Border border, string title = null)
158159
/// <param name="title">The title.</param>
159160
public ToplevelContainer (Rect frame, Border border, string title = null) : base (frame)
160161
{
161-
Initialize (frame, border, title);
162+
Initialize (frame, border, title ?? string.Empty);
162163
}
163164

164-
private void Initialize (Rect frame, Border border, string title = null)
165+
private void Initialize (Rect frame, Border border, string title)
165166
{
166167
ColorScheme = Colors.TopLevel;
167-
Text = title ?? "";
168168
if (border == null) {
169169
Border = new Border () {
170170
BorderStyle = BorderStyle.Single,
171-
BorderBrush = ColorScheme.Normal.Background
171+
BorderBrush = ColorScheme.Normal.Background,
172+
Title = (ustring)title
172173
};
173174
} else {
174175
Border = border;
@@ -266,8 +267,12 @@ public override void Redraw (Rect bounds)
266267
Border.DrawContent (this, false);
267268
if (HasFocus)
268269
Driver.SetAttribute (ColorScheme.HotNormal);
269-
if (Border.DrawMarginFrame)
270-
Border.DrawTitle (this, Frame);
270+
if (Border.DrawMarginFrame) {
271+
if (!ustring.IsNullOrEmpty (Border.Title))
272+
Border.DrawTitle (this);
273+
else
274+
Border.DrawTitle (this, Frame);
275+
}
271276
Driver.SetAttribute (GetNormalColor ());
272277

273278
// Checks if there are any SuperView view which intersect with this window.
@@ -306,16 +311,20 @@ public override bool MouseEvent (MouseEvent mouseEvent)
306311
}
307312

308313
/// <summary>
309-
/// Event to be invoked when any border property change.
314+
/// Invoked when any property of Border changes (except <see cref="Child"/>).
310315
/// </summary>
311316
public event Action<Border> BorderChanged;
312317

313318
private BorderStyle borderStyle;
314319
private bool drawMarginFrame;
315320
private Thickness borderThickness;
321+
private Color borderBrush;
322+
private Color background;
316323
private Thickness padding;
317324
private bool effect3D;
318325
private Point effect3DOffset = new Point (1, 1);
326+
private Attribute? effect3DBrush;
327+
private ustring title = ustring.Empty;
319328

320329
/// <summary>
321330
/// Specifies the <see cref="Gui.BorderStyle"/> for a view.
@@ -363,12 +372,24 @@ public Thickness BorderThickness {
363372
/// <summary>
364373
/// Gets or sets the <see cref="Color"/> that draws the outer border color.
365374
/// </summary>
366-
public Color BorderBrush { get; set; }
375+
public Color BorderBrush {
376+
get => borderBrush;
377+
set {
378+
borderBrush = value;
379+
OnBorderChanged ();
380+
}
381+
}
367382

368383
/// <summary>
369384
/// Gets or sets the <see cref="Color"/> that fills the area between the bounds of a <see cref="Border"/>.
370385
/// </summary>
371-
public Color Background { get; set; }
386+
public Color Background {
387+
get => background;
388+
set {
389+
background = value;
390+
OnBorderChanged ();
391+
}
392+
}
372393

373394
/// <summary>
374395
/// Gets or sets a <see cref="Thickness"/> value that describes the amount of space between a
@@ -448,7 +469,24 @@ public Point Effect3DOffset {
448469
/// <summary>
449470
/// Gets or sets the color for the <see cref="Border"/>
450471
/// </summary>
451-
public Attribute? Effect3DBrush { get; set; }
472+
public Attribute? Effect3DBrush {
473+
get => effect3DBrush;
474+
set {
475+
effect3DBrush = value;
476+
OnBorderChanged ();
477+
}
478+
}
479+
480+
/// <summary>
481+
/// The title to be displayed for this view.
482+
/// </summary>
483+
public ustring Title {
484+
get => title;
485+
set {
486+
title = value;
487+
OnBorderChanged ();
488+
}
489+
}
452490

453491
/// <summary>
454492
/// Calculate the sum of the <see cref="Padding"/> and the <see cref="BorderThickness"/>
@@ -677,6 +715,7 @@ private void DrawChildBorder (Rect frame, bool fill = true)
677715
};
678716
if (rect.Width > 0 && rect.Height > 0) {
679717
driver.DrawWindowFrame (rect, 1, 1, 1, 1, BorderStyle != BorderStyle.None, fill, this);
718+
DrawTitle (Child);
680719
}
681720
}
682721

@@ -831,6 +870,7 @@ private void DrawParentBorder (Rect frame, bool fill = true)
831870
};
832871
if (rect.Width > 0 && rect.Height > 0) {
833872
driver.DrawWindowFrame (rect, 1, 1, 1, 1, BorderStyle != BorderStyle.None, fill, this);
873+
DrawTitle (Parent);
834874
}
835875
}
836876

@@ -900,18 +940,47 @@ private void AddRuneAt (ConsoleDriver driver, int col, int row, Rune ch)
900940
}
901941

902942
/// <summary>
903-
/// Drawn the view text from a <see cref="View"/>.
943+
/// Draws the view <see cref="Title"/> to the screen.
904944
/// </summary>
945+
/// <param name="view">The view.</param>
946+
public void DrawTitle (View view)
947+
{
948+
var driver = Application.Driver;
949+
if (DrawMarginFrame) {
950+
driver.SetAttribute (Child.GetNormalColor ());
951+
if (Child.HasFocus)
952+
driver.SetAttribute (Child.ColorScheme.HotNormal);
953+
var padding = view.Border.GetSumThickness ();
954+
Rect scrRect;
955+
if (view == Child) {
956+
scrRect = view.ViewToScreen (new Rect (0, 0, view.Frame.Width + 2, view.Frame.Height + 2));
957+
scrRect = new Rect (scrRect.X - 1, scrRect.Y - 1, scrRect.Width, scrRect.Height);
958+
driver.DrawWindowTitle (scrRect, Title, 0, 0, 0, 0);
959+
} else {
960+
scrRect = view.ViewToScreen (new Rect (0, 0, view.Frame.Width, view.Frame.Height));
961+
driver.DrawWindowTitle (scrRect, Title,
962+
padding.Left, padding.Top, padding.Right, padding.Bottom);
963+
}
964+
}
965+
driver.SetAttribute (Child.GetNormalColor ());
966+
}
967+
968+
/// <summary>
969+
/// Draws the <see cref="View.Text"/> to the screen.
970+
/// </summary>
971+
/// <param name="view">The view.</param>
972+
/// <param name="rect">The frame.</param>
905973
public void DrawTitle (View view, Rect rect)
906974
{
907975
var driver = Application.Driver;
908-
if (BorderStyle != BorderStyle.None) {
976+
if (DrawMarginFrame) {
909977
driver.SetAttribute (view.GetNormalColor ());
910978
if (view.HasFocus) {
911979
driver.SetAttribute (view.ColorScheme.HotNormal);
912980
}
913-
var padding = GetSumThickness ();
914-
driver.DrawWindowTitle (rect, view.Text,
981+
var padding = Parent.Border.GetSumThickness ();
982+
var scrRect = Parent.ViewToScreen (new Rect (0, 0, rect.Width, rect.Height));
983+
driver.DrawWindowTitle (scrRect, view.Text,
915984
padding.Left, padding.Top, padding.Right, padding.Bottom);
916985
}
917986
driver.SetAttribute (view.GetNormalColor ());

Terminal.Gui/Views/PanelView.cs

+1
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ public override void Redraw (Rect bounds)
236236
{
237237
if (!NeedDisplay.IsEmpty) {
238238
Driver.SetAttribute (Child.GetNormalColor ());
239+
Clear ();
239240
Child.Border.DrawContent (Border.Child);
240241
}
241242
var savedClip = childContentView.ClipToBounds ();

Terminal.Gui/Windows/MessageBox.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ static int QueryFull (bool useErrorColors, int width, int height, ustring title,
242242
const int defaultWidth = 50;
243243
int textWidth = TextFormatter.MaxWidth (message, width == 0 ? defaultWidth : width);
244244
int textHeight = TextFormatter.MaxLines (message, textWidth); // message.Count (ustring.Make ('\n')) + 1;
245-
int msgboxHeight = Math.Max (1, textHeight) + 3; // textHeight + (top + top padding + buttons + bottom)
245+
int msgboxHeight = Math.Max (1, textHeight) + 4; // textHeight + (top + top padding + buttons + bottom)
246246

247247
// Create button array for Dialog
248248
int count = 0;

Terminal.Gui/Windows/Wizard.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ public WizardStep (ustring title)
204204
base.Add (contentView);
205205

206206
helpTextView.ColorScheme = new ColorScheme () {
207-
Normal = new Attribute(Color.Gray, Color.DarkGray)
207+
Normal = new Attribute(Color.Gray, Color.DarkGray),
208+
Focus = new Attribute(Color.DarkGray, Color.Gray),
209+
HotFocus = new Attribute(Color.White, Color.DarkGray)
208210
};
209211
helpTextView.ReadOnly = true;
210212
helpTextView.WordWrap = true;

UICatalog/Scenarios/Borders.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ public override void Setup ()
3030
BorderBrush = borderBrush,
3131
Padding = padding,
3232
Background = background,
33-
Effect3D = effect3D
33+
Effect3D = effect3D,
34+
Title = "Panel"
3435
},
36+
ColorScheme = Colors.TopLevel
3537
};
3638
smartPanel.Add (new Label () { // Or smartPanel.Child =
3739
X = 0,
@@ -79,7 +81,8 @@ public override void Setup ()
7981
BorderBrush = borderBrush,
8082
Padding = padding,
8183
Background = background,
82-
Effect3D = effect3D
84+
Effect3D = effect3D,
85+
Title = "Label"
8386
},
8487
ColorScheme = Colors.TopLevel,
8588
Text = "This is a test\nwithout a \nPanelView",

UICatalog/Scenarios/BordersComparisons.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ public override void Init (Toplevel top, ColorScheme colorScheme)
6565
BorderBrush = borderBrush,
6666
Padding = padding,
6767
Background = background,
68-
Effect3D = effect3D
69-
},
70-
"Test2") {
68+
Effect3D = effect3D,
69+
Title = "Test2"
70+
}) {
7171
ColorScheme = Colors.Base,
7272
};
7373

UICatalog/Scenarios/BordersOnFrameView.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public override void Setup ()
3030
BorderBrush = borderBrush,
3131
Padding = padding,
3232
Background = background,
33-
Effect3D = effect3D
33+
Effect3D = effect3D,
34+
Title = "Frame"
3435
},
3536
ColorScheme = Colors.TopLevel
3637
};

UICatalog/Scenarios/BordersOnToplevel.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public override void Setup ()
3030
BorderBrush = borderBrush,
3131
Padding = padding,
3232
Background = background,
33-
Effect3D = effect3D
33+
Effect3D = effect3D,
34+
Title = "Toplevel"
3435
},
3536
ColorScheme = Colors.TopLevel
3637
};

UICatalog/Scenarios/BordersOnWindow.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public override void Setup ()
3030
BorderBrush = borderBrush,
3131
Padding = padding,
3232
Background = background,
33-
Effect3D = effect3D
33+
Effect3D = effect3D,
34+
Title = "Window"
3435
},
3536
ColorScheme = Colors.TopLevel
3637
};

UnitTests/BorderTests.cs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public void Constructor_Defaults ()
2626
Assert.False (b.Effect3D);
2727
Assert.Equal (new Point (1, 1), b.Effect3DOffset);
2828
Assert.Null (b.Effect3DBrush);
29+
Assert.Equal (NStack.ustring.Empty, b.Title);
2930
}
3031

3132
[Fact]

0 commit comments

Comments
 (0)