Skip to content

Commit 0f3c1ee

Browse files
authored
Merge pull request #198 from tig/BDisp-v2_2489_scroll-tig-builtin
More Charmap scrollbar tweaks
2 parents b19437d + 38c604e commit 0f3c1ee

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

UICatalog/Scenarios/CharacterMap.cs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ public CharMap ()
320320
CanFocus = true;
321321
CursorVisibility = CursorVisibility.Default;
322322

323-
SetContentSize (new (RowWidth, (_maxCodePoint / 16 + 2) * _rowHeight));
323+
SetContentSize (new (RowWidth, (_maxCodePoint / 16 + 1) * _rowHeight));
324324

325325
AddCommand (
326326
Command.ScrollUp,
@@ -369,6 +369,11 @@ public CharMap ()
369369
ScrollHorizontal (-COLUMN_WIDTH);
370370
}
371371

372+
if (Cursor.X >= Viewport.Width)
373+
{
374+
ScrollHorizontal (Cursor.X - Viewport.Width + 1);
375+
}
376+
372377
return true;
373378
}
374379
);
@@ -464,22 +469,22 @@ public CharMap ()
464469

465470
ScrollBar hScrollBar = new ()
466471
{
472+
AutoHide = false,
467473
X = RowLabelWidth + 1,
468474
Y = Pos.AnchorEnd (),
469475
Width = Dim.Fill (1),
470476
Size = COLUMN_WIDTH * 15,
471477
Orientation = Orientation.Horizontal
472478
};
473479

474-
hScrollBar.VisibleChanged += (sender, args) => { Padding.Thickness = Padding.Thickness with { Bottom = hScrollBar.Visible ? 1 : 0 }; };
475-
476480
ScrollBar vScrollBar = new ()
477481
{
482+
AutoHide = false,
478483
X = Pos.AnchorEnd (),
479484
Y = 1, // Header
480-
Height = Dim.Fill (Dim.Func (() => hScrollBar.Visible ? 1 : 0)),
485+
Height = Dim.Fill (Dim.Func (() => Padding.Thickness.Bottom)),
481486
Orientation = Orientation.Vertical,
482-
Size = GetContentSize ().Height - _rowHeight, // Minus one row so last row stays visible
487+
Size = GetContentSize ().Height,
483488
};
484489
vScrollBar.PositionChanged += (sender, args) => { Viewport = Viewport with { Y = args.CurrentValue }; };
485490

@@ -488,7 +493,19 @@ public CharMap ()
488493

489494
ViewportChanged += (sender, args) =>
490495
{
491-
vScrollBar.Size = GetContentSize ().Height - _rowHeight; // Minus one row so last row stays visible
496+
if (Viewport.Width < GetContentSize ().Width)
497+
{
498+
Padding.Thickness = Padding.Thickness with { Bottom = 1 };
499+
}
500+
else
501+
{
502+
Padding.Thickness = Padding.Thickness with { Bottom = 0 };
503+
}
504+
505+
hScrollBar.Size = COLUMN_WIDTH * 15;
506+
hScrollBar.Position = Viewport.X;
507+
508+
vScrollBar.Size = GetContentSize ().Height;
492509
vScrollBar.Position = Viewport.Y;
493510
};
494511
}

0 commit comments

Comments
 (0)