Fix the border not respecting the user settings.

This commit is contained in:
BDisp
2023-03-10 18:26:04 +00:00
committed by Tig
parent 88680bd763
commit e486664ccc
4 changed files with 90 additions and 11 deletions

View File

@@ -62,7 +62,7 @@ namespace Terminal.Gui {
/// <remarks>
/// Use the constructor that does not take a <c>width</c> and <c>height</c> instead.
/// </remarks>
public Dialog (ustring title, int width, int height, params Button [] buttons) : base (title, padding: padding)
public Dialog (ustring title, int width, int height, params Button [] buttons) : base (title: title, padding: padding)
{
X = Pos.Center ();
Y = Pos.Center ();
@@ -119,6 +119,42 @@ namespace Terminal.Gui {
/// </remarks>
public Dialog (ustring title, params Button [] buttons) : this (title: title, width: 0, height: 0, buttons: buttons) { }
/// <summary>
/// Initializes a new instance of the <see cref="Dialog"/> class using <see cref="LayoutStyle.Computed"/> positioning,
/// with a <see cref="Border"/> and with an optional set of <see cref="Button"/>s to display
/// </summary>
/// <param name="title">Title for the dialog.</param>
/// <param name="border">The border.</param>
/// <param name="buttons">Optional buttons to lay out at the bottom of the dialog.</param>
public Dialog (ustring title, Border border, params Button [] buttons)
: this (title: title, width: 0, height: 0, buttons: buttons)
{
Initialize (title, border);
}
/// <summary>
/// Initializes a new instance of the <see cref="Dialog"/> class using <see cref="LayoutStyle.Computed"/> positioning,
/// with a <see cref="Border"/> and with an optional set of <see cref="Button"/>s to display
/// </summary>
/// <param name="title">Title for the dialog.</param>
/// <param name="width">Width for the dialog.</param>
/// <param name="height">Height for the dialog.</param>
/// <param name="border">The border.</param>
/// <param name="buttons">Optional buttons to lay out at the bottom of the dialog.</param>
public Dialog (ustring title, int width, int height, Border border, params Button [] buttons)
: this (title: title, width: width, height: height, buttons: buttons)
{
Initialize (title, border);
}
void Initialize (ustring title, Border border)
{
if (border != null) {
Border = border;
Border.Title = title;
}
}
/// <summary>
/// Adds a <see cref="Button"/> to the <see cref="Dialog"/>, its layout will be controlled by the <see cref="Dialog"/>
/// </summary>

View File

@@ -281,15 +281,11 @@ namespace Terminal.Gui {
// Create Dialog (retain backwards compat by supporting specifying height/width)
Dialog d;
if (width == 0 & height == 0) {
d = new Dialog (title, buttonList.ToArray ()) {
d = new Dialog (title, border, buttonList.ToArray ()) {
Height = msgboxHeight
};
} else {
d = new Dialog (title, width, Math.Max (height, 4), buttonList.ToArray ());
}
if (border != null) {
d.Border = border;
d = new Dialog (title, width, Math.Max (height, 4), border, buttonList.ToArray ());
}
if (useErrorColors) {

View File

@@ -125,6 +125,11 @@ namespace UICatalog.Scenarios {
};
frame.Add (defaultButtonEdit);
var border = new Border () {
Effect3D = true,
BorderStyle = BorderStyle.Single
};
label = new Label ("Style:") {
X = 0,
Y = Pos.Bottom (label),
@@ -133,16 +138,25 @@ namespace UICatalog.Scenarios {
TextAlignment = Terminal.Gui.TextAlignment.Right,
};
frame.Add (label);
var styleRadioGroup = new RadioGroup (new ustring [] { "_Query", "_Error" }) {
X = Pos.Right (label) + 1,
Y = Pos.Top (label),
};
styleRadioGroup.SelectedItemChanged += e => {
switch (e.SelectedItem) {
case 0:
border.BorderBrush = Colors.Dialog.Normal.Foreground;
border.Background = Colors.Dialog.Normal.Background;
break;
case 1:
border.BorderBrush = Colors.Error.Normal.Foreground;
border.Background = Colors.Error.Normal.Background;
break;
}
};
frame.Add (styleRadioGroup);
var border = new Border () {
Effect3D = true,
BorderStyle = BorderStyle.Single
};
var ckbEffect3D = new CheckBox ("Effect3D", true) {
X = Pos.Right (label) + 1,
Y = Pos.Top (label) + 2

View File

@@ -319,5 +319,38 @@ ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
Application.Run ();
}
[Theory, AutoInitShutdown]
[InlineData ("", true)]
[InlineData ("", false)]
[InlineData ("\n", true)]
[InlineData ("\n", false)]
public void MessageBox_With_A_Empty_Message_Or_A_NewLline_WrapMessagge_True_Or_False (string message, bool wrapMessage)
{
var iterations = -1;
Application.Begin (Application.Top);
Application.Iteration += () => {
iterations++;
if (iterations == 0) {
MessageBox.Query ("mywindow", message, 0, null, wrapMessage, "ok");
Application.RequestStop ();
} else if (iterations == 1) {
Application.Refresh ();
TestHelpers.AssertDriverContentsWithFrameAre (@"
┌ mywindow ────────────────────────────────────┐
│ │
│ │
│ [◦ ok ◦] │
└──────────────────────────────────────────────┘", output);
Application.RequestStop ();
}
};
Application.Run ();
}
}
}