Charmap refactor WIP

This commit is contained in:
Tig
2024-11-17 09:58:02 -07:00
parent f527e599b2
commit a9b3a3ed93
2 changed files with 46 additions and 71 deletions

View File

@@ -21,8 +21,6 @@ public class CharMap : View, IDesignable
private int _rowHeight = 1; // Height of each row of 16 glyphs - changing this is not tested
private ContextMenu _contextMenu = new ();
private readonly ScrollBar _vScrollBar;
private readonly ScrollBar _hScrollBar;
/// <summary>
/// Initalizes a new instance.
@@ -142,74 +140,56 @@ public class CharMap : View, IDesignable
SetContentSize (new (COLUMN_WIDTH * 16 + RowLabelWidth, MAX_CODE_POINT / 16 * _rowHeight + 1)); // +1 for Header
_hScrollBar = new ()
{
AutoShow = false,
X = RowLabelWidth,
Y = Pos.AnchorEnd (),
Orientation = Orientation.Horizontal,
Width = Dim.Fill (1),
ScrollableContentSize = GetContentSize ().Width - RowLabelWidth,
Increment = COLUMN_WIDTH,
};
HorizontalScrollBar.AutoShow = false;
HorizontalScrollBar.Increment = COLUMN_WIDTH;
HorizontalScrollBar.ScrollableContentSize = GetContentSize ().Width - RowLabelWidth;
HorizontalScrollBar.X = RowLabelWidth;
HorizontalScrollBar.Y = Pos.AnchorEnd ();
HorizontalScrollBar.Width = Dim.Fill (1);
_vScrollBar = new ()
{
AutoShow = false,
X = Pos.AnchorEnd (),
Y = 1, // Header
Height = Dim.Fill (Dim.Func (() => Padding.Thickness.Bottom)),
ScrollableContentSize = GetContentSize ().Height
};
VerticalScrollBar.AutoShow = false;
VerticalScrollBar.Visible = true;
VerticalScrollBar.ScrollableContentSize = GetContentSize ().Height;
VerticalScrollBar.X = Pos.AnchorEnd ();
VerticalScrollBar.Y = 1; // Header
VerticalScrollBar.Height = Dim.Fill (Dim.Func (() => Padding.Thickness.Bottom));
Padding.Add (_vScrollBar, _hScrollBar);
//VerticalScrollBar.PositionChanged += (sender, args) =>
// {
// if (Viewport.Height > 0)
// {
// Viewport = Viewport with
// {
// Y = Math.Min (args.CurrentValue, GetContentSize ().Height - (Viewport.Height - 1))
// };
// }
// };
_vScrollBar.PositionChanged += (sender, args) =>
{
if (Viewport.Height > 0)
{
Viewport = Viewport with
{
Y = Math.Min (args.CurrentValue, GetContentSize ().Height - (Viewport.Height - 1))
};
}
};
//HorizontalScrollBar.PositionChanged += (sender, args) =>
// {
// if (Viewport.Width > 0)
// {
// Viewport = Viewport with
// {
// X = Math.Min (args.CurrentValue, GetContentSize ().Width - Viewport.Width)
// };
// }
// };
_vScrollBar.Scrolled += (sender, args) =>
{
//ScrollVertical (args.CurrentValue);
};
_hScrollBar.PositionChanged += (sender, args) =>
{
if (Viewport.Width > 0)
{
Viewport = Viewport with
{
X = Math.Min (args.CurrentValue, GetContentSize ().Width - Viewport.Width)
};
}
};
FrameChanged += (sender, args) =>
ViewportChanged += (sender, args) =>
{
if (Viewport.Width < GetContentSize ().Width)
{
Padding.Thickness = Padding.Thickness with { Bottom = 1 };
HorizontalScrollBar.Visible = true;
}
else
{
Padding.Thickness = Padding.Thickness with { Bottom = 0 };
HorizontalScrollBar.Visible = false;
}
//_hScrollBar.ContentPosition = Viewport.X;
//_vScrollBar.ContentPosition = Viewport.Y;
VerticalScrollBar.VisibleContentSize = Viewport.Height - 1;
HorizontalScrollBar.VisibleContentSize = Viewport.Width - RowLabelWidth;
};
SubviewsLaidOut += (sender, args) =>
{
//_vScrollBar.ContentPosition = Viewport.Y;
//_hScrollBar.ContentPosition = Viewport.X;
};
}
private void ScrollToMakeCursorVisible (Point newCursor)
@@ -234,8 +214,8 @@ public class CharMap : View, IDesignable
ScrollHorizontal (newCursor.X - Viewport.Width + 1);
}
_vScrollBar.Position = Viewport.Y;
_hScrollBar.Position = Viewport.X;
//VerticalScrollBar.Position = Viewport.Y;
//HorizontalScrollBar.Position = Viewport.X;
}
#region Cursor
@@ -524,7 +504,7 @@ public class CharMap : View, IDesignable
if (e.Flags == MouseFlags.WheeledDown)
{
ScrollVertical (1);
_vScrollBar.Position = Viewport.Y;
// _vScrollBar.Position = Viewport.Y;
e.Handled = true;
return;
@@ -533,7 +513,7 @@ public class CharMap : View, IDesignable
if (e.Flags == MouseFlags.WheeledUp)
{
ScrollVertical (-1);
_vScrollBar.Position = Viewport.Y;
// _vScrollBar.Position = Viewport.Y;
e.Handled = true;
return;
@@ -542,7 +522,7 @@ public class CharMap : View, IDesignable
if (e.Flags == MouseFlags.WheeledRight)
{
ScrollHorizontal (1);
_hScrollBar.Position = Viewport.X;
// _hScrollBar.Position = Viewport.X;
e.Handled = true;
return;
@@ -551,7 +531,7 @@ public class CharMap : View, IDesignable
if (e.Flags == MouseFlags.WheeledLeft)
{
ScrollHorizontal (-1);
_hScrollBar.Position = Viewport.X;
// _hScrollBar.Position = Viewport.X;
e.Handled = true;
}
}

View File

@@ -26,13 +26,15 @@ Scrolling with the mouse and keyboard are enabled by:
3) Subscribing to [View.MouseEvent](~/api/Terminal.Gui.View.MouseEvent.yml) and calling calling [View.ScrollHorizontal()](~/api/Terminal.Gui.View.ScrollHorizontal.yml)/[ScrollVertical()](~/api/Terminal.Gui.View.ScrollVertical.yml) as needed.
4) Enabling the [ScrollBar](~/api/Terminal.Gui.ScrollBar.yml)s built into View ([View.HorizontalScrollBar/VerticalScrollBar](~/api/Terminal.Gui.View.HorizontalScrollBar.yml)) by either enabling automatic show/hide behavior (@Terminal.Gui.ScrollBar.AutoShow) or explicitly making them visible (@Terminal.Gui.View.Visible).
While *[ScrollBar](~/api/Terminal.Gui.ScrollBar.yml)* can be used in a standalone manner to provide proportional scrolling, it is typically enabled automatically via the [View.HorizontalScrollBar](~/api/Terminal.Gui.View.HorizontalScrollBar.yml) and [View.VerticalScrollBar](~/api/Terminal.Gui.View.VerticalScrollBar.yml) properties.
## Examples
These Scenarios illustrate Terminal.Gui scrolling:
* *Scrolling* - Demonstrates the @Terminal.Gui.ScrollBar objects built into-View.
* *ScrollBar Demo* - Demonstrates using @Terminal.Gui.ScrollBar view in a standalone manner.
* *Content Scrolling* - Demonstrates the various [Viewport Settings](~/api/Terminal.Gui.ViewportSettings.yml) (see below) in an interactive manner. Used by the development team to visually verify that convoluted View layout and arrangement scenarios scroll properly.
* *ViewportSettings* - Demonstrates the various [Viewport Settings](~/api/Terminal.Gui.ViewportSettings.yml) (see below) in an interactive manner. Used by the development team to visually verify that convoluted View layout and arrangement scenarios scroll properly.
* *Character Map* - Demonstrates a sophisticated scrolling use-case. The entire set of Unicode code-points can be scrolled and searched. From a scrolling perspective, this Scenario illustrates how to manually configure `Viewport`, `SetContentArea()`, and `ViewportSettings` to enable horizontal and vertical headers (as might appear in a spreadsheet), full keyboard and mouse support, and more.
* *ListView* and *TableView* - The source code to these built-in Views are good references for how to support scrolling and ScrollBars in a re-usable View sub-class.
@@ -50,10 +52,3 @@ Use [View.ViewportSettings](~/api/Terminal.Gui.View.ViewportSettings.yml) to adj
* [EnableHorizontal/VerticalScrollBar](~/api/Terminal.Gui.ViewportSettings.EnableHorizontalScrollBar) - If set, the scroll bar will be enabled and automatically made visible when the corresponding dimension of [View.Viewport](~/api/Terminal.Gui.View.Viewport.yml) is smaller than the dimension of [View.GetContentSize()](~/api/Terminal.Gui.View.GetContentSize.yml).
## [ScrollBar](~/api/Terminal.Gui.ScrollBar.yml)
Provides a visual indicator that content can be scrolled. ScrollBars consist of two buttons, one each for scrolling forward or backwards, a Scroll that can be clicked to scroll large amounts, and a ScrollSlider that can be dragged to scroll continuously. ScrollBars can be oriented either horizontally or vertically and support the user dragging and clicking with the mouse to scroll.
While the *[Scroll](~/api/Terminal.Gui.Scroll.yml)* *[ScrollBar](~/api/Terminal.Gui.ScrollBar.yml)* Views can be used in a standalone manner to provide proportional scrolling, they are typically enabled automatically via the [View.HorizontalScrollBar](~/api/Terminal.Gui.View.HorizontalScrollBar.yml) and [View.VerticalScrollBar](~/api/Terminal.Gui.View.VerticalScrollBar.yml) properties.