Files
Terminal.Gui/UICatalog/Scenarios/TextAlignments.cs
Tig 16055c53b0 Fixes #3039. Fix View.HotKey (#3249)
* Added View.DefaultCommand etc... Started on dedicated scenario

* Fixed un-shifted hotkeys -> Fixed Key Equals. Fixed WindowsDriver passing wrong key. Etc.

* Fixed Key Bindings and HotKeys

* Fixed Key Bindings and HotKeys

* Label now correctly supports hotkey

* Disabled unix hot keys because they are annoying and get in the way

* Updated nuget. fixed warnings

* Trying to fix ci/ci issue

* Trying to fix ci/ci issue

* Trying to fix ci/ci issue

* Changed TextChangingEventArgs to inherit from CancelEventArgs

* TextChangingEventArgs -> TextEventArgs

* Simplified Text events by having only on args class

* Fixed unit tests fail

* Simplified by removing TitleEventArgs

* POC of Title being primary for hotkey. Label and Button hacked to work

* POC of Title being primary for hotkey. Label and Button hacked to work - all unit tests pass

* Dropped Microsoft.NETFramework.ReferenceAssemblies

* Fixed Dialogs scenario hotkeys

* Fixed build warnings

* Fixed Border Title render bug

* Regiggering default command handling

* Regiggering default command handling

* Checkbox clean up

* Added StateEventArgs POC

* Command.Default -> Command.HotKey

* Command.Default -> Command.HotKey - fixed TableView

* Command.Default -> Command.HotKey - fixed TableView

* Updated reactive example

* Fixed Toplevel.BringOverlappedTopToFront - was reordering SubViews when it shouldn't

* WIP - broke

* Finished impl of StateEventArgs

* Deleted ToggleEventArgs.cs. Added StateEventArgs.cs

* XML doc fix

* Removed old code

* Removed commented out code

* Label.Clicked -> Label.Accept (missed this before)

* Removed Labels as Buttons scenario as it's not really  useful

* Moved SubView tests to own file

* Moved SubView tests to own file

* Simplified Text test

* Added OnAccept test

* Deleted DefaultCommand

* Modernized CheckBox

* New button test

* Cleaned up RadioGroup; added tests

* KeyCode->Key in ListView

* Added ListView unit tests

* ListView now does Accept correctly

* TreeView now does Accept correctly

* Cleaned up some TextField tests

* TextView now handles Accept properly; updated CharMap and Adornments scenarios to test

* Fixed ComboBox to deal with TextView now handles Accept properly; updated CharMap and Adornments scenarios to test

* Removed un-needed using statement
2024-02-22 15:11:26 -07:00

143 lines
5.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Terminal.Gui;
namespace UICatalog.Scenarios;
[ScenarioMetadata ("Simple Text Alignment", "Demonstrates horizontal text alignment")]
[ScenarioCategory ("Text and Formatting")]
public class TextAlignments : Scenario
{
public override void Setup ()
{
Win.X = 10;
Win.Width = Dim.Fill (10);
var txt = "Hello world, how are you today? Pretty neat!";
var unicodeSampleText = "A Unicode sentence (пÑРвеÑ) has words.";
List<TextAlignment> alignments = Enum.GetValues (typeof (TextAlignment)).Cast<TextAlignment> ().ToList ();
Label [] singleLines = new Label [alignments.Count];
Label [] multipleLines = new Label [alignments.Count];
var multiLineHeight = 5;
foreach (TextAlignment alignment in alignments)
{
singleLines [(int)alignment] = new Label
{
TextAlignment = alignment,
X = 1,
AutoSize = false,
Width = Dim.Fill (1),
Height = 1,
ColorScheme = Colors.ColorSchemes ["Dialog"],
Text = txt
};
multipleLines [(int)alignment] = new Label
{
TextAlignment = alignment,
X = 1,
AutoSize = false,
Width = Dim.Fill (1),
Height = multiLineHeight,
ColorScheme = Colors.ColorSchemes ["Dialog"],
Text = txt
};
}
// Add a label & text field so we can demo IsDefault
var editLabel = new Label { X = 0, Y = 0, Text = "Text:" };
Win.Add (editLabel);
var edit = new TextView
{
X = Pos.Right (editLabel) + 1,
Y = Pos.Y (editLabel),
Width = Dim.Fill ("Text:".Length + " Unicode Sample".Length + 2),
Height = 4,
ColorScheme = Colors.ColorSchemes ["TopLevel"],
Text = txt
};
edit.TextChanged += (s, e) =>
{
foreach (TextAlignment alignment in alignments)
{
singleLines [(int)alignment].Text = edit.Text;
multipleLines [(int)alignment].Text = edit.Text;
}
};
Win.Add (edit);
var unicodeSample = new Button { X = Pos.Right (edit) + 1, Y = 0, Text = "Unicode Sample" };
unicodeSample.Accept += (s, e) => { edit.Text = unicodeSampleText; };
Win.Add (unicodeSample);
var update = new Button { X = Pos.Right (edit) + 1, Y = Pos.Bottom (edit) - 1, Text = "_Update" };
update.Accept += (s, e) =>
{
foreach (TextAlignment alignment in alignments)
{
singleLines [(int)alignment].Text = edit.Text;
multipleLines [(int)alignment].Text = edit.Text;
}
};
Win.Add (update);
var enableHotKeyCheckBox = new CheckBox
{
X = 0, Y = Pos.Bottom (edit), Text = "Enable Hotkey (_)", Checked = false
};
Win.Add (enableHotKeyCheckBox);
var label = new Label
{
Y = Pos.Bottom (enableHotKeyCheckBox) + 1, Text = "Demonstrating single-line (should clip):"
};
Win.Add (label);
foreach (TextAlignment alignment in alignments)
{
label = new Label { Y = Pos.Bottom (label), Text = $"{alignment}:" };
Win.Add (label);
singleLines [(int)alignment].Y = Pos.Bottom (label);
Win.Add (singleLines [(int)alignment]);
label = singleLines [(int)alignment];
}
txt += "\nSecond line\n\nFourth Line.";
label = new Label { Y = Pos.Bottom (label), Text = "Demonstrating multi-line and word wrap:" };
Win.Add (label);
foreach (TextAlignment alignment in alignments)
{
label = new Label { Y = Pos.Bottom (label), Text = $"{alignment}:" };
Win.Add (label);
multipleLines [(int)alignment].Y = Pos.Bottom (label);
Win.Add (multipleLines [(int)alignment]);
label = multipleLines [(int)alignment];
}
enableHotKeyCheckBox.Toggled += (s, e) =>
{
foreach (TextAlignment alignment in alignments)
{
singleLines [(int)alignment].HotKeySpecifier =
e.OldValue == true ? (Rune)0xffff : (Rune)'_';
multipleLines [(int)alignment].HotKeySpecifier =
e.OldValue == true ? (Rune)0xffff : (Rune)'_';
}
Win.SetNeedsDisplay ();
Win.LayoutSubviews ();
};
}
}