Class Scenario
Base class for each demo/scenario.
To define a new scenario:
- Create a new
.cs
file in theScenarios directory that derives from Scenario. - Annotate the Scenario derived class with a Scenario.ScenarioMetadata attribute specifying the scenario's name and description.
- Add one or more Scenario.ScenarioCategory attributes to the class specifying which categories the scenario belongs to. If you don't specify a category the scenario will show up in "_All".
- Implement the Setup() override which will be called when a user selects the scenario to run.
- Optionally, implement the
and/or Run() overrides to provide a custom implementation.
The UI Catalog program uses reflection to find all scenarios and adds them to the ListViews. Press ENTER to run the selected scenario. Press CTRL-Q to exit it. /
Inheritance
Implements
Examples
The example below is provided in the 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 ("Press me!") {
X = Pos.Center (),
Y = Pos.Center (),
Clicked = () => MessageBox.Query (20, 7, "Hi", "Neat?", "Yes", "No")
});
}
}
}
Inherited Members
Namespace: UICatalog
Assembly: UICatalog.dll
Syntax
public class Scenario : IDisposable
Properties
| Improve this Doc View SourceWin
Declaration
public Window Win { get; set; }
Property Value
Type | Description |
---|---|
Window |
Methods
| Improve this Doc View SourceDispose()
Declaration
public void Dispose()
Dispose(Boolean)
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing |
GetCategories()
Helper function to get the list of categories a Scenario belongs to (defined in Scenario.ScenarioCategory)
Declaration
public List<string> GetCategories()
Returns
Type | Description |
---|---|
System.Collections.Generic.List<System.String> | list of category names |
GetDescription()
Helper to get the Scenario Description (defined in Scenario.ScenarioMetadata)
Declaration
public string GetDescription()
Returns
Type | Description |
---|---|
System.String |
GetName()
Helper to get the Scenario Name (defined in Scenario.ScenarioMetadata)
Declaration
public string GetName()
Returns
Type | Description |
---|---|
System.String |
GetScenarios()
Returns a list of all Scenario instanaces defined in the project, sorted by Name. https://stackoverflow.com/questions/5411694/get-all-inherited-classes-of-an-abstract-class
Declaration
public static List<Scenario> GetScenarios()
Returns
Type | Description |
---|---|
System.Collections.Generic.List<Scenario> |
Init(ColorScheme)
Helper that provides the default Window implementation with a frame and label showing the name of the Scenario and logic to exit back to the Scenario picker UI. Override Init(ColorScheme) to provide any Toplevel behavior needed.
Declaration
public virtual void Init(ColorScheme colorScheme)
Parameters
Type | Name | Description |
---|---|---|
ColorScheme | colorScheme | The colorscheme to use. |
RequestStop()
Stops the scenario. Override to change shutdown behavior for the Scenario.
Declaration
public virtual void RequestStop()
Run()
Declaration
public virtual void Run()
Setup()
Override this to implement the Scenario setup logic (create controls, etc...).
Declaration
public virtual void Setup()
ToString()
Gets the Scenario Name + Description with the Description padded based on the longest known Scenario name.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String |