|
|
1 年之前 | |
|---|---|---|
| .. | ||
| Properties | 1 年之前 | |
| Resources | 1 年之前 | |
| Scenarios | 1 年之前 | |
| .gitignore | 5 年之前 | |
| Dockerfile | 2 年之前 | |
| KeyBindingsDialog.cs | 1 年之前 | |
| NumberToWords.cs | 1 年之前 | |
| README.md | 1 年之前 | |
| Scenario.cs | 1 年之前 | |
| UICatalog.cs | 1 年之前 | |
| UICatalog.csproj | 1 年之前 | |
| UICatalog.csproj.DotSettings | 1 年之前 | |
| generic_screenshot.png | 5 年之前 | |
| screenshot.png | 5 年之前 | |
UI Catalog is a comprehensive sample library for Terminal.Gui. It attempts to satisfy the following goals:
The original demo.cs sample app for Terminal.Gui is neither good to showcase, nor does it explain different concepts. In addition, because it is built on a single source file, it has proven to cause friction when multiple contributors are simultaneously working on different aspects of Terminal.Gui.
See Issue #368 for more background.
Build and run UI Catalog by typing dotnet run from the UI Catalog folder or by using the Terminal.Gui Visual Studio solution.
Program.cs is the main UI Catalog app and provides a UI for selecting and running Scenarios. Each *Scenario is implemented as a class derived from Scenario and Program.cs uses reflection to dynamically build the UI.
Scenarios are tagged with categories using the [ScenarioCategory] attribute. The left pane of the main screen lists the categories. Clicking on a category shows all the scenarios in that category.
Scenarios can be run either from the UICatalog.exe app UI or by being specified on the command line:
UICatalog.exe <Scenario Name>
e.g.
UICatalog.exe Buttons
Hitting ENTER on a selected Scenario or double-clicking on a Scenario runs that scenario as though it were a stand-alone Terminal.Gui app.
When a Scenario is run, it runs as though it were a standalone Terminal.Gui app. However, scaffolding is provided (in the Scenario base class) that (optionally) takes care of Terminal.Gui initialization.
To add a new Scenario simply:
.cs file in the Scenarios directory that derives from Scenario.[ScenarioMetaData] attribute to the class specifying the scenario's name and description.[ScenarioCategory] attributes to the class specifying which categories the sceanrio belongs to. If you don't specify a category the sceanrio will show up in "All".Setup override which will be called when a user selects the scenario to run.Init and/or Run overrides to provide a custom implementation.The sample below is provided in the .\UICatalog\Scenarios directory as a generic sample that can be copied and re-named:
using Terminal.Gui;
namespace UICatalog {
[ScenarioMetadata (Name: "Generic", Description: "Generic sample - A template for creating new Scenarios")]
[ScenarioCategory ("Controls")]
class MyScenario : Scenario {
public override void Setup ()
{
// Put your scenario code here, e.g.
Win.Add (new Button () {
Text = "Press me!",
X = Pos.Center (),
Y = Pos.Center (),
Clicked = () => MessageBox.Query (20, 7, "Hi", "Neat?", "Yes", "No")
});
}
}
}
Scenario provides Win, a Window object that provides a canvas for the Scenario to operate.
The default Window shows the Scenario name and supports exiting the Scenario through the Esc key.
To build a more advanced scenario, where control of the Toplevel and Window is needed (e.g. for scenarios using MenuBar or StatusBar), simply use Application.Top per normal Terminal.Gui programming, as seen in the Notepad scenario.
For complete control, the Init and Run overrides can be implemented. The base.Init creates Win. The base.Run simply calls Application.Run(Application.Top).
Name for Scenarios. Keep them short.Description.Scenario code to describe to others why it's a useful Scenario.Scenarios with [ScenarioCategory] attributes. Minimize the number of new categories created.Bug Repo Category for Scenarios that reproduce bugs.
develop submit another PR to remove the Scenario (or modify it to provide a good regression test/sample).UI Catalog as Terminal.Gui Github Issues with "UICatalog: ".