Files
Terminal.Gui/UICatalog/Scenarios/LabelsAsButtons.cs
BDisp ea24de3a27 Fixes #2482. Refactor Redraw - Non-virtual with the right set of virtual OnXXX methods. (#2577)
* Fixes #2482. Refactor Redraw - Non-virtual with the right set of virtual OnXXX methods.

* Change documentation comments.

* Fixes #2575 - TableView to use interface instead of System.Data.DataTable (#2576)

* WIP: Add ITableDataSource

* WIP: Refactor TableView

* WIP: Port CSVEditor

* WIP: Port TableEditor

* WIP: Port MultiColouredTable scenario

* Fix bug of adding duplicate column styles

* Update tests to use DataTableSource

* Tidy up

* Add EnumerableTableDataSource<T>

* Add test for EnumerableTableDataSource

* Add test for EnumerableTableDataSource

* Add code example to xmldoc

* Add ProcessTable scenario

* Rename ITableDataSource to ITableSource and update docs

* Rename EnumerableTableDataSource to EnumerableTableSource

* Fixed Frame != Bounds; changed UICat Scenarios list to use tableview!

* Fix scroll resetting in ProcessTable scenario

* Fix unit tests by setting Frame to same as Bounds

* Document why we have to measure our data for use with TableView

---------

Co-authored-by: Tig Kindel <tig@users.noreply.github.com>

* Fixes #2582 - Refactors FileDialog for cleaner data model (#2583)

* WIP: Add ITableDataSource

* WIP: Refactor TableView

* WIP: Port CSVEditor

* WIP: Port TableEditor

* WIP: Port MultiColouredTable scenario

* Fix bug of adding duplicate column styles

* Update tests to use DataTableSource

* Tidy up

* Add EnumerableTableDataSource<T>

* Add test for EnumerableTableDataSource

* Add test for EnumerableTableDataSource

* Add code example to xmldoc

* Add ProcessTable scenario

* Rename ITableDataSource to ITableSource and update docs

* Rename EnumerableTableDataSource to EnumerableTableSource

* Fixed Frame != Bounds; changed UICat Scenarios list to use tableview!

* Fix scroll resetting in ProcessTable scenario

* Fix unit tests by setting Frame to same as Bounds

* Document why we have to measure our data for use with TableView

* WIP: Simplify FileDialogs use of TableView

* WIP start migrating sorter

* WIP new filedialog table source mostly working

* WIP remove sorter class

* Refactor GetOrderByValue to be adjacent to GetColumnValue

* Fix collection navigator back so it ignores icon

* Fix unit tests

* Tidy up

* Fix UseColors

* Add test for UseColors

---------

Co-authored-by: Tig Kindel <tig@users.noreply.github.com>

* Fixes #2196. TextView: Setting Text places cursor at beginning, unlike TextField (#2572)

* Fixes #2196. TextView: Setting Text places cursor at beginning, unlike TextField

* Change all private members to have the _prefix.

* Renamed local member to prevLayoutStyle.

* Helper function for SetNeedsDisplay.

* Fixes #2569. Borders scenarios needed to be refactored. (#2570)

* Fixes #2569. Borders scenarios needed to be refactored.

* Fix border title with width equal to 4 and thickness top grater than 1.

* Improves border manipulation on borders scenarios.

* Prevents null value on the margin, border and padding thickness on the border scenarios.

* Remove NStack using dependence and fix prior commit.

* Refactoring the Frames scenario.

* Deleted borders scenarios.

* I did not realize that it was changed to SetSubViewNeedsDisplay.

* Re-layout; fixed colorpicker; fixed radio group

* Remove Thickness.IsEmpty as requested.

* Change the Frames scenario as requested.

---------

Co-authored-by: Tig Kindel <tig@users.noreply.github.com>

