CycleButtonState

class CycleButtonState<T : Any>(values: List<T>, initialValue: T)(source)

Caller-owned selected value and display conversion for one generic CycleButton.

The immutable nonempty option snapshot defines forward and backward wraparound order. Every value must be unique by equality, and writes outside the option set fail without mutation. The primary list constructor uses Any.toString, while the collection constructor and enum factory retain their supplied conversion for the state lifetime. Selection, observation, and display conversion are confined to the thread that creates the state. The display conversion runs synchronously when called directly or when a CycleButton snapshots its labels, is not used for option identity, and propagates its exceptions unchanged.

Parameters

values

nonempty unique option order.

initialValue

initially selected member of values.

Type Parameters

T

immutable option type.

Throws

when values is empty or contains equal members, or when initialValue is outside values.

Constructors

Link copied to clipboard
constructor(values: List<T>, initialValue: T)
constructor(values: Collection<T>, initialValue: T, toString: (T) -> String)

Creates state from one caller-owned collection snapshot and explicit display conversion.

constructor(values: List<T>)

Creates state selecting the first member of a validated nonempty values list.

Types

Link copied to clipboard
object Companion

Type-specific state factories.

Properties

Link copied to clipboard
var value: T

Current selected option.

Link copied to clipboard
val values: List<T>

Functions

Link copied to clipboard
fun format(value: T): String

Formats one option through the conversion supplied at construction.

Link copied to clipboard
fun next(): T

Selects and returns the next option with wraparound.

Link copied to clipboard

Installs one privileged retained observer.

Link copied to clipboard
fun previous(): T

Selects and returns the previous option with wraparound.