Skip to content
Eduard Gushchin edited this page Jul 1, 2026 · 3 revisions

Home | API by Category | Complete API Index | API Compatibility

Field Value
Full name Electron2D.Theme
Namespace Electron2D
Kind class
Category UI and Text

Overview

Provides a reusable resource for styling UI controls.

Syntax

public class Electron2D.Theme : Electron2D.Resource

Godot 4.7 C# profile compatibility

Profile: Electron2D 0.1.0 2D
Status: Supported / Parity verified
Out of profile: no
Godot reference: Theme

UI theme resource with colors, constants, fonts, font sizes, icons, style boxes, defaults, AOT-safe value serialization and branch lookup through Control.

Remarks

Theme stores typed UI items by item name and theme type. Controls resolve local overrides first, then the nearest theme assigned to a control branch.

Thread Safety

This type is not synchronized. Create and mutate themes on the main scene thread.

Since

This type is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Control.Theme
  • Electron2D.StyleBox

Members

Member Kind Summary
DefaultBaseScale Property Gets or sets the default base scale for this theme.
DefaultFont Property Gets or sets the default font for this theme.
DefaultFontSize Property Gets or sets the default font size for this theme.
Electron2D.Theme() Constructor Initializes a new instance of the Electron2D.Theme class.
Clear() Method Removes all items and default values from this theme.
ClearColor(System.String, System.String) Method Removes a color item.
ClearConstant(System.String, System.String) Method Removes a constant item.
ClearFont(System.String, System.String) Method Removes a font item.
ClearFontSize(System.String, System.String) Method Removes a font size item.
ClearIcon(System.String, System.String) Method Removes an icon item.
ClearStyleBox(System.String, System.String) Method Removes a style box item.
GetColor(System.String, System.String) Method Gets a color item.
GetConstant(System.String, System.String) Method Gets a constant item.
GetFont(System.String, System.String) Method Gets a font item.
GetFontSize(System.String, System.String) Method Gets a font size item.
GetIcon(System.String, System.String) Method Gets an icon item.
GetStyleBox(System.String, System.String) Method Gets a style box item.
HasColor(System.String, System.String) Method Reports whether a color item exists.
HasConstant(System.String, System.String) Method Reports whether a constant item exists.
HasDefaultBaseScale() Method Reports whether this theme has a valid default base scale.
HasDefaultFont() Method Reports whether this theme has a default font.
HasDefaultFontSize() Method Reports whether this theme has a valid default font size.
HasFont(System.String, System.String) Method Reports whether a font item exists.
HasFontSize(System.String, System.String) Method Reports whether a font size item exists.
HasIcon(System.String, System.String) Method Reports whether an icon item exists.
HasStyleBox(System.String, System.String) Method Reports whether a style box item exists.
SetColor(System.String, System.String, Electron2D.Color) Method Sets a color item.
SetConstant(System.String, System.String, System.Int32) Method Sets a constant item.
SetFont(System.String, System.String, Electron2D.Font) Method Sets a font item.
SetFontSize(System.String, System.String, System.Int32) Method Sets a font size item.
SetIcon(System.String, System.String, Electron2D.Texture2D) Method Sets an icon item.
SetStyleBox(System.String, System.String, Electron2D.StyleBox) Method Sets a style box item.

Member Details

DefaultBaseScale

Kind: Property

public System.Single DefaultBaseScale { get; set; }

Summary

Gets or sets the default base scale for this theme.

Remarks

Controls use this value to scale resolved constants and font sizes.

Value

A finite non-negative scale. A value of 0 means the theme has no explicit base scale.

Exceptions

  • System.ArgumentOutOfRangeException: Thrown when the assigned value is negative or not finite.

Thread Safety

This property is not synchronized. Mutate it on the main scene thread.

Since

This property is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme.HasDefaultBaseScale

DefaultFont

Kind: Property

public Electron2D.Font DefaultFont { get; set; }

Summary

Gets or sets the default font for this theme.

Remarks

Controls use this value when a requested font item is not present.

Value

The fallback font resource, or null when no default font is set.

Thread Safety

This property is not synchronized. Mutate it on the main scene thread.

Since

This property is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme.HasDefaultFont

DefaultFontSize

Kind: Property

public System.Int32 DefaultFontSize { get; set; }

Summary

Gets or sets the default font size for this theme.

Remarks

Controls scale this value by the resolved theme base scale before using it for drawing.

Value

The fallback font size in UI units. Values below 1 mean no default font size is set.

Thread Safety

This property is not synchronized. Mutate it on the main scene thread.

Since

This property is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme.HasDefaultFontSize

Electron2D.Theme()

Kind: Constructor

public Electron2D.Theme()

Summary

Initializes a new instance of the Electron2D.Theme class.

Remarks

The new theme contains no items and uses runtime fallback values for missing theme lookups.

