Files
Terminal.Gui/Examples/UICatalog/Scenarios/WindowsAndFrameViews.cs
Tig 3e2eebfd2c Fixes #4057 - MASSIVE! Fully implements ColorScheme->Scheme + VisualRole + Colors.->SchemeManager. (#4062)
* touching publish.yml

* ColorScheme->Scheme

* ColorScheme->Scheme 2

* Prototype of GetAttributeForRole

* Badly broke CM

* Further Badly broke CM

* Refactored CM big-time. View still broken

* All unit test pass again. Tons added. CM is still WIP, but Schemes is not mostly refactored and working.

* Actually:
All unit test pass again.
Tons added.
CM is still WIP, but Schemes is not mostly refactored and working.

* Bug fixes.
DeepMemberWiseClone cleanup

* Further cleanup of Scope<T>, ConfigProperty, etc.

* Made ConfigManager thread safe.

* WIP: Broken

* WIP: new deep clone impl

* WIP: new deep clone impl is done. Now fixing CM

* WIP:
- config.md
- Working on AOT clean up
- Core CM is broken; but known.

* WIP

* Merged.
Removed CM from Application.Init

* WIP

* More WIP; Less broke

* All CM unit tests pass... Not sure if it actually works though

* All unit tests pass... Themes are broken though in UI Cat

* CM Ready for review?

* Fixed failures due to TextStyles PR

* Working on Scheme/Attribute

* Working on Scheme/Attribute 2

* Working on Scheme/Attribute 3

* Working on Scheme/Attribute 4

* Working on Scheme/Attribute 5

* Working on Scheme/Attribute 6

* Added test to show how awful memory usage is

* Improved schema. Updated config.json

* Nade Scope<T> concurrentdictionary and added test to prove

* Made Themes ConcrurrentDictionary. Added bunches of tests

* Code cleanup

* Code cleanup 2

* Code cleanup 3

* Tweaking Scheme

* ClearJsonErrors

* ClearJsonErrors2

* Updated Attribute API

* It all (mostly) works!

* Skip odd unit test

* Messed with Themes

* Theme tweaks

* Code reorg. New .md stuff

* Fixed Enabled. Added mock driver

* Fixed a bunch of View.Enabled related issues

* Scheme -> Get/SetScheme()

* Cleanup

* Cleanup2

* Broke something

* Fixed everything

* Made CM.Enable better

* Text Style Scenario

* Added comments

* Fixed UI Catalog Theme Changing

* Fixed more dynamic CM update stuff

* Warning cleanup

* New Default Theme

* fixed unit test

* Refactoring Scheme and Attribute to fix inheritance

* more unit tests

* ConfigProperty is not updating schemes correctly

* All unit tests pass.
Code cleanup

* All unit tests pass.
Code cleanup2

* Fixed unit tests

* Upgraded TextField and TextView

* Fixed TextView !Enabled bug

* More updates to TextView. More unit tests for SchemeManager

* Upgraded CharMap

* API docs

* Fixe HexView API

* upgrade HexView

* Fixed shortcut KeyView

* Fixed more bugs. Added new themes

* updated themes

* upgraded Border

* Fixed themes memory usage...mostly

* Fixed themes memory usage...mostly2

* Fixed themes memory usage...2

* Fixed themes memory usage...3

* Added new colors

* Fixed GetHardCodedConfig bug

* Added Themes Scenario - WIP

* Added Themes Scenario

* Tweaked Themes Scenario

* Code cleanup

* Fixed json schmea

* updated deepdives

* updated deepdives

* Tweaked Themes Scenario

* Made Schemes a concurrent dict

* Test cleanup

* Thread safe ConfigProperty tests

* trying to make things more thread safe

* more trying to make things more thread safe

* Fixing bugs in shadowview

* Fixing bugs in shadowview 2

* Refactored GetViewsUnderMouse to GetViewsUnderLocation etc...

* Fixed dupe unit tests?

