Class Scheme
Represents a theme definition that maps each VisualRole (such as Focus, Disabled, etc.) to an Attribute describing its foreground color, background color, and text style.
A Scheme enables consistent, semantic theming of UI elements by associating each visual state with a specific style. Each property (e.g., Normal, Focus, Disabled) is an Attribute. If a property is not explicitly set, its value is derived from other roles (typically Normal) using well-defined inheritance rules.
Scheme objects are immutable. To update a scheme, create a new instance with the desired values. Use SchemeManager to manage available schemes and apply them to views.
See https://gui-cs.github.io/Terminal.GuiV2Docs/docs/drawing.html for more information.
[JsonConverter(typeof(SchemeJsonConverter))]
public record Scheme : IEqualityOperators<Scheme, Scheme, bool>, IEquatable<Scheme>
- Inheritance
-
Scheme
- Implements
- Inherited Members
Remarks
Immutability: Scheme objects are immutable. Once constructed, their properties cannot be changed. To modify a Scheme, create a new instance with the desired values (e.g., using the Scheme(Scheme?) constructor).
Attribute Resolution Algorithm:
Each Scheme property corresponds to a VisualRole and is an Attribute.
The Normal attribute must always be set.
All other attributes are optional. If an attribute for a given VisualRole is not explicitly set,
its value is derived using the following rules:
- Normal: Must always be explicitly set.
- Focus: If not set, derived from Normal by swapping foreground and background colors.
- Active: If not set, derived from Focus by:
- Highlight: If not set, derived from Normal by:
- Editable: If not set, derived from Normal by:
- ReadOnly: If not set, derived from Editable by adding Faint to the style.
- Disabled: If not set, derived from Normal by adding Faint to the style.
- HotNormal: If not set, derived from Normal by adding Underline to the style.
- HotFocus: If not set, derived from Focus by adding Underline to the style.
- HotActive: If not set, derived from Active by adding Underline to the style.
Constructors
- Scheme(Attribute)
Creates a new instance, initialized with the values from
attribute
.
- Scheme(Scheme?)
Creates a new instance, initialized with the values from
scheme
.
Properties
- Active
The visual role for elements that are active or selected (e.g., selected item in a ListView). Also used for headers in, HexView, CharMap and TabView. If not explicitly set, will be a derived value. See the description for Scheme for details on the algorithm used.
- Disabled
The visual role for elements that are disabled and not interactable. If not explicitly set, will be a derived value. See the description for Scheme for details on the algorithm used.
- Editable
The visual role for elements that are editable (e.g., TextField and TextView). If not explicitly set, will be a derived value. See the description for Scheme for details on the algorithm used.
- Focus
The visual role when the element is focused. If not explicitly set, will be a derived value. See the description for Scheme for details on the algorithm used.
- Highlight
The visual role for elements that are highlighted (e.g., when the mouse is inside a Button). If not explicitly set, will be a derived value. See the description for Scheme for details on the algorithm used.
- HotActive
The visual role for Active elements with a HotKey indicator. If not explicitly set, will be a derived value. See the description for Scheme for details on the algorithm used.
- HotFocus
The visual role for Focus elements with a HotKey indicator. If not explicitly set, will be a derived value. See the description for Scheme for details on the algorithm used.
- HotNormal
The visual role for Normal elements with a HotKey indicator. If not explicitly set, will be a derived value. See the description for Scheme for details on the algorithm used.
- Normal
The default visual role for unfocused, unselected, enabled elements. The Normal attribute must always be set. All other attributes are optional, and if not explicitly set, will be automatically generated. See the description for Scheme for details on the algorithm used.
- ReadOnly
The visual role for elements that are normally editable but currently read-only. If not explicitly set, will be a derived value. See the description for Scheme for details on the algorithm used.
Methods
- Equals(Scheme?)
Indicates whether the current object is equal to another object of the same type.
- GetAttributeForRole(string)
Gets the Attribute associated with a specified VisualRole string.
- GetAttributeForRole(VisualRole)
Gets the Attribute associated with a specified VisualRole, applying inheritance rules for attributes not explicitly set.
- GetHashCode()
Serves as the default hash function.
- ToString()
Returns a string that represents the current object.
- TryGetExplicitlySetAttributeForRole(VisualRole, out Attribute?)
Attempts to get the Attribute associated with a specified VisualRole. If the role is not explicitly set, it will return false and the out parameter will be null.