mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-28 08:47:59 +01:00
@BDisp
Remove constructors with frame parameters from FrameView class.
This commit is contained in:
@@ -1,68 +1,61 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text;
|
||||
using static Terminal.Gui.ConfigurationManager;
|
||||
|
||||
namespace Terminal.Gui {
|
||||
namespace Terminal.Gui;
|
||||
/// <summary>
|
||||
/// The FrameView is a container frame that draws a frame around the contents. It is similar to
|
||||
/// a GroupBox in Windows.
|
||||
/// </summary>
|
||||
public class FrameView : View {
|
||||
/// <summary>
|
||||
/// The FrameView is a container frame that draws a frame around the contents. It is similar to
|
||||
/// a GroupBox in Windows.
|
||||
/// Initializes a new instance of the <see cref="Gui.FrameView"/> class using <see cref="LayoutStyle.Absolute"/> layout.
|
||||
/// </summary>
|
||||
public class FrameView : View {
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Gui.FrameView"/> class using <see cref="LayoutStyle.Absolute"/> layout.
|
||||
/// </summary>
|
||||
/// <param name="frame">Frame.</param>
|
||||
/// <param name="title">Title.</param>
|
||||
/// <param name="views">Views.</param>
|
||||
public FrameView (Rect frame, string title = null, View [] views = null) : base (frame)
|
||||
{
|
||||
SetInitialProperties (frame, title, views);
|
||||
/// <param name="title">Title.</param>
|
||||
/// <param name="views">Views.</param>
|
||||
public FrameView (string title = null, View [] views = null)
|
||||
{
|
||||
SetInitialProperties (title, views);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Gui.FrameView"/> class using <see cref="LayoutStyle.Computed"/> layout.
|
||||
/// </summary>
|
||||
/// <param name="title">Title.</param>
|
||||
public FrameView (string title)
|
||||
{
|
||||
SetInitialProperties (title, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Gui.FrameView"/> class using <see cref="LayoutStyle.Computed"/> layout.
|
||||
/// </summary>
|
||||
public FrameView () : this (title: string.Empty) { }
|
||||
|
||||
/// <summary>
|
||||
/// The default <see cref="LineStyle"/> for <see cref="FrameView"/>'s border. The default is <see cref="LineStyle.Single"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This property can be set in a Theme to change the default <see cref="LineStyle"/> for all <see cref="FrameView"/>s.
|
||||
/// </remarks>
|
||||
[SerializableConfigurationProperty (Scope = typeof (ThemeScope)), JsonConverter (typeof (JsonStringEnumConverter))]
|
||||
public static LineStyle DefaultBorderStyle { get; set; } = LineStyle.Single;
|
||||
|
||||
void SetInitialProperties (string title, View [] views = null)
|
||||
{
|
||||
this.Title = title;
|
||||
Border.Thickness = new Thickness (1);
|
||||
Border.LineStyle = DefaultBorderStyle;
|
||||
//Border.ColorScheme = ColorScheme;
|
||||
Border.Data = "Border";
|
||||
}
|
||||
|
||||
///<inheritdoc/>
|
||||
public override bool OnEnter (View view)
|
||||
{
|
||||
if (Subviews.Count == 0 || !Subviews.Any (subview => subview.CanFocus)) {
|
||||
Application.Driver?.SetCursorVisibility (CursorVisibility.Invisible);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Gui.FrameView"/> class using <see cref="LayoutStyle.Computed"/> layout.
|
||||
/// </summary>
|
||||
/// <param name="title">Title.</param>
|
||||
public FrameView (string title)
|
||||
{
|
||||
SetInitialProperties (Rect.Empty, title, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Gui.FrameView"/> class using <see cref="LayoutStyle.Computed"/> layout.
|
||||
/// </summary>
|
||||
public FrameView () : this (title: string.Empty) {
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The default <see cref="LineStyle"/> for <see cref="FrameView"/>'s border. The default is <see cref="LineStyle.Single"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This property can be set in a Theme to change the default <see cref="LineStyle"/> for all <see cref="FrameView"/>s.
|
||||
/// </remarks>
|
||||
[SerializableConfigurationProperty (Scope = typeof (ThemeScope)), JsonConverter (typeof (JsonStringEnumConverter))]
|
||||
public static LineStyle DefaultBorderStyle { get; set; } = LineStyle.Single;
|
||||
|
||||
void SetInitialProperties (Rect frame, string title, View [] views = null)
|
||||
{
|
||||
this.Title = title;
|
||||
Border.Thickness = new Thickness (1);
|
||||
Border.LineStyle = DefaultBorderStyle;
|
||||
//Border.ColorScheme = ColorScheme;
|
||||
Border.Data = "Border";
|
||||
}
|
||||
|
||||
///<inheritdoc/>
|
||||
public override bool OnEnter (View view)
|
||||
{
|
||||
if (Subviews.Count == 0 || !Subviews.Any (subview => subview.CanFocus)) {
|
||||
Application.Driver?.SetCursorVisibility (CursorVisibility.Invisible);
|
||||
}
|
||||
|
||||
return base.OnEnter (view);
|
||||
}
|
||||
return base.OnEnter (view);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,93 +1,86 @@
|
||||
using Microsoft.VisualStudio.TestPlatform.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Terminal.Gui.ViewsTests {
|
||||
public class FrameViewTests {
|
||||
readonly ITestOutputHelper output;
|
||||
namespace Terminal.Gui.ViewsTests;
|
||||
public class FrameViewTests {
|
||||
readonly ITestOutputHelper _output;
|
||||
|
||||
public FrameViewTests (ITestOutputHelper output)
|
||||
{
|
||||
this.output = output;
|
||||
}
|
||||
public FrameViewTests (ITestOutputHelper output)
|
||||
{
|
||||
this._output = output;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constuctors_Defaults ()
|
||||
{
|
||||
var fv = new FrameView ();
|
||||
Assert.Equal (string.Empty, fv.Title);
|
||||
Assert.Equal (string.Empty, fv.Text);
|
||||
Assert.Equal (LineStyle.Single, fv.BorderStyle);
|
||||
[Fact]
|
||||
public void Constructors_Defaults ()
|
||||
{
|
||||
var fv = new FrameView ();
|
||||
Assert.Equal (string.Empty, fv.Title);
|
||||
Assert.Equal (string.Empty, fv.Text);
|
||||
Assert.Equal (LineStyle.Single, fv.BorderStyle);
|
||||
|
||||
fv = new FrameView ("Test");
|
||||
Assert.Equal ("Test", fv.Title);
|
||||
Assert.Equal (string.Empty, fv.Text);
|
||||
Assert.Equal (LineStyle.Single, fv.BorderStyle);
|
||||
fv = new FrameView ("Test");
|
||||
Assert.Equal ("Test", fv.Title);
|
||||
Assert.Equal (string.Empty, fv.Text);
|
||||
Assert.Equal (LineStyle.Single, fv.BorderStyle);
|
||||
|
||||
fv = new FrameView (new Rect (1, 2, 10, 20), "Test");
|
||||
Assert.Equal ("Test", fv.Title);
|
||||
Assert.Equal (string.Empty, fv.Text);
|
||||
fv.BeginInit ();
|
||||
fv.EndInit ();
|
||||
Assert.Equal (LineStyle.Single, fv.BorderStyle);
|
||||
Assert.Equal (new Rect (1, 2, 10, 20), fv.Frame);
|
||||
}
|
||||
fv = new FrameView ("Test") { X = 1, Y = 2, Width = 10, Height = 20 };
|
||||
Assert.Equal ("Test", fv.Title);
|
||||
Assert.Equal (string.Empty, fv.Text);
|
||||
fv.BeginInit ();
|
||||
fv.EndInit ();
|
||||
Assert.Equal (LineStyle.Single, fv.BorderStyle);
|
||||
Assert.Equal (new Rect (1, 2, 10, 20), fv.Frame);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void Draw_Defaults ()
|
||||
{
|
||||
((FakeDriver)Application.Driver).SetBufferSize (10, 10);
|
||||
var fv = new FrameView ();
|
||||
Assert.Equal (string.Empty, fv.Title);
|
||||
Assert.Equal (string.Empty, fv.Text);
|
||||
Application.Top.Add (fv);
|
||||
Application.Begin (Application.Top);
|
||||
Assert.Equal (new Rect (0, 0, 0, 0), fv.Frame);
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"", output);
|
||||
[Fact, AutoInitShutdown]
|
||||
public void Draw_Defaults ()
|
||||
{
|
||||
((FakeDriver)Application.Driver).SetBufferSize (10, 10);
|
||||
var fv = new FrameView ();
|
||||
Assert.Equal (string.Empty, fv.Title);
|
||||
Assert.Equal (string.Empty, fv.Text);
|
||||
Application.Top.Add (fv);
|
||||
Application.Begin (Application.Top);
|
||||
Assert.Equal (new Rect (0, 0, 0, 0), fv.Frame);
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"", _output);
|
||||
|
||||
fv.Height = 5;
|
||||
fv.Width = 5;
|
||||
Assert.Equal (new Rect (0, 0, 5, 5), fv.Frame);
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
fv.Height = 5;
|
||||
fv.Width = 5;
|
||||
Assert.Equal (new Rect (0, 0, 5, 5), fv.Frame);
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
┌───┐
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
└───┘", output);
|
||||
└───┘", _output);
|
||||
|
||||
fv.X = 1;
|
||||
fv.Y = 2;
|
||||
Assert.Equal (new Rect (1, 2, 5, 5), fv.Frame);
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
fv.X = 1;
|
||||
fv.Y = 2;
|
||||
Assert.Equal (new Rect (1, 2, 5, 5), fv.Frame);
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
┌───┐
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
└───┘", output);
|
||||
└───┘", _output);
|
||||
|
||||
fv.X = -1;
|
||||
fv.Y = -2;
|
||||
Assert.Equal (new Rect (-1, -2, 5, 5), fv.Frame);
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
fv.X = -1;
|
||||
fv.Y = -2;
|
||||
Assert.Equal (new Rect (-1, -2, 5, 5), fv.Frame);
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
│
|
||||
│
|
||||
───┘", output);
|
||||
───┘", _output);
|
||||
|
||||
fv.X = 7;
|
||||
fv.Y = 8;
|
||||
Assert.Equal (new Rect (7, 8, 5, 5), fv.Frame);
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
fv.X = 7;
|
||||
fv.Y = 8;
|
||||
Assert.Equal (new Rect (7, 8, 5, 5), fv.Frame);
|
||||
Application.Refresh ();
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
┌──
|
||||
│ ", output);
|
||||
}
|
||||
│ ", _output);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user