Thread Safety

This constructor is not synchronized. Call it from the main scene thread.

Since

This constructor is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme

Clear()

Kind: Method

public System.Void Clear()()

Summary

Removes all items and default values from this theme.

Remarks

The theme remains usable after clearing. Later lookups fall back to runtime defaults until new items are added.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme.SetColor(System.String,System.String,Electron2D.Color)

ClearColor(System.String, System.String)

Kind: Method

public System.Void ClearColor(System.String, System.String)(System.String name, System.String themeType)

Summary

Removes a color item.

Remarks

Removing a missing item is a no-op.

Parameters

  • name: The color item name.
  • themeType: The theme type that owns the item.

Exceptions

  • System.ArgumentException: Thrown when name or themeType is empty.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme.HasColor(System.String,System.String)

ClearConstant(System.String, System.String)

Kind: Method

public System.Void ClearConstant(System.String, System.String)(System.String name, System.String themeType)

Summary

Removes a constant item.

Remarks

Removing a missing item is a no-op.

Parameters

  • name: The constant item name.
  • themeType: The theme type that owns the item.

Exceptions

  • System.ArgumentException: Thrown when name or themeType is empty.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme.HasConstant(System.String,System.String)

ClearFont(System.String, System.String)

Kind: Method

public System.Void ClearFont(System.String, System.String)(System.String name, System.String themeType)

Summary

Removes a font item.

Remarks

Removing a missing item is a no-op.

Parameters

  • name: The font item name.
  • themeType: The theme type that owns the item.

Exceptions

  • System.ArgumentException: Thrown when name or themeType is empty.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme.HasFont(System.String,System.String)

ClearFontSize(System.String, System.String)

Kind: Method

public System.Void ClearFontSize(System.String, System.String)(System.String name, System.String themeType)

Summary

Removes a font size item.

Remarks

Removing a missing item is a no-op.

Parameters

  • name: The font size item name.
  • themeType: The theme type that owns the item.

Exceptions

  • System.ArgumentException: Thrown when name or themeType is empty.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme.HasFontSize(System.String,System.String)

ClearIcon(System.String, System.String)

Kind: Method

public System.Void ClearIcon(System.String, System.String)(System.String name, System.String themeType)

Summary

Removes an icon item.

Remarks

Removing a missing item is a no-op.

Parameters

  • name: The icon item name.
  • themeType: The theme type that owns the item.

Exceptions

  • System.ArgumentException: Thrown when name or themeType is empty.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme.HasIcon(System.String,System.String)

ClearStyleBox(System.String, System.String)

Kind: Method

public System.Void ClearStyleBox(System.String, System.String)(System.String name, System.String themeType)

Summary

Removes a style box item.

Remarks

Removing a missing item is a no-op.

Parameters

  • name: The style box item name.
  • themeType: The theme type that owns the item.

Exceptions

  • System.ArgumentException: Thrown when name or themeType is empty.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme.HasStyleBox(System.String,System.String)

GetColor(System.String, System.String)

Kind: Method

public Electron2D.Color GetColor(System.String, System.String)(System.String name, System.String themeType)

Summary

Gets a color item.

Remarks

Use Electron2D.Theme.HasColor(System.String,System.String) to distinguish an explicit white color from a missing item.

Parameters

  • name: The color item name.
  • themeType: The theme type that owns the item.

Returns

The stored color, or opaque white when the item is missing.

Exceptions

  • System.ArgumentException: Thrown when name or themeType is empty.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme.SetColor(System.String,System.String,Electron2D.Color)

GetConstant(System.String, System.String)

Kind: Method

public System.Int32 GetConstant(System.String, System.String)(System.String name, System.String themeType)

Summary

Gets a constant item.

Remarks

Use Electron2D.Theme.HasConstant(System.String,System.String) to distinguish an explicit zero from a missing item.

Parameters

  • name: The constant item name.
  • themeType: The theme type that owns the item.

Returns

The stored constant, or 0 when the item is missing.

Exceptions

  • System.ArgumentException: Thrown when name or themeType is empty.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme.SetConstant(System.String,System.String,System.Int32)

GetFont(System.String, System.String)

Kind: Method

public Electron2D.Font GetFont(System.String, System.String)(System.String name, System.String themeType)

Summary

Gets a font item.

Remarks

Use Electron2D.Theme.HasFont(System.String,System.String) to distinguish a named item from the default font fallback.

Parameters

  • name: The font item name.
  • themeType: The theme type that owns the item.

Returns

The stored font, the default font, or null when neither exists.

Exceptions

  • System.ArgumentException: Thrown when name or themeType is empty.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme.SetFont(System.String,System.String,Electron2D.Font)

GetFontSize(System.String, System.String)

Kind: Method

public System.Int32 GetFontSize(System.String, System.String)(System.String name, System.String themeType)

