Skip to content
Open
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
2 changes: 2 additions & 0 deletions SadConsole.Extended/UI/Controls/Table.TableCells.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ public void Clear(bool clearLayoutOptions = true)
MaxRow = 0;
MaxColumn = 0;
_cells.Clear();
_table._checkScrollBarVisibility = true;
_table.IsDirty = true;
}

Expand Down Expand Up @@ -521,6 +522,7 @@ public void Remove()
{
Dictionary<int, Layout> layoutDict = _layoutType == LayoutType.Row ? _table.Cells._rowLayout : _table.Cells._columnLayout;
layoutDict.Remove(_index);
_table._checkScrollBarVisibility = true;
_table.IsDirty = true;
}

Expand Down
79 changes: 59 additions & 20 deletions SadConsole.Extended/UI/Controls/Table.Theme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public override void UpdateAndRedraw(TimeSpan time)
{
if (!IsDirty) return;

EnsureAutomaticScrollBars();
RefreshThemeStateColors(FindThemeColors());

// Draw the basic table surface foreground and background, and clear the glyphs
Expand All @@ -31,12 +32,15 @@ public override void UpdateAndRedraw(TimeSpan time)

SetScrollBarVisibility(maxRowsHeight, maxColumnsWidth);

int viewportWidth = EffectiveViewportWidth;
int viewportHeight = EffectiveViewportHeight;

int rows = 0;
int rowIndexPos = Cells.GetIndexAtCellPosition(StartRenderYPos, Table.TableCells.Layout.LayoutType.Row, out _);
int rowIndex = IsVerticalScrollBarVisible ? rowIndexPos : 0;
bool offScreenY = false;
List<((int x, int y), (int row, int col))>? fakeCells = DrawFakeCells ? new() : null;
for (int row = 0; row <= Height; row++)
for (int row = 0; row <= viewportHeight; row++)
{
if (rows >= allRowIndexesWithContent.Count) break;
if (allRowIndexesWithContent.Contains(row)) rows++;
Expand All @@ -51,7 +55,7 @@ public override void UpdateAndRedraw(TimeSpan time)
int fullRowSize = 0;

bool headerRow = false;
for (int col = 0; col <= Width; col++)
for (int col = 0; col <= viewportWidth; col++)
{
if (columns >= allColumnIndexesWithContent.Count) break;
if (allColumnIndexesWithContent.Contains(col)) columns++;
Expand Down Expand Up @@ -84,15 +88,15 @@ public override void UpdateAndRedraw(TimeSpan time)
}

// Don't attempt to render off-screen rows/columns
if (cellPosition.X > Width || cellPosition.Y > Height)
if (cellPosition.X > viewportWidth || cellPosition.Y > viewportHeight)
{
if (cellPosition.Y > Height)
if (cellPosition.Y > viewportHeight)
{
offScreenY = true;
break;
}

if (cellPosition.X > Width)
if (cellPosition.X > viewportWidth)
break;
}

Expand Down Expand Up @@ -184,11 +188,10 @@ private void SetScrollBarPropertiesOnTable(ScrollBar scrollBar, int maxRowsHeigh
{
if (scrollBar != null)
{
int max = scrollBar.Orientation == Orientation.Vertical ? EffectiveViewportHeight : EffectiveViewportWidth;
int total = scrollBar.Orientation == Orientation.Vertical ?
(maxRowsHeight >= Height ? Height : maxRowsHeight) :
(maxColumnsWidth >= Width ? Width : maxColumnsWidth);

int max = scrollBar.Orientation == Orientation.Vertical ? Height : Width;
Math.Min(maxRowsHeight, max) :
Math.Min(maxColumnsWidth, max);

if (scrollBar.Orientation == Orientation.Vertical)
{
Expand All @@ -211,19 +214,55 @@ private void SetScrollBarPropertiesOnTable(ScrollBar scrollBar, int maxRowsHeigh
/// <param name="maxColumnsWidth">The maximum width of the columns.</param>
protected void SetScrollBarVisibility(int maxRowsHeight, int maxColumnsWidth)
{
if (_checkScrollBarVisibility)
if (!_checkScrollBarVisibility)
return;

EnsureAutomaticScrollBars();

ScrollBar? horizontalScrollBar = HorizontalScrollBar;
ScrollBar? verticalScrollBar = VerticalScrollBar;

bool showHorizontal = horizontalScrollBar != null && GetScrollBarItems(Orientation.Horizontal, Width) > 0;
bool showVertical = verticalScrollBar != null && GetScrollBarItems(Orientation.Vertical, Height) > 0;

for (int i = 0; i < 2; i++)
{
if (VerticalScrollBar != null)
{
IsVerticalScrollBarVisible = ShowHideScrollBar(VerticalScrollBar);
SetScrollBarPropertiesOnTable(VerticalScrollBar, maxRowsHeight, maxColumnsWidth);
}
if (HorizontalScrollBar != null)
{
IsHorizontalScrollBarVisible = ShowHideScrollBar(HorizontalScrollBar);
SetScrollBarPropertiesOnTable(HorizontalScrollBar, maxRowsHeight, maxColumnsWidth);
}
int viewportWidth = Math.Max(Width - (_automaticallyManageVerticalScrollBar && showVertical ? 1 : 0), 0);
int viewportHeight = Math.Max(Height - (_automaticallyManageHorizontalScrollBar && showHorizontal ? 1 : 0), 0);
bool nextShowHorizontal = horizontalScrollBar != null && GetScrollBarItems(Orientation.Horizontal, viewportWidth) > 0;
bool nextShowVertical = verticalScrollBar != null && GetScrollBarItems(Orientation.Vertical, viewportHeight) > 0;

if (showHorizontal == nextShowHorizontal && showVertical == nextShowVertical)
break;

showHorizontal = nextShowHorizontal;
showVertical = nextShowVertical;
}

if (horizontalScrollBar != null)
horizontalScrollBar.IsVisible = showHorizontal;
if (verticalScrollBar != null)
verticalScrollBar.IsVisible = showVertical;

UpdateAutomaticScrollBarGeometry();

if (HorizontalScrollBar != null)
{
int scrollItems = GetScrollBarItems(Orientation.Horizontal);
ReconcileScrollBarState(HorizontalScrollBar, HorizontalScrollBar.IsVisible, scrollItems);
SetScrollBarPropertiesOnTable(HorizontalScrollBar, maxRowsHeight, maxColumnsWidth);
}

if (VerticalScrollBar != null)
{
int scrollItems = GetScrollBarItems(Orientation.Vertical);
ReconcileScrollBarState(VerticalScrollBar, VerticalScrollBar.IsVisible, scrollItems);
SetScrollBarPropertiesOnTable(VerticalScrollBar, maxRowsHeight, maxColumnsWidth);
}

SynchronizeScrollOffsetsFromValues();

_checkScrollBarVisibility = false;
}

/// <summary>
Expand Down
Loading