Skip to content

Game.UI.Widgets.IIconProvider

Assembly: Assembly-CSharp.dll
Namespace: Game.UI.Widgets

Type: Interface

Base: N/A

Summary:
Provides a contract for UI widgets or other components to expose a lazily-evaluated or dynamic icon source. The interface exposes a single property, iconSrc, of type System.Func, allowing consumers to retrieve an icon path, resource key, data URI, or any string identifier when needed. This is useful for cases where the icon can change over time or depends on current state and should be resolved at render time rather than stored as a constant.


Fields

  • None
    No backing fields are defined on the interface level. Implementations may have private fields to store state or cached values used by the iconSrc delegate.

Properties

  • public System.Func<string> iconSrc { get; set; }
    A getter/setter for a function that returns a string representing the icon source. Typical uses:
  • Return a file path or resource key for the icon atlas.
  • Return a data URI or base64 string for inline images.
  • Provide a delegate that computes which icon to show based on current state. Notes:
  • The delegate is invoked by the consumer; implementations should avoid long-running work inside the delegate.
  • The delegate can be replaced at runtime by setting the property, allowing dynamic icon updates.

Constructors

  • None
    Interfaces do not define constructors. Implementing types provide their own constructors.

Methods

  • None defined on the interface.
    Implementations may provide additional methods to manage icon state, caching, or preloading.

Usage Example

public class SimpleIconProvider : Game.UI.Widgets.IIconProvider
{
    // Provide a simple function that returns a path or key.
    public System.Func<string> iconSrc { get; set; }

    public SimpleIconProvider(string initialPath)
    {
        iconSrc = () => initialPath;
    }
}

// Usage
var provider = new SimpleIconProvider("Icons/Building/house.png");

// Later, consumer retrieves the icon source when rendering:
string iconPath = provider.iconSrc(); // "Icons/Building/house.png"

// Update to a different icon dynamically:
provider.iconSrc = () => IsOpen ? "Icons/Building/house_open.png" : "Icons/Building/house.png";

Additional notes: - Ensure the returned string format matches what the UI system expects (file path, atlas key, data URI, etc.). - Keep the delegate lightweight; heavy computation should be performed elsewhere and cached.