* Added better description of layout and coordiantes to deep dive

* Added better description of layout and coordiantes to deep dive

* Modified tests that call v2.AddTimeout; they were returning true which means restart the timer!
This was causing mac/linux unit test failures.
I think

* Fixed auto scheme.
Broke TextView/TextField selection

* Realized Attribute.IsExplicitlySet is stupid; just use nullable

* Fixed Attribute. Simplified. MOre theme testing

* Updated themes again

* GetViewsUnderMouse to GetViewsUnderLocation broke TransparentMouse.

* Fixing mouseunder bugs

* rewriting...

* All working again.
Shadows are now slick as snot.
GetViewsUnderLocation is rewritten to actually work and be readable.
Tons more low-level unit tests.
Margin is now actually ViewportSettings.Transparent.

* Code cleanup

* Code cleanup

* Code cleanup of color apis

* Fixed Hover/Highlight

* Update Examples/UICatalog/Scenarios/AllViewsTester.cs

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

* Update Examples/UICatalog/Scenarios/CharacterMap/CharacterMap.cs

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

* Update Examples/UICatalog/Scenarios/Clipping.cs

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

* Fixed race condition?

* reverted

* Simplified Attribute API by removing events from SetAttributeForRole

* Removed recursion from GetViewsAtLocation

* Removed unneeded code

* Code clean up.
Fixed Scheme bug.

* reverted temporary disable

* Adjusted scheme algo

* Upgraded TextValidateField

* Fixed TextValidate bugs

* Tweaks

* Frameview rounded border by default

* API doc cleanup

* Readme fix

* Addressed tznind feeback

* Fixed more unit test issues by protecting Application statics from being set if Application.Initialized is not true

* Fixed more unit test issues by protecting Application statics from being set if Application.Initialized is not true 2

* cleanup

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-05-29 14:08:48 -06:00

219 lines
6.7 KiB
C#

