Fixed multiline dialog layout (#160)

This commit is contained in:
Cameron MacFarland
2019-01-08 23:34:30 +08:00
committed by Miguel de Icaza
parent 57c926e7ef
commit a88cb16b30
2 changed files with 15 additions and 2 deletions

View File

@@ -52,7 +52,7 @@ namespace Terminal.Gui {
static int QueryFull (bool useErrorColors, int width, int height, string title, string message, params string [] buttons)
{
int lines = Label.MeasureLines (message, width);
int textWidth = Label.MaxWidth (message, width);
int clicked = -1, count = 0;
var d = new Dialog (title, width, height);
@@ -69,7 +69,7 @@ namespace Terminal.Gui {
d.AddButton (b);
}
if (message != null) {
var l = new Label ((width - 4 - message.Length) / 2, 0, message);
var l = new Label ((width - 4 - textWidth) / 2, 0, message);
d.Add (l);
}

View File

@@ -209,6 +209,19 @@ namespace Terminal.Gui {
return result.Count;
}
/// <summary>
/// Computes the the max width of a line or multilines needed to render by the Label control
/// </summary>
/// <returns>Max width of lines.</returns>
/// <param name="text">Text, may contain newlines.</param>
/// <param name="width">The width for the text.</param>
public static int MaxWidth(ustring text, int width)
{
var result = new List<ustring>();
Recalc(text, result, width, TextAlignment.Left);
return result.Max(s => s.RuneCount);
}
/// <summary>
/// The text displayed by this widget.
/// </summary>