Fixes #1861. Border: Title property is preferable to Text. (#1862)

* Fixes #1861. Border Title property is preferable than the Text.

* Fixes #1866. Bug when scrolling text and type in a TextView. (#1868)

* Some fixes for the WebConsole support. (#1865)

* Invoking NotifyStopRunState for all situations.

* Added Clicked property to support web console.

* Changing to MoveDown to stay always visible.

* Fixes #1849. Wizard as non-popup is broken (#1853)

* trying to make it work

* Fixes #1849. Wizard as non-modal doesn't work

* Fixes #1855. Window and Frame content view without the margin frame.

* Fixing layout of non-modal

* WizardSTep is now a FrameView

* Now use Modal = false to set visual style automatically

* Removed Controls as an explicit construct. Now just Add to WizardStep

Co-authored-by: BDisp <bd.bdisp@gmail.com>

* Update docs with keybindings, global key event and designer (#1869)

* Added docs on keybinding and global key event

* Added TerminalGuiDesigner to showcases/examples

* Regenerated Docs (#1870)

* Fixed cancel logic. Title now shows for non-modal. (#1871)

* Fixes #1874. API docs on github are broken. (#1875)

* Fixes #1874. API docs on github are broken.

* Rebuild with docfx 2.59.3.0 version.

* Fixes Wizard cancel logic and updates docs (#1878)

* Fixed cancel logic. Title now shows for non-modal.

* trying to fix docs

* trying to fix docs

* Fixes #1867. Use Undo and Redo commands with WordWrap enabled. (#1877)

* Updated docs; regeneraged docs (#1881)

* Added a 'Read Only' to the Editor scenario Format menu. (#1882)

* Fixes #1883. Toplevel now propogates Loaded & Ready events to child Toplevel views.

* Updated API doc theme. Added Wizard Sample

* Tweaked API docs format and content. Fixed build warnings.

* Fixes #1889. Docs broken after org move.

* Regen API docs

* Fixes readme links to API docs

* Avoiding breaking change.

* Fixes typos.

* Passing string.Empty to Title from the default constructor.

* Initializes title with string.Empty instead of null.

Co-authored-by: Tig Kindel <tig@users.noreply.github.com>
Co-authored-by: Thomas Nind <31306100+tznind@users.noreply.github.com>
This commit is contained in:
BDisp
2022-08-02 00:06:15 +01:00
committed by GitHub
parent a8ec4fd074
commit 49e2b95625
8 changed files with 102 additions and 25 deletions

View File

@@ -1,4 +1,5 @@
using System;
using NStack;
using System;
namespace Terminal.Gui {
/// <summary>
@@ -138,7 +139,7 @@ namespace Terminal.Gui {
/// <summary>
/// Initializes with default null values.
/// </summary>
public ToplevelContainer () : this (null, null) { }
public ToplevelContainer () : this (null, string.Empty) { }
/// <summary>
/// Initializes a <see cref="ToplevelContainer"/> with a <see cref="LayoutStyle.Computed"/>
@@ -147,7 +148,7 @@ namespace Terminal.Gui {
/// <param name="title">The title.</param>
public ToplevelContainer (Border border, string title = null)
{
Initialize (Rect.Empty, border, title);
Initialize (Rect.Empty, border, title ?? string.Empty);
}
/// <summary>
@@ -158,17 +159,17 @@ namespace Terminal.Gui {
/// <param name="title">The title.</param>
public ToplevelContainer (Rect frame, Border border, string title = null) : base (frame)
{
Initialize (frame, border, title);
Initialize (frame, border, title ?? string.Empty);
}
private void Initialize (Rect frame, Border border, string title = null)
private void Initialize (Rect frame, Border border, string title)
{
ColorScheme = Colors.TopLevel;
Text = title ?? "";
if (border == null) {
Border = new Border () {
BorderStyle = BorderStyle.Single,
BorderBrush = ColorScheme.Normal.Background
BorderBrush = ColorScheme.Normal.Background,
Title = (ustring)title
};
} else {
Border = border;
@@ -266,8 +267,12 @@ namespace Terminal.Gui {
Border.DrawContent (this, false);
if (HasFocus)
Driver.SetAttribute (ColorScheme.HotNormal);
if (Border.DrawMarginFrame)
Border.DrawTitle (this, Frame);
if (Border.DrawMarginFrame) {
if (!ustring.IsNullOrEmpty (Border.Title))
Border.DrawTitle (this);
else
Border.DrawTitle (this, Frame);
}
Driver.SetAttribute (GetNormalColor ());
// Checks if there are any SuperView view which intersect with this window.
@@ -306,16 +311,20 @@ namespace Terminal.Gui {
}
/// <summary>
/// Event to be invoked when any border property change.
/// Invoked when any property of Border changes (except <see cref="Child"/>).
/// </summary>
public event Action<Border> BorderChanged;
private BorderStyle borderStyle;
private bool drawMarginFrame;
private Thickness borderThickness;
private Color borderBrush;
private Color background;
private Thickness padding;
private bool effect3D;
private Point effect3DOffset = new Point (1, 1);
private Attribute? effect3DBrush;
private ustring title = ustring.Empty;
/// <summary>
/// Specifies the <see cref="Gui.BorderStyle"/> for a view.
@@ -363,12 +372,24 @@ namespace Terminal.Gui {
/// <summary>
/// Gets or sets the <see cref="Color"/> that draws the outer border color.
/// </summary>
public Color BorderBrush { get; set; }
public Color BorderBrush {
get => borderBrush;
set {
borderBrush = value;
OnBorderChanged ();
}
}
/// <summary>
/// Gets or sets the <see cref="Color"/> that fills the area between the bounds of a <see cref="Border"/>.
/// </summary>
public Color Background { get; set; }
public Color Background {
get => background;
set {
background = value;
OnBorderChanged ();
}
}
/// <summary>
/// Gets or sets a <see cref="Thickness"/> value that describes the amount of space between a
@@ -448,7 +469,24 @@ namespace Terminal.Gui {
/// <summary>
/// Gets or sets the color for the <see cref="Border"/>
/// </summary>
public Attribute? Effect3DBrush { get; set; }
public Attribute? Effect3DBrush {
get => effect3DBrush;
set {
effect3DBrush = value;
OnBorderChanged ();
}
}
/// <summary>
/// The title to be displayed for this view.
/// </summary>
public ustring Title {
get => title;
set {
title = value;
OnBorderChanged ();
}
}
/// <summary>
/// Calculate the sum of the <see cref="Padding"/> and the <see cref="BorderThickness"/>
@@ -677,6 +715,7 @@ namespace Terminal.Gui {
};
if (rect.Width > 0 && rect.Height > 0) {
driver.DrawWindowFrame (rect, 1, 1, 1, 1, BorderStyle != BorderStyle.None, fill, this);
DrawTitle (Child);
}
}
@@ -831,6 +870,7 @@ namespace Terminal.Gui {
};
if (rect.Width > 0 && rect.Height > 0) {
driver.DrawWindowFrame (rect, 1, 1, 1, 1, BorderStyle != BorderStyle.None, fill, this);
DrawTitle (Parent);
}
}
@@ -900,18 +940,47 @@ namespace Terminal.Gui {
}
/// <summary>
/// Drawn the view text from a <see cref="View"/>.
/// Draws the view <see cref="Title"/> to the screen.
/// </summary>
/// <param name="view">The view.</param>
public void DrawTitle (View view)
{
var driver = Application.Driver;
if (DrawMarginFrame) {
driver.SetAttribute (Child.GetNormalColor ());
if (Child.HasFocus)
driver.SetAttribute (Child.ColorScheme.HotNormal);
var padding = view.Border.GetSumThickness ();
Rect scrRect;
if (view == Child) {
scrRect = view.ViewToScreen (new Rect (0, 0, view.Frame.Width + 2, view.Frame.Height + 2));
scrRect = new Rect (scrRect.X - 1, scrRect.Y - 1, scrRect.Width, scrRect.Height);
driver.DrawWindowTitle (scrRect, Title, 0, 0, 0, 0);
} else {
scrRect = view.ViewToScreen (new Rect (0, 0, view.Frame.Width, view.Frame.Height));
driver.DrawWindowTitle (scrRect, Title,
padding.Left, padding.Top, padding.Right, padding.Bottom);
}
}
driver.SetAttribute (Child.GetNormalColor ());
}
/// <summary>
/// Draws the <see cref="View.Text"/> to the screen.
/// </summary>
/// <param name="view">The view.</param>
/// <param name="rect">The frame.</param>
public void DrawTitle (View view, Rect rect)
{
var driver = Application.Driver;
if (BorderStyle != BorderStyle.None) {
if (DrawMarginFrame) {
driver.SetAttribute (view.GetNormalColor ());
if (view.HasFocus) {
driver.SetAttribute (view.ColorScheme.HotNormal);
}
var padding = GetSumThickness ();
driver.DrawWindowTitle (rect, view.Text,
var padding = Parent.Border.GetSumThickness ();
var scrRect = Parent.ViewToScreen (new Rect (0, 0, rect.Width, rect.Height));
driver.DrawWindowTitle (scrRect, view.Text,
padding.Left, padding.Top, padding.Right, padding.Bottom);
}
driver.SetAttribute (view.GetNormalColor ());

View File

@@ -236,6 +236,7 @@ namespace Terminal.Gui {
{
if (!NeedDisplay.IsEmpty) {
Driver.SetAttribute (Child.GetNormalColor ());
Clear ();
Child.Border.DrawContent (Border.Child);
}
var savedClip = childContentView.ClipToBounds ();

View File

@@ -30,8 +30,10 @@ namespace UICatalog.Scenarios {
BorderBrush = borderBrush,
Padding = padding,
Background = background,
Effect3D = effect3D
Effect3D = effect3D,
Title = "Panel"
},
ColorScheme = Colors.TopLevel
};
smartPanel.Add (new Label () { // Or smartPanel.Child =
X = 0,
@@ -79,7 +81,8 @@ namespace UICatalog.Scenarios {
BorderBrush = borderBrush,
Padding = padding,
Background = background,
Effect3D = effect3D
Effect3D = effect3D,
Title = "Label"
},
ColorScheme = Colors.TopLevel,
Text = "This is a test\nwithout a \nPanelView",

View File

@@ -65,9 +65,9 @@ namespace UICatalog.Scenarios {
BorderBrush = borderBrush,
Padding = padding,
Background = background,
Effect3D = effect3D
},
"Test2") {
Effect3D = effect3D,
Title = "Test2"
}) {
ColorScheme = Colors.Base,
};

View File

@@ -30,7 +30,8 @@ namespace UICatalog.Scenarios {
BorderBrush = borderBrush,
Padding = padding,
Background = background,
Effect3D = effect3D
Effect3D = effect3D,
Title = "Frame"
},
ColorScheme = Colors.TopLevel
};

View File

@@ -30,7 +30,8 @@ namespace UICatalog.Scenarios {
BorderBrush = borderBrush,
Padding = padding,
Background = background,
Effect3D = effect3D
Effect3D = effect3D,
Title = "Toplevel"
},
ColorScheme = Colors.TopLevel
};

View File

@@ -30,7 +30,8 @@ namespace UICatalog.Scenarios {
BorderBrush = borderBrush,
Padding = padding,
Background = background,
Effect3D = effect3D
Effect3D = effect3D,
Title = "Window"
},
ColorScheme = Colors.TopLevel
};

View File

@@ -26,6 +26,7 @@ namespace Terminal.Gui.Core {
Assert.False (b.Effect3D);
Assert.Equal (new Point (1, 1), b.Effect3DOffset);
Assert.Null (b.Effect3DBrush);
Assert.Equal (NStack.ustring.Empty, b.Title);
}
[Fact]