mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-30 17:57:57 +01:00
Fixed dialog & messagebox
This commit is contained in:
@@ -962,11 +962,14 @@ namespace Terminal.Gui {
|
||||
LayoutFrames ();
|
||||
}
|
||||
|
||||
// TODO: v2 - Hack for now
|
||||
private void Border_BorderChanged (Border border)
|
||||
{
|
||||
BorderFrame.Thickness = border.BorderThickness;
|
||||
BorderFrame.BorderStyle = border.BorderStyle;
|
||||
if (!border.DrawMarginFrame) BorderFrame.BorderStyle = BorderStyle.None;
|
||||
if (BorderFrame.BorderStyle != BorderStyle.None) {
|
||||
BorderFrame.Thickness = new Thickness (1);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -38,13 +38,9 @@ namespace Terminal.Gui {
|
||||
[SerializableConfigurationProperty (Scope = typeof (ThemeScope))]
|
||||
public static Border DefaultBorder { get; set; } = new Border () {
|
||||
BorderStyle = BorderStyle.Single,
|
||||
DrawMarginFrame = false,
|
||||
Effect3D = true,
|
||||
Effect3DOffset = new Point (1, 1),
|
||||
};
|
||||
|
||||
internal List<Button> buttons = new List<Button> ();
|
||||
const int padding = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Dialog"/> class using <see cref="LayoutStyle.Computed"/> positioning
|
||||
@@ -62,7 +58,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: title, padding: padding)
|
||||
public Dialog (ustring title, int width, int height, params Button [] buttons) : base (title: title, padding: 0, border: DefaultBorder)
|
||||
{
|
||||
X = Pos.Center ();
|
||||
Y = Pos.Center ();
|
||||
@@ -130,7 +126,6 @@ namespace Terminal.Gui {
|
||||
public Dialog (ustring title, Border border, params Button [] buttons)
|
||||
: this (title: title, width: 0, height: 0, buttons: buttons)
|
||||
{
|
||||
Initialize (title, border);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -145,13 +140,8 @@ namespace Terminal.Gui {
|
||||
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)
|
||||
{
|
||||
Title = title;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a <see cref="Button"/> to the <see cref="Dialog"/>, its layout will be controlled by the <see cref="Dialog"/>
|
||||
@@ -226,7 +216,7 @@ namespace Terminal.Gui {
|
||||
if (shiftLeft > -1) {
|
||||
button.X = Pos.AnchorEnd (shiftLeft);
|
||||
} else {
|
||||
button.X = Frame.Width - shiftLeft;
|
||||
button.X = Bounds.Width - shiftLeft;
|
||||
}
|
||||
button.Y = Pos.AnchorEnd (1);
|
||||
}
|
||||
@@ -236,7 +226,7 @@ namespace Terminal.Gui {
|
||||
// Justify Buttons
|
||||
// leftmost and rightmost buttons are hard against edges. The rest are evenly spaced.
|
||||
|
||||
var spacing = (int)Math.Ceiling ((double)(Bounds.Width - buttonsWidth - (Border.DrawMarginFrame ? 2 : 0)) / (buttons.Count - 1));
|
||||
var spacing = (int)Math.Ceiling ((double)(Bounds.Width - buttonsWidth) / (buttons.Count - 1));
|
||||
for (int i = buttons.Count - 1; i >= 0; i--) {
|
||||
Button button = buttons [i];
|
||||
if (i == buttons.Count - 1) {
|
||||
@@ -245,7 +235,7 @@ namespace Terminal.Gui {
|
||||
} else {
|
||||
if (i == 0) {
|
||||
// first (leftmost) button - always hard flush left
|
||||
var left = Bounds.Width - ((Border.DrawMarginFrame ? 2 : 0) + Border.BorderThickness.Left + Border.BorderThickness.Right);
|
||||
var left = Bounds.Width + Border.BorderThickness.Horizontal;
|
||||
button.X = Pos.AnchorEnd (left);
|
||||
} else {
|
||||
shiftLeft += button.Frame.Width + (spacing);
|
||||
|
||||
@@ -247,9 +247,6 @@ namespace Terminal.Gui {
|
||||
[SerializableConfigurationProperty (Scope = typeof (ThemeScope))]
|
||||
public static Border DefaultBorder { get; set; } = new Border () {
|
||||
BorderStyle = BorderStyle.Single,
|
||||
DrawMarginFrame = false,
|
||||
Effect3D = true,
|
||||
Effect3DOffset = new Point (1, 1),
|
||||
};
|
||||
|
||||
static int QueryFull (bool useErrorColors, int width, int height, ustring title, ustring message,
|
||||
|
||||
@@ -125,11 +125,6 @@ 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),
|
||||
@@ -145,14 +140,6 @@ namespace UICatalog.Scenarios {
|
||||
};
|
||||
frame.Add (styleRadioGroup);
|
||||
|
||||
var ckbEffect3D = new CheckBox ("Effect3D", true) {
|
||||
X = Pos.Right (label) + 1,
|
||||
Y = Pos.Top (label) + 2
|
||||
};
|
||||
ckbEffect3D.Toggled += (s,e) => {
|
||||
border.Effect3D = (bool)!e.OldValue;
|
||||
};
|
||||
frame.Add (ckbEffect3D);
|
||||
var ckbWrapMessage = new CheckBox ("Wrap Message", true) {
|
||||
X = Pos.Right (label) + 1,
|
||||
Y = Pos.Top (label) + 3
|
||||
@@ -171,7 +158,6 @@ namespace UICatalog.Scenarios {
|
||||
defaultButtonEdit.Frame.Height +
|
||||
styleRadioGroup.Frame.Height +
|
||||
2 +
|
||||
ckbEffect3D.Frame.Height +
|
||||
ckbWrapMessage.Frame.Height;
|
||||
Application.Top.Loaded -= Top_Loaded;
|
||||
}
|
||||
@@ -213,9 +199,9 @@ namespace UICatalog.Scenarios {
|
||||
btns.Add (NumberToWords.Convert (i));
|
||||
}
|
||||
if (styleRadioGroup.SelectedItem == 0) {
|
||||
buttonPressedLabel.Text = $"{MessageBox.Query (width, height, titleEdit.Text.ToString (), messageEdit.Text.ToString (), defaultButton, border, (bool)ckbWrapMessage.Checked, btns.ToArray ())}";
|
||||
buttonPressedLabel.Text = $"{MessageBox.Query (width, height, titleEdit.Text.ToString (), messageEdit.Text.ToString (), defaultButton, null, (bool)ckbWrapMessage.Checked, btns.ToArray ())}";
|
||||
} else {
|
||||
buttonPressedLabel.Text = $"{MessageBox.ErrorQuery (width, height, titleEdit.Text.ToString (), messageEdit.Text.ToString (), defaultButton, border, (bool)ckbWrapMessage.Checked, btns.ToArray ())}";
|
||||
buttonPressedLabel.Text = $"{MessageBox.ErrorQuery (width, height, titleEdit.Text.ToString (), messageEdit.Text.ToString (), defaultButton, null, (bool)ckbWrapMessage.Checked, btns.ToArray ())}";
|
||||
}
|
||||
} catch (FormatException) {
|
||||
buttonPressedLabel.Text = "Invalid Options";
|
||||
|
||||
@@ -1407,7 +1407,8 @@ namespace Terminal.Gui.TopLevelTests {
|
||||
});
|
||||
|
||||
var firstIteration = false;
|
||||
Application.RunMainLoopIteration (ref rs, true, ref firstIteration); Assert.Equal (dialog, Application.MouseGrabView);
|
||||
Application.RunMainLoopIteration (ref rs, true, ref firstIteration);
|
||||
Assert.Equal (dialog, Application.MouseGrabView);
|
||||
|
||||
Assert.Equal (new Rect (25, 7, 30, 10), dialog.Frame);
|
||||
TestHelpers.AssertDriverContentsWithFrameAre (@"
|
||||
|
||||
Reference in New Issue
Block a user