Summary

Gets a font size item.

Remarks

This method returns the raw theme value. Controls apply base scale when resolving font size items.

Parameters

  • name: The font size item name.
  • themeType: The theme type that owns the item.

Returns

The stored font size, the default font size, or 16 when neither exists.

Exceptions

  • System.ArgumentException: Thrown when name or themeType is empty.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme.SetFontSize(System.String,System.String,System.Int32)

GetIcon(System.String, System.String)

Kind: Method

public Electron2D.Texture2D GetIcon(System.String, System.String)(System.String name, System.String themeType)

Summary

Gets an icon item.

Remarks

Icon items are runtime texture resources resolved by controls and custom widgets.

Parameters

  • name: The icon item name.
  • themeType: The theme type that owns the item.

Returns

The stored icon, or null when the item is missing.

Exceptions

  • System.ArgumentException: Thrown when name or themeType is empty.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme.SetIcon(System.String,System.String,Electron2D.Texture2D)

GetStyleBox(System.String, System.String)

Kind: Method

public Electron2D.StyleBox GetStyleBox(System.String, System.String)(System.String name, System.String themeType)

Summary

Gets a style box item.

Remarks

Style boxes are used by controls to draw themed backgrounds and borders.

Parameters

  • name: The style box item name.
  • themeType: The theme type that owns the item.

Returns

The stored style box, or null when the item is missing.

Exceptions

  • System.ArgumentException: Thrown when name or themeType is empty.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme.SetStyleBox(System.String,System.String,Electron2D.StyleBox)

HasColor(System.String, System.String)

Kind: Method

public System.Boolean HasColor(System.String, System.String)(System.String name, System.String themeType)

Summary

Reports whether a color item exists.

Remarks

This method checks only color items and does not inspect defaults.

Parameters

  • name: The color item name.
  • themeType: The theme type that owns the item.

Returns

true when the item exists; otherwise, false.

Exceptions

  • System.ArgumentException: Thrown when name or themeType is empty.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme.SetColor(System.String,System.String,Electron2D.Color)

HasConstant(System.String, System.String)

Kind: Method

public System.Boolean HasConstant(System.String, System.String)(System.String name, System.String themeType)

Summary

Reports whether a constant item exists.

Remarks

This method checks only constant items and does not inspect defaults.

Parameters

  • name: The constant item name.
  • themeType: The theme type that owns the item.

Returns

true when the item exists; otherwise, false.

Exceptions

  • System.ArgumentException: Thrown when name or themeType is empty.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme.SetConstant(System.String,System.String,System.Int32)

HasDefaultBaseScale()

Kind: Method

public System.Boolean HasDefaultBaseScale()()

Summary

Reports whether this theme has a valid default base scale.

Remarks

A theme without a base scale falls back to the runtime scale 1.

Returns

true when Electron2D.Theme.DefaultBaseScale is greater than 0; otherwise, false.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme.DefaultBaseScale

HasDefaultFont()

Kind: Method

public System.Boolean HasDefaultFont()()

Summary

Reports whether this theme has a default font.

Remarks

A default font is used only when a specific font item is missing.

Returns

true when Electron2D.Theme.DefaultFont is not null; otherwise, false.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme.DefaultFont

HasDefaultFontSize()

Kind: Method

public System.Boolean HasDefaultFontSize()()

Summary

Reports whether this theme has a valid default font size.

Remarks

A default font size is used only when a specific font size item is missing.

Returns

true when Electron2D.Theme.DefaultFontSize is greater than 0; otherwise, false.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme.DefaultFontSize

HasFont(System.String, System.String)

Kind: Method

public System.Boolean HasFont(System.String, System.String)(System.String name, System.String themeType)

Summary

Reports whether a font item exists.

Remarks

This method checks only named font items and does not inspect Electron2D.Theme.DefaultFont.

Parameters

  • name: The font item name.
  • themeType: The theme type that owns the item.

Returns

true when the item exists; otherwise, false.

Exceptions

  • System.ArgumentException: Thrown when name or themeType is empty.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme.SetFont(System.String,System.String,Electron2D.Font)

HasFontSize(System.String, System.String)

Kind: Method

public System.Boolean HasFontSize(System.String, System.String)(System.String name, System.String themeType)

Summary

Reports whether a font size item exists.

Remarks

This method checks only named font size items and does not inspect Electron2D.Theme.DefaultFontSize.

Parameters

  • name: The font size item name.
  • themeType: The theme type that owns the item.

Returns

true when the item exists; otherwise, false.

Exceptions

  • System.ArgumentException: Thrown when name or themeType is empty.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme.SetFontSize(System.String,System.String,System.Int32)

HasIcon(System.String, System.String)

Kind: Method

public System.Boolean HasIcon(System.String, System.String)(System.String name, System.String themeType)

Summary

Reports whether an icon item exists.

