Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed multiline dialog layout #160

Merged
merged 1 commit into from
Jan 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Terminal.Gui/Dialogs/MessageBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static int ErrorQuery (int width, int height, string title, string messag

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);
Expand All @@ -69,7 +69,7 @@ static int QueryFull (bool useErrorColors, int width, int height, string title,
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);
}

Expand Down
13 changes: 13 additions & 0 deletions Terminal.Gui/Views/Label.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,19 @@ public static int MeasureLines (ustring text, int width)
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>
Expand Down