Files
Terminal.Gui/Examples/UICatalog/Scenarios/Adornments.cs
Tig fb1a3e03f3 Fixes some bugs in the Scenario/EditorsAndHelpers and backports WideGlyphs (#4494)
* Fix scenario editors and tweak scenarios.

Enhance ShadowStyles with a second shadow window (transparent style) and a button event handler that shows a message box. In WideGlyphs, add AdornmentsEditor and ViewportSettingsEditor for view property editing, apply custom color schemes to arrangeable views, and update superView with a transparent shadow and increased shadow width. These changes improve interactivity and visualization in the demo scenarios.

* Fix scenario editors and tweak scenarios.

Enhance ShadowStyles with a second shadow window (transparent style) and a button event handler that shows a message box. In WideGlyphs, add AdornmentsEditor and ViewportSettingsEditor for view property editing, apply custom color schemes to arrangeable views, and update superView with a transparent shadow and increased shadow width. These changes improve interactivity and visualization in the demo scenarios.

* Scenario Editors code cleanup & latent bug fixes.

Refactored event handler patterns to use correct sender values and discards for unused parameters, aligning with .NET conventions. Cleaned up code by removing redundant usings and comments, and clarified logic in property setters and switch statements. Enhanced robustness and clarity in editor components, fixing issues with value changes, event subscriptions, and nullability. Improved disposal logic in EditorBase and made minor UI and label adjustments. Added "diag" to the custom dictionary. These changes modernize event handling and address subtle bugs in the UICatalog editors.

* code cleanup

* Update Examples/UICatalog/Scenarios/EditorsAndHelpers/EditorBase.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* PR feedback.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-14 17:31:57 -07:00

165 lines
6.9 KiB
C#

using System;
namespace UICatalog.Scenarios;
[ScenarioMetadata ("Adornments Demo", "Demonstrates Margin, Border, and Padding on Views.")]
[ScenarioCategory ("Layout")]
[ScenarioCategory ("Adornments")]
public class Adornments : Scenario
{
public override void Main ()
{
Application.Init ();
Window appWindow = new ()
{
Title = GetQuitKeyAndName (),
BorderStyle = LineStyle.None
};
var editor = new AdornmentsEditor
{
BorderStyle = LineStyle.Single,
AutoSelectViewToEdit = true,
// This is for giggles, to show that the editor can be moved around.
Arrangement = ViewArrangement.Movable,
X = Pos.AnchorEnd ()
};
editor.Border!.Thickness = new (1, 2, 1, 1);
appWindow.Add (editor);
var window = new Window
{
Title = "The _Window",
Arrangement = ViewArrangement.Overlapped | ViewArrangement.Movable,
Width = Dim.Fill (Dim.Func (_ => editor.Frame.Width)),
Height = Dim.Fill ()
};
appWindow.Add (window);
var tf1 = new TextField { Width = 10, Text = "TextField" };
var color = new ColorPicker16 { Title = "BG", BoxHeight = 1, BoxWidth = 1, X = Pos.AnchorEnd () };
color.BorderStyle = LineStyle.RoundedDotted;
color.ColorChanged += (s, e) =>
{
color.SuperView!.SetScheme (
new (color.SuperView.GetScheme ())
{
Normal = new (
color.SuperView.GetAttributeForRole (VisualRole.Normal).Foreground,
e.Result,
color.SuperView.GetAttributeForRole (VisualRole.Normal).Style
)
});
};
var button = new Button { X = Pos.Center (), Y = Pos.Center (), Text = "Press me!" };
button.Accepting += (s, e) =>
MessageBox.Query (appWindow.App, 20, 7, "Hi", $"Am I a {window.GetType ().Name}?", "Yes", "No");
var label = new TextView
{
X = Pos.Center (),
Y = Pos.Bottom (button),
Title = "Title",
Text = "I have a 3 row top border.\nMy border inherits from the SuperView.",
Width = 40,
Height = 6 // TODO: Use Dim.Auto
};
label.Border!.Thickness = new (1, 3, 1, 1);
var btnButtonInWindow = new Button { X = Pos.AnchorEnd (), Y = Pos.AnchorEnd (), Text = "Button" };
var labelAnchorEnd = new Label
{
Y = Pos.AnchorEnd (),
Width = 40,
Height = Dim.Percent (20),
Text = "Label\nY=AnchorEnd(),Height=Dim.Percent(10)",
SchemeName = "Dialog"
};
window.Margin!.Data = "Margin";
window.Margin!.Text = "Margin Text";
window.Margin!.Thickness = new (0);
window.Border!.Data = "Border";
window.Border!.Text = "Border Text";
window.Border!.Thickness = new (0);
window.Padding.Data = "Padding";
window.Padding.Text = "Padding Text line 1\nPadding Text line 3\nPadding Text line 3\nPadding Text line 4\nPadding Text line 5";
window.Padding.Thickness = new (3);
window.Padding.SchemeName = "Error";
window.Padding.CanFocus = true;
var longLabel = new Label
{
X = 40, Y = 5, Title = "This is long text (in a label) that should clip."
};
longLabel.TextFormatter.WordWrap = true;
window.Add (tf1, color, button, label, btnButtonInWindow, labelAnchorEnd, longLabel);
window.Initialized += (s, e) =>
{
editor.ViewToEdit = window;
editor.ShowViewIdentifier = true;
var labelInPadding = new Label { X = 0, Y = 1, Title = "_Text:" };
window.Padding.Add (labelInPadding);
var textFieldInPadding = new TextField
{
X = Pos.Right (labelInPadding) + 1,
Y = Pos.Top (labelInPadding), Width = 10,
Text = "text (Y = 1)",
CanFocus = true
};
textFieldInPadding.Accepting += (s, e) => MessageBox.Query (appWindow.App, 20, 7, "TextField", textFieldInPadding.Text, "Ok");
window.Padding.Add (textFieldInPadding);
var btnButtonInPadding = new Button
{
X = Pos.Center (),
Y = 1,
Text = "_Button in Padding Y = 1",
CanFocus = true,
HighlightStates = MouseState.None,
};
btnButtonInPadding.Accepting += (s, e) => MessageBox.Query (appWindow.App, 20, 7, "Hi", "Button in Padding Pressed!", "Ok");
btnButtonInPadding.BorderStyle = LineStyle.Dashed;
btnButtonInPadding.Border!.Thickness = new (1, 1, 1, 1);
window.Padding.Add (btnButtonInPadding);
#if SUBVIEW_BASED_BORDER
btnButtonInPadding.Border!.CloseButton.Visible = true;
view.Border!.CloseButton.Visible = true;
view.Border!.CloseButton.Accept += (s, e) =>
{
MessageBox.Query (20, 7, "Hi", "Window Close Button Pressed!", "Ok");
e.Handled = true;
};
view.Accept += (s, e) => MessageBox.Query (20, 7, "Hi", "Window Close Button Pressed!", "Ok");
#endif
};
editor.AutoSelectViewToEdit = true;
editor.AutoSelectSuperView = window;
editor.AutoSelectAdornments = true;
Application.Run (appWindow);
appWindow.Dispose ();
Application.Shutdown ();
}
}