Remarks

This method checks only icon items.

Parameters

  • name: The icon item name.
  • themeType: The theme type that owns the item.

Returns

true when the item exists; otherwise, false.

Exceptions

  • System.ArgumentException: Thrown when name or themeType is empty.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme.SetIcon(System.String,System.String,Electron2D.Texture2D)

HasStyleBox(System.String, System.String)

Kind: Method

public System.Boolean HasStyleBox(System.String, System.String)(System.String name, System.String themeType)

Summary

Reports whether a style box item exists.

Remarks

This method checks only style box items.

Parameters

  • name: The style box item name.
  • themeType: The theme type that owns the item.

Returns

true when the item exists; otherwise, false.

Exceptions

  • System.ArgumentException: Thrown when name or themeType is empty.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme.SetStyleBox(System.String,System.String,Electron2D.StyleBox)

SetColor(System.String, System.String, Electron2D.Color)

Kind: Method

public System.Void SetColor(System.String, System.String, Electron2D.Color)(System.String name, System.String themeType, Electron2D.Color color)

Summary

Sets a color item.

Remarks

Existing items with the same name and theme type are replaced.

Parameters

  • name: The color item name.
  • themeType: The theme type that owns the item.
  • color: The color value to store.

Exceptions

  • System.ArgumentException: Thrown when name or themeType is empty.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme.GetColor(System.String,System.String)

SetConstant(System.String, System.String, System.Int32)

Kind: Method

public System.Void SetConstant(System.String, System.String, System.Int32)(System.String name, System.String themeType, System.Int32 constant)

Summary

Sets a constant item.

Remarks

Constants are scaled by controls when resolved through Electron2D.Control.GetThemeConstant(System.String,System.String).

Parameters

  • name: The constant item name.
  • themeType: The theme type that owns the item.
  • constant: The non-negative integer value to store.

Exceptions

  • System.ArgumentException: Thrown when name or themeType is empty.
  • System.ArgumentOutOfRangeException: Thrown when constant is negative.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme.GetConstant(System.String,System.String)

SetFont(System.String, System.String, Electron2D.Font)

Kind: Method

public System.Void SetFont(System.String, System.String, Electron2D.Font)(System.String name, System.String themeType, Electron2D.Font font)

Summary

Sets a font item.

Remarks

Existing items with the same name and theme type are replaced.

Parameters

  • name: The font item name.
  • themeType: The theme type that owns the item.
  • font: The font resource to store.

Exceptions

  • System.ArgumentException: Thrown when name or themeType is empty.
  • System.ArgumentNullException: Thrown when font is null.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme.GetFont(System.String,System.String)

SetFontSize(System.String, System.String, System.Int32)

Kind: Method

public System.Void SetFontSize(System.String, System.String, System.Int32)(System.String name, System.String themeType, System.Int32 fontSize)

Summary

Sets a font size item.

Remarks

Font sizes are scaled by controls when resolved through Electron2D.Control.GetThemeFontSize(System.String,System.String).

Parameters

  • name: The font size item name.
  • themeType: The theme type that owns the item.
  • fontSize: The font size value. It must be greater than zero.

Exceptions

  • System.ArgumentException: Thrown when name or themeType is empty.
  • System.ArgumentOutOfRangeException: Thrown when fontSize is less than or equal to zero.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme.GetFontSize(System.String,System.String)

SetIcon(System.String, System.String, Electron2D.Texture2D)

Kind: Method

public System.Void SetIcon(System.String, System.String, Electron2D.Texture2D)(System.String name, System.String themeType, Electron2D.Texture2D icon)

Summary

Sets an icon item.

Remarks

Existing items with the same name and theme type are replaced.

Parameters

  • name: The icon item name.
  • themeType: The theme type that owns the item.
  • icon: The texture resource to store.

Exceptions

  • System.ArgumentException: Thrown when name or themeType is empty.
  • System.ArgumentNullException: Thrown when icon is null.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme.GetIcon(System.String,System.String)

SetStyleBox(System.String, System.String, Electron2D.StyleBox)

Kind: Method

public System.Void SetStyleBox(System.String, System.String, Electron2D.StyleBox)(System.String name, System.String themeType, Electron2D.StyleBox styleBox)

Summary

Sets a style box item.

Remarks

Existing items with the same name and theme type are replaced.

Parameters

  • name: The style box item name.
  • themeType: The theme type that owns the item.
  • styleBox: The style box resource to store.

Exceptions

  • System.ArgumentException: Thrown when name or themeType is empty.
  • System.ArgumentNullException: Thrown when styleBox is null.

Thread Safety

This method is not synchronized. Call it on the main scene thread.

Since

This method is available since Electron2D 0.1.0 Preview.

See Also

  • Electron2D.Theme.GetStyleBox(System.String,System.String)

Clone this wiki locally