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
attribute specifying the scenario's name and description. - Add one or more Scenario.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".
- Implement the Setup() override which will be called when a user selects the scenario to run.
- Optionally, implement the Init(Toplevel) 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
Inherited Members
Namespace: UICatalog
Assembly: UICatalog.dll
Syntax
public class Scenario : IDisposable
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")
});
}
}
}
Properties
Top
Declaration
public Toplevel Top { get; set; }
Property Value
Type | Description |
---|---|
Toplevel |
Win
Declaration
public Window Win { get; set; }
Property Value
Type | Description |
---|---|
Window |
Methods
Dispose()
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 catagory 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 |
Init(Toplevel)
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(Toplevel) to provide any Toplevel behavior needed.
Declaration
public virtual void Init(Toplevel top)
Parameters
Type | Name | Description |
---|---|---|
Toplevel | top |
Remarks
Thg base implementation calls Init(), sets Top to the passed in Toplevel, creates a Window for Win and adds it to Top.
Overrides that do not call the base.Run(), must call Init() before creating any views or calling other Terminal.Gui APIs.
RequestStop()
Stops the scenario. Override to change shutdown behavior for the Scenario.
Declaration
public virtual void RequestStop()
Run()
Declaration
public virtual void Run()
Remarks
Overrides that do not call the base.Run(), must call Shutdown(Boolean) before returning.
Setup()
Override this to implement the Scenario setup logic (create controls, etc...).
Declaration
public virtual void Setup()
Remarks
This is typically the best place to put scenario logic code.
ToString()
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String |