* Builds CollectionNavigator support into UI Catalog for TableView (#2584)

* Builds collectionnav support into UI cat for TableView

* Fixes keyboard mapping

* MultiSelect = false for TableView

* MultiSelect = false doesn't unbind ctrl-a

* Fixes #2581 Refactor CollectionNavigator so it supports TableView (#2586)

* Refactor CollectionNavigator to a base and a collection implementation

* Refactor CollectionNavigatorBase to look for first match smartly

* Add TableCollectionNavigator

* Make TableCollectionNavigator a core part of TableView

* Fix bad merge

* Added tests for tableview collection navigator

* Add FileDialogCollectionNavigator which ignores . and directory separator prefixes on file names

* whitespace fixes

---------

Co-authored-by: Tig <tig@users.noreply.github.com>

* Resolving merge conflicts.

* Fix merge errors.

* Fix merge errors.

* Add Command.Accept and snap to the selected glyph when ShowHorizontalScrollIndicator change to true.

* Reformat.

* Reformat again.

---------

Co-authored-by: Thomas Nind <31306100+tznind@users.noreply.github.com>
Co-authored-by: Tig Kindel <tig@users.noreply.github.com>
2023-05-04 13:17:59 +02:00

312 lines
10 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using NStack;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Terminal.Gui;
namespace UICatalog.Scenarios {
[ScenarioMetadata (Name: "Labels As Buttons", Description: "Illustrates that Button is really just a Label++")]
[ScenarioCategory ("Controls")]
[ScenarioCategory ("Proof of Concept")]
public class LabelsAsLabels : Scenario {
public override void Setup ()
{
// Add a label & text field so we can demo IsDefault
var editLabel = new Label ("TextField (to demo IsDefault):") {
X = 0,
Y = 0,
};
Win.Add (editLabel);
// Add a TextField using Absolute layout.
var edit = new TextField (31, 0, 15, "");
Win.Add (edit);
// This is the default Label (IsDefault = true); if user presses ENTER in the TextField
// the scenario will quit
var defaultLabel = new Label ("_Quit") {
X = Pos.Center (),
//TODO: Change to use Pos.AnchorEnd()
Y = Pos.Bottom (Win) - 3,
//IsDefault = true,
HotKeySpecifier = (System.Rune)'_',
CanFocus = true,
};
defaultLabel.Clicked += (s,e) => Application.RequestStop ();
Win.Add (defaultLabel);
var swapLabel = new Label (50, 0, "S_wap Default (Absolute Layout)") {
HotKeySpecifier = (System.Rune)'_',
CanFocus = true,
};
swapLabel.Clicked += (s,e) => {
//defaultLabel.IsDefault = !defaultLabel.IsDefault;
//swapLabel.IsDefault = !swapLabel.IsDefault;
};
Win.Add (swapLabel);
static void DoMessage (Label Label, ustring txt)
{
Label.Clicked += (s,e) => {
var btnText = Label.Text.ToString ();
MessageBox.Query ("Message", $"Did you click {txt}?", "Yes", "No");
};
}
var colorLabelsLabel = new Label ("Color Labels:") {
X = 0,
Y = Pos.Bottom (editLabel) + 1,
};
Win.Add (colorLabelsLabel);
//With this method there is no need to call Application.TopReady += () => Application.TopRedraw (Top.Bounds);
var x = Pos.Right (colorLabelsLabel) + 2;
foreach (var colorScheme in Colors.ColorSchemes) {
var colorLabel = new Label ($"{colorScheme.Key}") {
ColorScheme = colorScheme.Value,
X = x,
Y = Pos.Y (colorLabelsLabel),
HotKeySpecifier = (System.Rune)'_',
CanFocus = true,
};
DoMessage (colorLabel, colorLabel.Text);
Win.Add (colorLabel);
x += colorLabel.Text.Length + 2;
}
Application.Top.Ready += (s,e) => Application.Top.Draw ();
Label Label;
Win.Add (Label = new Label ("A super long _Label that will probably expose a bug in clipping or wrapping of text. Will it?") {
X = 2,
Y = Pos.Bottom (colorLabelsLabel) + 1,
HotKeySpecifier = (System.Rune)'_',
CanFocus = true,
});
DoMessage (Label, Label.Text);
// Note the 'N' in 'Newline' will be the hotkey
Win.Add (Label = new Label ("a Newline\nin the Label") {
X = 2,
Y = Pos.Bottom (Label) + 1,
HotKeySpecifier = (System.Rune)'_',
CanFocus = true,
TextAlignment = TextAlignment.Centered,
VerticalTextAlignment = VerticalTextAlignment.Middle
});
Label.Clicked += (s,e) => MessageBox.Query ("Message", "Question?", "Yes", "No");
var textChanger = new Label ("Te_xt Changer") {
X = 2,
Y = Pos.Bottom (Label) + 1,
HotKeySpecifier = (System.Rune)'_',
CanFocus = true,
};
Win.Add (textChanger);
textChanger.Clicked += (s,e) => textChanger.Text += "!";
Win.Add (Label = new Label ("Lets see if this will move as \"Text Changer\" grows") {
X = Pos.Right (textChanger) + 2,
Y = Pos.Y (textChanger),
HotKeySpecifier = (System.Rune)'_',
CanFocus = true,
});
var removeLabel = new Label ("Remove this Label") {
X = 2,
Y = Pos.Bottom (Label) + 1,
ColorScheme = Colors.Error,
HotKeySpecifier = (System.Rune)'_',
CanFocus = true,
};
Win.Add (removeLabel);
// This in interesting test case because `moveBtn` and below are laid out relative to this one!
removeLabel.Clicked += (s,e) => {
// Now this throw a InvalidOperationException on the TopologicalSort method as is expected.
//Win.Remove (removeLabel);
removeLabel.Visible = false;
Win.SetNeedsDisplay ();
};
var computedFrame = new FrameView ("Computed Layout") {
X = 0,
Y = Pos.Bottom (removeLabel) + 1,
Width = Dim.Percent (50),
Height = 5
};
Win.Add (computedFrame);
// Demonstrates how changing the View.Frame property can move Views
var moveBtn = new Label ("Move This \u263b Label _via Pos") {
X = 0,
Y = Pos.Center () - 1,
Width = 30,
ColorScheme = Colors.Error,
HotKeySpecifier = (System.Rune)'_',
CanFocus = true,
};
moveBtn.Clicked += (s,e) => {
moveBtn.X = moveBtn.Frame.X + 5;
// This is already fixed with the call to SetNeedDisplay() in the Pos Dim.
//computedFrame.LayoutSubviews (); // BUGBUG: This call should not be needed. View.X is not causing relayout correctly
};
computedFrame.Add (moveBtn);
// Demonstrates how changing the View.Frame property can SIZE Views (#583)
var sizeBtn = new Label ("Size This \u263a Label _via Pos") {
//var sizeBtn = new Label ("Size This x Label _via Pos") {
X = 0,
Y = Pos.Center () + 1,
Width = 30,
ColorScheme = Colors.Error,
HotKeySpecifier = (System.Rune)'_',
CanFocus = true,
AutoSize = false
};
sizeBtn.Clicked += (s,e) => {
sizeBtn.Width = sizeBtn.Frame.Width + 5;
//computedFrame.LayoutSubviews (); // FIXED: This call should not be needed. View.X is not causing relayout correctly
};
computedFrame.Add (sizeBtn);
var absoluteFrame = new FrameView ("Absolute Layout") {
X = Pos.Right (computedFrame),
Y = Pos.Bottom (removeLabel) + 1,
Width = Dim.Fill (),
Height = 5
};
Win.Add (absoluteFrame);
// Demonstrates how changing the View.Frame property can move Views
var moveBtnA = new Label (0, 0, "Move This Label via Frame") {
ColorScheme = Colors.Error,
HotKeySpecifier = (System.Rune)'_',
CanFocus = true,
};
moveBtnA.Clicked += (s,e) => {
moveBtnA.Frame = new Rect (moveBtnA.Frame.X + 5, moveBtnA.Frame.Y, moveBtnA.Frame.Width, moveBtnA.Frame.Height);
};
absoluteFrame.Add (moveBtnA);
// Demonstrates how changing the View.Frame property can SIZE Views (#583)
var sizeBtnA = new Label (0, 2, " ~  s  gui.cs   master ↑10 = Со_хранить") {
ColorScheme = Colors.Error,
HotKeySpecifier = (System.Rune)'_',
CanFocus = true,
AutoSize = false
};
sizeBtnA.Clicked += (s,e) => {
sizeBtnA.Frame = new Rect (sizeBtnA.Frame.X, sizeBtnA.Frame.Y, sizeBtnA.Frame.Width + 5, sizeBtnA.Frame.Height);
};
absoluteFrame.Add (sizeBtnA);
var label = new Label ("Text Alignment (changes the four Labels above): ") {
X = 2,
Y = Pos.Bottom (computedFrame) + 1,
HotKeySpecifier = (System.Rune)'_',
CanFocus = true,
};
Win.Add (label);
var radioGroup = new RadioGroup (new ustring [] { "Left", "Right", "Centered", "Justified" }) {
X = 4,
Y = Pos.Bottom (label) + 1,
SelectedItem = 2,
};
Win.Add (radioGroup);
// Demo changing hotkey
ustring MoveHotkey (ustring txt)
{
// Remove the '_'
var runes = txt.ToRuneList ();
var i = runes.IndexOf ('_');
ustring start = "";
if (i > -1) {
start = ustring.Make (runes.GetRange (0, i));
}
txt = start + ustring.Make (runes.GetRange (i + 1, runes.Count - (i + 1)));
runes = txt.ToRuneList ();
// Move over one or go to start
i++;
if (i >= runes.Count) {
i = 0;
}
// Slip in the '_'
start = ustring.Make (runes.GetRange (0, i));
return start + ustring.Make ('_') + ustring.Make (runes.GetRange (i, runes.Count - i));
}
var mhkb = "Click to Change th_is Label's Hotkey";
var moveHotKeyBtn = new Label (mhkb) {
X = 2,
Y = Pos.Bottom (radioGroup) + 1,
Width = Dim.Width (computedFrame) - 2,
ColorScheme = Colors.TopLevel,
HotKeySpecifier = (System.Rune)'_',
CanFocus = true,
};
moveHotKeyBtn.Clicked += (s,e) => {
moveHotKeyBtn.Text = MoveHotkey (moveHotKeyBtn.Text);
};
Win.Add (moveHotKeyBtn);
ustring muhkb = " ~  s  gui.cs   master ↑10 = Сохранить";
var moveUnicodeHotKeyBtn = new Label (muhkb) {
X = Pos.Left (absoluteFrame) + 1,
Y = Pos.Bottom (radioGroup) + 1,
Width = Dim.Width (absoluteFrame) - 2,
ColorScheme = Colors.TopLevel,
HotKeySpecifier = (System.Rune)'_',
CanFocus = true,
};
moveUnicodeHotKeyBtn.Clicked += (s,e) => {
moveUnicodeHotKeyBtn.Text = MoveHotkey (moveUnicodeHotKeyBtn.Text);
};
Win.Add (moveUnicodeHotKeyBtn);
radioGroup.SelectedItemChanged += (s,args) => {
switch (args.SelectedItem) {
case 0:
moveBtn.TextAlignment = TextAlignment.Left;
sizeBtn.TextAlignment = TextAlignment.Left;
moveBtnA.TextAlignment = TextAlignment.Left;
sizeBtnA.TextAlignment = TextAlignment.Left;
moveHotKeyBtn.TextAlignment = TextAlignment.Left;
moveUnicodeHotKeyBtn.TextAlignment = TextAlignment.Left;
break;
case 1:
moveBtn.TextAlignment = TextAlignment.Right;
sizeBtn.TextAlignment = TextAlignment.Right;
moveBtnA.TextAlignment = TextAlignment.Right;
sizeBtnA.TextAlignment = TextAlignment.Right;
moveHotKeyBtn.TextAlignment = TextAlignment.Right;
moveUnicodeHotKeyBtn.TextAlignment = TextAlignment.Right;
break;
case 2:
moveBtn.TextAlignment = TextAlignment.Centered;
sizeBtn.TextAlignment = TextAlignment.Centered;
moveBtnA.TextAlignment = TextAlignment.Centered;
sizeBtnA.TextAlignment = TextAlignment.Centered;
moveHotKeyBtn.TextAlignment = TextAlignment.Centered;
moveUnicodeHotKeyBtn.TextAlignment = TextAlignment.Centered;
break;
case 3:
moveBtn.TextAlignment = TextAlignment.Justified;
sizeBtn.TextAlignment = TextAlignment.Justified;
moveBtnA.TextAlignment = TextAlignment.Justified;
sizeBtnA.TextAlignment = TextAlignment.Justified;
moveHotKeyBtn.TextAlignment = TextAlignment.Justified;
moveUnicodeHotKeyBtn.TextAlignment = TextAlignment.Justified;
break;
}
};
Application.Top.Ready += (s,e) => radioGroup.Refresh ();
}
}
}