mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
Fixed multiline dialog layout (#160)
This commit is contained in:
committed by
Miguel de Icaza
parent
57c926e7ef
commit
a88cb16b30
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user