Game.UI.Widgets.FlexLayout
Assembly:
Assembly-CSharp (typical for game mod types; actual assembly may vary)
Namespace: Game.UI.Widgets
Type: struct (value type)
Base: System.ValueType
Implements: Colossal.UI.Binding.IJsonWritable
Summary:
Represents flexbox-like layout properties for UI widgets: grow, shrink and basis. Used to control how a UI element expands or contracts within a flexible container. The struct provides two convenient static presets (Default and Fill) and can serialize itself to a JSON writer via the IJsonWritable implementation.
Fields
None (no explicit instance fields; uses auto-implemented properties)
This struct exposes its data through public auto-properties (grow, shrink, basis). There are also two static convenience properties (Default and Fill).
Properties
-
public static FlexLayout Default { get; }
Returns a FlexLayout preset equivalent to new FlexLayout(0f, 1f, -1). Typical for elements that do not grow but can shrink, with an unspecified basis. -
public static FlexLayout Fill { get; }
Returns a FlexLayout preset equivalent to new FlexLayout(1f, 0f, 0). Typical for elements that should fill available space. -
public float grow { get; set; }
Flex grow factor: relative proportion of extra space the element should take when container has additional room. -
public float shrink { get; set; }
Flex shrink factor: relative proportion the element should shrink when container has insufficient space. -
public int basis { get; set; }
Flex basis (in pixels). A value of -1 commonly indicates "auto" or unspecified basis; non-negative values set a fixed basis.
Constructors
public FlexLayout(float grow, float shrink, int basis)
Creates a new FlexLayout with the provided grow, shrink and basis values.
Example behavior: - grow = 0, shrink = 1, basis = -1 => Default preset - grow = 1, shrink = 0, basis = 0 => Fill preset
Methods
public void Write(IJsonWriter writer)
: System.Void
Serializes this FlexLayout to the provided IJsonWriter. The implementation writes a type wrapper using the struct's full type name, then writes three properties in order: "grow", "shrink", and "basis", writing their current values, and closes the type wrapper.
Serialization sequence: 1. writer.TypeBegin(GetType().FullName) 2. writer.PropertyName("grow"); writer.Write(grow) 3. writer.PropertyName("shrink"); writer.Write(shrink) 4. writer.PropertyName("basis"); writer.Write(basis) 5. writer.TypeEnd()
This makes the struct compatible with Colossal UI's JSON-based persistence/transport mechanisms.
Usage Example
// Create using presets
var a = FlexLayout.Default; // grow=0, shrink=1, basis=-1
var b = FlexLayout.Fill; // grow=1, shrink=0, basis=0
// Create custom
var custom = new FlexLayout(0.5f, 0.5f, 100);
// Example of writing to an IJsonWriter (pseudocode: depends on actual writer implementation)
IJsonWriter writer = GetJsonWriter();
custom.Write(writer);
Notes and tips: - Values are mutable (properties have public setters); if you need an immutable pattern, avoid changing instances after creation. - Commonly used in layout containers that implement flex-like behavior; interpret basis values according to the UI framework conventions (often -1 = auto). - Ensure the IJsonWriter passed to Write is the one provided by the Colossal UI binding/persistence system used in the mod environment.