mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-30 09:47:58 +01:00
Fixed MessagBox paint issue
This commit is contained in:
@@ -386,66 +386,6 @@ public static class MessageBox
|
||||
messageLabel.TextFormatter.MultiLine = !wrapMessage;
|
||||
d.Add (messageLabel);
|
||||
|
||||
d.Loaded += (s, e) =>
|
||||
{
|
||||
if (width != 0 || height != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: replace with Dim.Fit when implemented
|
||||
Rectangle maxBounds = d.SuperView?.Bounds ?? Application.Top.Bounds;
|
||||
|
||||
Thickness adornmentsThickness = d.GetAdornmentsThickness ();
|
||||
|
||||
if (wrapMessage)
|
||||
{
|
||||
messageLabel.TextFormatter.Size = new (
|
||||
maxBounds.Size.Width
|
||||
- adornmentsThickness.Horizontal,
|
||||
maxBounds.Size.Height
|
||||
- adornmentsThickness.Vertical
|
||||
);
|
||||
}
|
||||
|
||||
string msg = messageLabel.TextFormatter.Format ();
|
||||
Size messageSize = messageLabel.TextFormatter.FormatAndGetSize ();
|
||||
|
||||
// Ensure the width fits the text + buttons
|
||||
int newWidth = Math.Max (
|
||||
width,
|
||||
Math.Max (
|
||||
messageSize.Width + adornmentsThickness.Horizontal,
|
||||
d.GetButtonsWidth () + d.Buttons.Length + adornmentsThickness.Horizontal
|
||||
)
|
||||
);
|
||||
|
||||
if (newWidth > d.Frame.Width)
|
||||
{
|
||||
d.Width = newWidth;
|
||||
}
|
||||
|
||||
// Ensure height fits the text + vspace + buttons
|
||||
if (messageSize.Height == 0)
|
||||
{
|
||||
d.Height = Math.Max (height, 3 + adornmentsThickness.Vertical);
|
||||
}
|
||||
else
|
||||
{
|
||||
string lastLine = messageLabel.TextFormatter.GetLines () [^1];
|
||||
|
||||
// INTENT: Instead of the check against \n or \r\n, how about just Environment.NewLine?
|
||||
d.Height = Math.Max (
|
||||
height,
|
||||
messageSize.Height
|
||||
+ (lastLine.EndsWith ("\r\n") || lastLine.EndsWith ('\n') ? 1 : 2)
|
||||
+ adornmentsThickness.Vertical
|
||||
);
|
||||
}
|
||||
|
||||
d.SetRelativeLayout (d.SuperView?.Frame ?? Application.Top.Frame);
|
||||
};
|
||||
|
||||
// Setup actions
|
||||
Clicked = -1;
|
||||
|
||||
@@ -466,10 +406,69 @@ public static class MessageBox
|
||||
}
|
||||
}
|
||||
|
||||
d.Loaded += Dialog_Loaded;
|
||||
|
||||
// Run the modal; do not shutdown the mainloop driver when done
|
||||
Application.Run (d);
|
||||
d.Dispose ();
|
||||
|
||||
return Clicked;
|
||||
|
||||
void Dialog_Loaded (object s, EventArgs e)
|
||||
{
|
||||
if (width != 0 || height != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: replace with Dim.Fit when implemented
|
||||
Rectangle maxBounds = d.SuperView?.Bounds ?? Application.Top.Bounds;
|
||||
|
||||
Thickness adornmentsThickness = d.GetAdornmentsThickness ();
|
||||
|
||||
if (wrapMessage)
|
||||
{
|
||||
messageLabel.TextFormatter.Size = new (
|
||||
maxBounds.Size.Width
|
||||
- adornmentsThickness.Horizontal,
|
||||
maxBounds.Size.Height
|
||||
- adornmentsThickness.Vertical);
|
||||
}
|
||||
|
||||
string msg = messageLabel.TextFormatter.Format ();
|
||||
Size messageSize = messageLabel.TextFormatter.FormatAndGetSize ();
|
||||
|
||||
// Ensure the width fits the text + buttons
|
||||
int newWidth = Math.Max (
|
||||
width,
|
||||
Math.Max (
|
||||
messageSize.Width + adornmentsThickness.Horizontal,
|
||||
d.GetButtonsWidth () + d.Buttons.Length + adornmentsThickness.Horizontal));
|
||||
|
||||
if (newWidth > d.Frame.Width)
|
||||
{
|
||||
d.Width = newWidth;
|
||||
}
|
||||
|
||||
// Ensure height fits the text + vspace + buttons
|
||||
if (messageSize.Height == 0)
|
||||
{
|
||||
d.Height = Math.Max (height, 3 + adornmentsThickness.Vertical);
|
||||
}
|
||||
else
|
||||
{
|
||||
string lastLine = messageLabel.TextFormatter.GetLines () [^1];
|
||||
|
||||
// INTENT: Instead of the check against \n or \r\n, how about just Environment.NewLine?
|
||||
d.Height = Math.Max (
|
||||
height,
|
||||
messageSize.Height
|
||||
+ (lastLine.EndsWith ("\r\n") || lastLine.EndsWith ('\n') ? 1 : 2)
|
||||
+ adornmentsThickness.Vertical);
|
||||
}
|
||||
|
||||
d.SetRelativeLayout (d.SuperView?.Frame ?? Application.Top.Frame);
|
||||
d.LayoutSubviews ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,8 +61,6 @@ public class Buttons : Scenario
|
||||
{
|
||||
ColorScheme = colorScheme.Value,
|
||||
X = Pos.Right (prev) + 2,
|
||||
|
||||
//X = x,
|
||||
Y = Pos.Y (colorButtonsLabel),
|
||||
Text = $"_{colorScheme.Key}"
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user