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

Fixes #2717. Label not display fully when resizing terminal. #2718

Merged
merged 5 commits into from
Jul 5, 2023
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
40 changes: 25 additions & 15 deletions Terminal.Gui/Core/TextFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1176,24 +1176,35 @@ public void Draw (Rect bounds, Attribute normalColor, Attribute hotColor, Rect c
}

var isVertical = IsVerticalDirection (textDirection);
var savedClip = Application.Driver?.Clip;
var maxBounds = bounds;
if (Application.Driver != null) {
Application.Driver.Clip = maxBounds = containerBounds == default
? bounds
: new Rect (Math.Max (containerBounds.X, bounds.X),
var maxBounds = containerBounds == default
? bounds
: new Rect (Math.Max (containerBounds.X, bounds.X),
Math.Max (containerBounds.Y, bounds.Y),
Math.Max (Math.Min (containerBounds.Width, containerBounds.Right - bounds.Left), 0),
Math.Max (Math.Min (containerBounds.Height, containerBounds.Bottom - bounds.Top), 0));
}
Math.Max (Math.Max (containerBounds.Width, containerBounds.Right - bounds.Left), 0),
Math.Max (Math.Max (containerBounds.Height, containerBounds.Bottom - bounds.Top), 0));

int boundsStart = 0;
if (isVertical) {
if (bounds.X < 0) {
boundsStart = bounds.X;
}
} else {
if (bounds.Y < 0) {
boundsStart = bounds.Y;
}
}
for (int line = 0; line < linesFormated.Count; line++) {
if ((isVertical && line > bounds.Width) || (!isVertical && line > bounds.Height))
if (boundsStart < 0) {
boundsStart++;
continue;
}
if ((isVertical && line > bounds.Width) || (!isVertical && line > bounds.Height)) {
continue;
}
if ((isVertical && line >= maxBounds.Left + maxBounds.Width)
|| (!isVertical && line >= maxBounds.Top + maxBounds.Height))

|| (!isVertical && line >= maxBounds.Top + maxBounds.Height)) {
break;
}

var runes = lines [line].ToRunes ();

Expand Down Expand Up @@ -1278,8 +1289,9 @@ public void Draw (Rect bounds, Attribute normalColor, Attribute hotColor, Rect c
} else if (!fillRemaining && idx > runes.Length - 1) {
break;
}
if ((!isVertical && idx > maxBounds.Left + maxBounds.Width - bounds.X) || (isVertical && idx > maxBounds.Top + maxBounds.Height - bounds.Y))
if ((!isVertical && idx >= maxBounds.Left + maxBounds.Width - bounds.X) || (isVertical && idx >= maxBounds.Top + maxBounds.Height - bounds.Y)) {
break;
}

var rune = (Rune)' ';
if (isVertical) {
Expand Down Expand Up @@ -1316,8 +1328,6 @@ public void Draw (Rect bounds, Attribute normalColor, Attribute hotColor, Rect c
}
}
}
if (Application.Driver != null)
Application.Driver.Clip = (Rect)savedClip;
}
}
}
4 changes: 2 additions & 2 deletions Terminal.Gui/Core/View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ public void Clear (Rect regionScreen)
/// <param name="rcol">Absolute column; screen-relative.</param>
/// <param name="rrow">Absolute row; screen-relative.</param>
/// <param name="clipped">Whether to clip the result of the ViewToScreen method, if set to <see langword="true"/>, the rcol, rrow values are clamped to the screen (terminal) dimensions (0..TerminalDim-1).</param>
internal void ViewToScreen (int col, int row, out int rcol, out int rrow, bool clipped = true)
internal void ViewToScreen (int col, int row, out int rcol, out int rrow, bool clipped = false)
{
// Computes the real row, col relative to the screen.
rrow = row + frame.Y;
Expand Down Expand Up @@ -1268,7 +1268,7 @@ public void DrawHotString (ustring text, bool focused, ColorScheme scheme)
/// <param name="row">Row.</param>
/// <param name="clipped">Whether to clip the result of the ViewToScreen method,
/// if set to <see langword="true"/>, the col, row values are clamped to the screen (terminal) dimensions (0..TerminalDim-1).</param>
public void Move (int col, int row, bool clipped = true)
public void Move (int col, int row, bool clipped = false)
{
if (Driver.Rows == 0) {
return;
Expand Down
21 changes: 21 additions & 0 deletions UnitTests/Views/ViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4499,5 +4499,26 @@ public void Test_Nested_Views_With_Height_Equal_To_One ()
222";
TestHelpers.AssertDriverContentsAre (looksLike, output);
}

[Fact, AutoInitShutdown]
public void Move_And_ViewToScreen_Should_Not_Use_Clipped_Parameter_As_True_By_Default_But_Only_For_Cursor ()
{
var container = new View () { Width = 10, Height = 2 };
var top = new View () { Width = 10, Height = 1 };
var label = new Label ("Label");
top.Add (label);
var bottom = new View () { Y = 1, Width = 10, Height = 1 };
container.Add (top, bottom);
Application.Top.Add (container);
Application.Begin (Application.Top);

TestHelpers.AssertDriverContentsAre (@"
Label", output);

((FakeDriver)Application.Driver).SetBufferSize (10, 1);
Application.Refresh ();
TestHelpers.AssertDriverContentsAre (@"
Label", output);
}
}
}