Skip to content

Commit

Permalink
#67 - fixed row shifts when console window is resized
Browse files Browse the repository at this point in the history
  • Loading branch information
lastunicorn committed Mar 21, 2022
1 parent 379f1c6 commit 854c007
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 40 deletions.
1 change: 1 addition & 0 deletions doc/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ver 1.1.0
---------
- [feature] Splitted the one nuget package into multiple packages.
- [feature] DataGrid: Add multiple rows ar once.
- [bugfix ] BlockControl: Fixed row shifting when console window is resized.

ver 1.0.0
---------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ protected int AvailableWidth
switch (DefaultParent)
{
case DefaultParent.ConsoleBuffer:
return Console.BufferWidth;
return Console.BufferWidth - 1;

case DefaultParent.ConsoleWindow:
return Console.WindowWidth;
return Console.WindowWidth - 1;

default:
throw new ArgumentOutOfRangeException();
Expand Down
19 changes: 7 additions & 12 deletions sources/ConsoleTools/ConsoleTools.Core/Controls/ControlDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,44 +151,39 @@ private void SetCustomBackgroundColor(ConsoleColor? backgroundColor)
/// </summary>
public void EndRow()
{
bool isConsoleRowFull = FillEmptySpace();
FillContentEmptySpace();
WriteRightPadding();

RestoreForegroundColor();
RestoreBackgroundColor();

WriteRightMargin();
WriteOuterRightEmptySpace();

if (!isConsoleRowFull)
Console.WriteLine();

Console.WriteLine();

RowCount++;
}

private bool FillEmptySpace()
private void FillContentEmptySpace()
{
if (Layout == null)
return false;
return;

int cursorLeft = Console.CursorLeft;

if (cursorLeft >= Layout.ActualFullWidth)
return false;
return;

int marginRight = Layout.MarginRight;
int paddingRight = Layout.PaddingRight;
int emptySpaceRight = Layout.ActualFullWidth - cursorLeft - paddingRight - marginRight;

if (emptySpaceRight <= 0)
return false;
return;

string rightContentEmptySpace = new string(' ', emptySpaceRight);
CustomConsole.Write(rightContentEmptySpace);

int currentCursorPosition = cursorLeft + emptySpaceRight + paddingRight + marginRight;
bool isConsoleRowFull = currentCursorPosition == Console.BufferWidth;
return isConsoleRowFull;
}

private void RestoreForegroundColor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,11 @@ internal class Program
{
private static void Main()
{
Console.WriteLine($"Window: {Console.WindowWidth} : {Console.WindowHeight}");
Console.WriteLine($"Buffer: {Console.BufferWidth} : {Console.BufferHeight}");
Console.SetWindowSize(80, 50);
Console.SetBufferSize(160, 512);

ConsoleColor oldColor = Console.BackgroundColor;
Console.BackgroundColor = ConsoleColor.Blue;

string lessThanLine = new string('*', 100);
string fullLine = new string('*', 120);
string moreThanLine = new string('*', 140);

Console.WriteLine();
Console.WriteLine(lessThanLine);

Console.WriteLine();
Console.WriteLine(fullLine);
Console.WriteLine("something");

Console.WriteLine();
Console.WriteLine(moreThanLine);

Console.BackgroundColor = oldColor;

//Console.SetWindowSize(80, 50);
//Console.SetBufferSize(160, 512);

//DisplayApplicationHeader();
//RunDemos();
DisplayApplicationHeader();
RunDemos();
}

private static void DisplayApplicationHeader()
Expand Down

0 comments on commit 854c007

Please sign in to comment.