using System.Collections.Generic;
using System.Linq;
using Terminal.Gui;
namespace UICatalog.Scenarios;
[ScenarioMetadata ("Windows & FrameViews", "Stress Tests Windows, sub-Windows, and FrameViews.")]
[ScenarioCategory ("Layout")]
public class WindowsAndFrameViews : Scenario
{
public override void Main ()
{
Application.Init ();
Window app = new ()
{
Title = GetQuitKeyAndName ()
};
static int About ()
{
return MessageBox.Query (
"About UI Catalog",
"UI Catalog is a comprehensive sample library for Terminal.Gui",
"Ok"
);
}
var margin = 2;
var padding = 1;
var contentHeight = 7;
// list of Windows we create
List<View> listWin = new ();
var win = new Window
{
Title = $"{listWin.Count} - Scenario: {GetName ()}",
X = Pos.Center (),
Y = 1,
Width = Dim.Fill (15),
Height = 10,
SchemeName = "Dialog",
Arrangement = ViewArrangement.Overlapped | ViewArrangement.Movable | ViewArrangement.Resizable
};
win.Padding.Thickness = new (padding);
win.Margin.Thickness = new (margin);
var paddingButton = new Button
{
X = Pos.Center (),
Y = 0,
SchemeName = "Error",
Text = $"Padding of container is {padding}"
};
paddingButton.Accepting += (s, e) => About ();
win.Add (paddingButton);
win.Add (
new Button
{
X = Pos.Center (),
Y = Pos.AnchorEnd (),
SchemeName = "Error",
Text = "Press ME! (Y = Pos.AnchorEnd(1))"
}
);
app.Add (win);
// add it to our list
listWin.Add (win);
// create 3 more Windows in a loop, adding them Application.Top
// Each with a
// button
// sub Window with
// TextField
// sub FrameView with
//
for (var pad = 0; pad < 3; pad++)
{
Window loopWin = null;
loopWin = new ()
{
Title = $"{listWin.Count} - Window Loop - padding = {pad}",
X = margin,
Y = Pos.Bottom (listWin.Last ()) + margin,
Width = Dim.Fill (margin),
Height = contentHeight + pad * 2 + 2,
Arrangement = ViewArrangement.Overlapped | ViewArrangement.Movable | ViewArrangement.Resizable
};
loopWin.Padding.Thickness = new (pad);
loopWin.SchemeName = "Dialog";
var pressMeButton = new Button
{
X = Pos.Center (), Y = 0, SchemeName = "Error", Text = "Press me! (Y = 0)",
};
pressMeButton.Accepting += (s, e) =>
MessageBox.ErrorQuery (loopWin.Title, "Neat?", "Yes", "No");
loopWin.Add (pressMeButton);
var subWin = new Window
{
Title = "Sub Window",
X = Pos.Percent (0),
Y = 1,
Width = Dim.Percent (50),
Height = 5,
SchemeName = "Base",
Text = "The Text in the Window",
Arrangement = ViewArrangement.Overlapped | ViewArrangement.Movable | ViewArrangement.Resizable
};
subWin.Add (
new TextField { Y = 1, SchemeName = "Error", Text = "Edit me! " + loopWin.Title }
);
loopWin.Add (subWin);
var frameView = new FrameView
{
X = Pos.Percent (50),
Y = 1,
Width = Dim.Percent (100, DimPercentMode.Position), // Or Dim.Percent (50)
Height = 5,
SchemeName = "Base",
Text = "The Text in the FrameView",
Title = "This is a Sub-FrameView"
};
frameView.Add (
new TextField { Y = 1, Text = "Edit Me!" }
);
loopWin.Add (frameView);
app.Add (loopWin);
listWin.Add (loopWin);
}
FrameView frame = null;
frame = new ()
{
X = margin,
Y = Pos.Bottom (listWin.Last ()) + margin / 2,
Width = Dim.Fill (margin),
Height = contentHeight + 2, // 2 for default padding
Title = "This is a FrameView"
};
frame.SchemeName = "Dialog";
frame.Add (
new Label
{
X = Pos.Center (), Y = 0, SchemeName = "Error", Text = "This is a Label! (Y = 0)"
}
);
var subWinofFV = new Window
{
Title = "This is a Sub-Window",
X = Pos.Percent (0),
Y = 1,
Width = Dim.Percent (50),
Height = Dim.Fill () - 1,
SchemeName = "Base",
Text = "The Text in the Window",
Arrangement = ViewArrangement.Overlapped | ViewArrangement.Movable | ViewArrangement.Resizable
};
subWinofFV.Add (
new TextField { SchemeName = "Error", Text = "Edit Me" }
);
subWinofFV.Add (new CheckBox { Y = 1, Text = "Check me" });
subWinofFV.Add (new CheckBox { Y = 2, Text = "Or, Check me" });
frame.Add (subWinofFV);
var subFrameViewofFV = new FrameView
{
X = Pos.Percent (50),
Y = 1,
Width = Dim.Percent (100),
Height = Dim.Fill () - 1,
SchemeName = "Base",
Text = "The Text in the FrameView",
Title = "this is a Sub-FrameView"
};
subFrameViewofFV.Add (new TextField { Width = 15, Text = "Edit Me" });
subFrameViewofFV.Add (new CheckBox { Y = 1, Text = "Check me" });
subFrameViewofFV.Add (new CheckBox { Y = 2, Text = "Or, Check me" });
frame.Add (
new CheckBox { X = 0, Y = Pos.AnchorEnd (), Text = "Btn1 (Y = Pos.AnchorEnd ())" }
);
var c = new CheckBox { X = Pos.AnchorEnd (), Y = Pos.AnchorEnd (), Text = "Btn2 (Y = Pos.AnchorEnd ())" };
frame.Add (c);
frame.Add (subFrameViewofFV);
app.Add (frame);
listWin.Add (frame);
app.SchemeName = "Base";
Application.Run (app);
app.Dispose ();
Application.Shutdown ();
}
}