mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
* Pulled from v2_release * Refactor migration guide for Terminal.Gui v2 Restructured and expanded the migration guide to provide a comprehensive resource for transitioning from Terminal.Gui v1 to v2. Key updates include: - Added a Table of Contents for easier navigation. - Summarized major architectural changes in v2, including the instance-based application model, IRunnable architecture, and 24-bit TrueColor support. - Updated examples to reflect new patterns, such as initializers replacing constructors and explicit disposal using `IDisposable`. - Documented changes to the layout system, including the removal of `Absolute`/`Computed` styles and the introduction of `Viewport`. - Standardized event patterns to use `object sender, EventArgs args`. - Detailed updates to the Keyboard, Mouse, and Navigation APIs, including configurable key bindings and viewport-relative mouse coordinates. - Replaced legacy components like `ScrollView` and `ContextMenu` with built-in scrolling and `PopoverMenu`. - Clarified disposal rules and introduced best practices for resource management. - Provided a complete migration example and a summary of breaking changes. This update aims to simplify the migration process by addressing breaking changes, introducing new features, and aligning with modern .NET conventions. * Refactor to use Application.Instance for lifecycle management Replaced all occurrences of `ApplicationImpl.Instance` with the new `Application.Instance` property across the codebase to align with the updated application lifecycle model. Encapsulated the `ApplicationImpl` class by making it `internal`, ensuring it is no longer directly accessible outside its assembly. Introduced the `[Obsolete]` `Application.Instance` property as a backward-compatible singleton for the legacy static `Application` model, while encouraging the use of `Application.Create()` for new code. Updated `MessageBox` methods to use `Application.Instance` for consistent modal dialog management. Improved documentation to reflect these changes and emphasize the transition to the instance-based application model. Performed code cleanup in multiple classes to ensure consistency and maintainability. These changes maintain backward compatibility while preparing the codebase for the eventual removal of the legacy `ApplicationImpl` class. * Fix doc bug * - Removed obsolete `.cd` class diagram files. - Introduced `IRunnable` interface for decoupling component execution. - Added fluent API for running dialogs and retrieving results. - Enhanced `View` with `App` and `Driver` properties for better decoupling. - Improved testability with support for mock and real applications. - Implemented `IDisposable` for proper resource cleanup. - Replaced `RunnableSessionStack` with `SessionStack` for session management. - Updated driver architecture to align with the new model. - Scoped `IKeyboard` to application contexts for modularity. - Updated documentation with migration strategies and best practices. These changes modernize the library, improve maintainability, and align with current development practices.
218 lines
6.7 KiB
C#
218 lines
6.7 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
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 (Application.Instance,
|
|
"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.TopRunnable
|
|
// 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 ((s as View)?.App, 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 ();
|
|
}
|
|
}
|