Class SimpleKeyedFocusModel<K>

java.lang.Object
io.github.cottonmc.cotton.gui.widget.focus.SimpleKeyedFocusModel<K>
Type Parameters:
K - the focus key type
All Implemented Interfaces:
FocusModel<K>

public final class SimpleKeyedFocusModel<K> extends Object implements FocusModel<K>
A FocusModel implementation that wraps a List of foci. New instances can be created with the constructor or the builder.
Since:
7.0.0
  • Constructor Details

    • SimpleKeyedFocusModel

      public SimpleKeyedFocusModel(List<Focus<K>> foci)
      Constructs a keyed focus model.
      Parameters:
      foci - the foci
      Throws:
      IllegalArgumentException - if there are duplicate keys
  • Method Details

    • getFocusedKey

      @Nullable public K getFocusedKey()
      Returns the focused key, or null if not available.
      Returns:
      the focused key, or null if not available
    • isFocused

      public boolean isFocused(Focus<K> focus)
      Description copied from interface: FocusModel
      Checks if a focus is focused in the target widget. If the target widget is not focused itself, none of its foci should have focus.
      Specified by:
      isFocused in interface FocusModel<K>
      Parameters:
      focus - the focus to check
      Returns:
      true if the focus is focused, false otherwise
    • setFocused

      public void setFocused(Focus<K> focus)
      Description copied from interface: FocusModel
      Applies a focus to the target widget.

      This method does not need to request the GUI's focus for the widget; that is the responsibility of the caller.

      Specified by:
      setFocused in interface FocusModel<K>
      Parameters:
      focus - the focus
    • foci

      public Stream<Focus<K>> foci()
      Description copied from interface: FocusModel
      Returns a stream of all foci in the target widget.
      Specified by:
      foci in interface FocusModel<K>
      Returns:
      a stream of all foci in the target widget
    • builder

      @Contract("-> new") public static <K> SimpleKeyedFocusModel.Builder<K> builder()
      Creates a builder for SimpleKeyedFocusModel.
      Type Parameters:
      K - the focus key type
      Returns:
      the builder