File-By-File
Toggle

Toggle

A Toggle is a rather basic concept - it can be in one of two states: on and off. Whenever the toggle is toggled, it'll follow the following pattern:

  • If it's off, the toggle will turn to on.
  • If it's on, the toggle will turn to off.

Toggles are most useful in loop-based code: if you want to have a stateful component that can be toggled with the press of a button, for example, a toggle would be perfect.

Methods

Toggle(boolean initialState)

Constructs a new Toggle with the specified initial state.

Toggle()

Constructs a new Toggle with an initial state of false.

toggle()

Changes the state of the toggle. If the current state is true, it becomes false, and vice-versa.

getState()

Returns the current boolean state of the toggle.

setState(boolean state)

Overrides or directly sets the state of the toggle to the provided boolean state.