Class Cycle.Builder<T>

java.lang.Object
dev.xichil.mvui.Entry.Builder<Cycle.Builder<T>>
dev.xichil.mvui.Cycle.Builder<T>
Type Parameters:
T - the value type
Enclosing class:
Cycle<T>

public static final class Cycle.Builder<T> extends Entry.Builder<Cycle.Builder<T>>
Builds a Cycle; from Cycle.builder(String). Also has the options every entry has (Entry.Builder).
  • Method Details

    • label

      public Cycle.Builder<T> label(Supplier<Text> label)
      The text before ": value", re-read on every refresh. Required.
      Parameters:
      label - read on refresh
      Returns:
      this builder
    • label

      public Cycle.Builder<T> label(Text label)
      A fixed label; see label(Supplier).
      Parameters:
      label - the label
      Returns:
      this builder
    • values

      public Cycle.Builder<T> values(List<T> values)
      The values to step through, in order. Required, not empty. Copied at build time; later changes to the list don't show. For an enum: Arrays.asList(MyEnum.values()).
      Parameters:
      values - the values; must implement Object.equals(Object) consistently
      Returns:
      this builder
    • value

      public Cycle.Builder<T> value(Supplier<T> value)
      Reads the mod's current value; re-read on every refresh. Required. If it returns something not in values, the cycle shows the first value (and the next click selects the second).
      Parameters:
      value - reads the current value
      Returns:
      this builder
    • valueText

      public Cycle.Builder<T> valueText(Function<? super T, Text> valueText)
      How a value is shown after "label: ". Required. Use translatable text for enum constants, e.g. m -> Text.translatable("mymod.mode." + m.key, m.englishName).
      Parameters:
      valueText - maps a value to its text; never returns null
      Returns:
      this builder
    • onChange

      public Cycle.Builder<T> onChange(Consumer<? super T> onChange)
      Stores the newly selected value; runs on the main thread. Required. The button shows the new value only if value returns it afterwards.
      Parameters:
      onChange - receives the selected value
      Returns:
      this builder
    • build

      public Cycle<T> build()
      Builds the cycle.
      Returns:
      the cycle
      Throws:
      IllegalStateException - if a required field is missing or values is empty