Skip to content

Commit

Permalink
MaxWidth/MaxHeight taking into account before rendering. Fixes #45
Browse files Browse the repository at this point in the history
  • Loading branch information
elw00d committed Mar 9, 2018
1 parent 37fd4b1 commit bde72d5
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion ConsoleFramework/Controls/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ private struct MinMax

private Rect calculateLayoutClip() {
Vector offset = computeAlignmentOffset();
Size clientSize = getClientSize();
Size clientSize = getClippedClientSize();
return new Rect(-offset.X, -offset.Y, clientSize.Width, clientSize.Height);
}

Expand Down Expand Up @@ -908,6 +908,23 @@ private struct MinMax
Math.Max(0, renderSlotRect.Height - marginHeight));
}

/// <summary>
/// This method returns the size of layout slot computed with Max-constraints and
/// decreased by margins. This is the final size of layout slot that will be written
/// to layoutClipInfo.
/// </summary>
private Size getClippedClientSize() {
Thickness margin = Margin;
int marginWidth = margin.Left + margin.Right;
int marginHeight = margin.Top + margin.Bottom;

Rect renderSlotRect = RenderSlotRect;

// Take MaxWidth/MaxHeight into account when before applying margins
return new Size(Math.Max(0, Math.Min(renderSlotRect.Width, MaxWidth) - marginWidth),
Math.Max(0, Math.Min(renderSlotRect.Height, MaxHeight) - marginHeight));
}

private Vector computeAlignmentOffsetCore(Size clientSize, Size inkSize) {
Vector offset = new Vector();

Expand Down

0 comments on commit bde72d5

Please sign in to comment.