Skip to content

Game.UI.Widgets.IWidget

Assembly:
Assembly-CSharp (typical for Cities: Skylines 2 mod assemblies)

Namespace:
Game.UI.Widgets

Type:
interface

Base:
Colossal.UI.Binding.IJsonWritable

Summary:
Represents a UI widget contract used by the game's UI system. Implementers expose a path (PathSegment) identifying the widget in the hierarchy, a list of visible child widgets, a string name describing the properties type, and provide update and JSON-serialization entry points. This interface is used by the UI framework to update widget state and serialize widget properties for tooling, saving, or debugging.


Fields

  • None.
    This is an interface; it declares no backing fields.

Properties

  • PathSegment path { get; set; }
    Path segment that identifies where this widget lives in the UI hierarchy. Implementations should get and set this to indicate the widget's location/identifier in the widget tree.

  • IList<IWidget> visibleChildren { get; }
    A read-only list of child widgets that are currently visible. The UI system inspects this to traverse/render children or to propagate updates.

  • string propertiesTypeName { get; }
    A string identifying the type name (or key) of this widget's properties object. Used when writing/serializing properties so the receiving code can interpret the JSON correctly.

Constructors

  • None.
    Interfaces do not define constructors. Concrete implementations provide constructors as needed.

Methods

  • WidgetChanges Update()
    Called by the UI system to allow the widget to update its internal state. Returns a WidgetChanges value (an enum) indicating what changed as a result of the update (e.g., layout, visuals, none). Implementers should perform run-time updates and return the appropriate change flag(s).

  • void WriteProperties(IJsonWriter writer)
    Serialize this widget's properties to the provided IJsonWriter. Implementations must write the widget-specific properties (typically using the propertiesTypeName to indicate the payload type) so tools or the save system can consume them.

Usage Example

using System.Collections.Generic;
using Colossal.UI.Binding;
using Game.UI.Widgets;

public class SimpleWidget : IWidget
{
    public PathSegment path { get; set; }

    // Expose a list for visible children; UI framework may read this.
    public IList<IWidget> visibleChildren { get; } = new List<IWidget>();

    // Type name used when serializing properties.
    public string propertiesTypeName { get; } = "SimpleWidgetProperties";

    public WidgetChanges Update()
    {
        // Perform update logic here (layout, state changes, animation, etc.)
        // Return appropriate change mask. Example:
        return WidgetChanges.None;
    }

    public void WriteProperties(IJsonWriter writer)
    {
        // Example JSON serialization. Actual IJsonWriter API may vary.
        writer.WriteStartObject();
        writer.WriteProperty("type", propertiesTypeName);
        // write other properties...
        writer.WriteEndObject();
    }
}

{{ Additional notes }} - IWidget extends IJsonWritable (Colossal.UI.Binding) — ensure your implementation uses the same JSON conventions expected by the surrounding UI tooling. - PathSegment and WidgetChanges are types used by the UI framework; consult their definitions for valid values and semantics. - Keep visibleChildren in sync with your widget's actual children and visibility state so the UI traversal and rendering behave correctly.