Table of Contents

Class Scenario

Namespace
UICatalog
Assembly
UICatalog.dll

Base class for each demo/scenario.

To define a new scenario:

  1. Create a new .cs file in the Scenarios directory that derives from Scenario.
  2. Annotate the Scenario derived class with a Scenario.ScenarioMetadata attribute specifying the scenario's name and description.
  3. 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".
  4. Implement the Setup() override which will be called when a user selects the scenario to run.
  5. Optionally, implement the Init(Toplevel, ColorScheme) 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. /

public class Scenario : IDisposable
Inheritance
Scenario
Implements
Derived
Inherited Members

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

Win

The Window for the Scenario. This should be set to Top in most cases.

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Dispose(bool)
GetCategories()

Helper function to get the list of categories a Scenario belongs to (defined in Scenario.ScenarioCategory)

GetDescription()

Helper to get the Scenario Description (defined in Scenario.ScenarioMetadata)

GetName()

Helper to get the Scenario Name (defined in Scenario.ScenarioMetadata)

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

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.

RequestStop()

Stops the scenario. Override to change shutdown behavior for the Scenario.

Run()

Runs the Scenario. Override to start the Scenario using a Toplevel different than Top.

Setup()

Override this to implement the Scenario setup logic (create controls, etc...).

ToString()

Gets the Scenario Name + Description with the Description padded based on the longest known Scenario name.