Class StyleContainer<Style extends BaseStyles>

java.lang.Object
technology.sola.engine.graphics.gui.style.StyleContainer<Style>
Type Parameters:
Style - the BaseStyles type

@NullMarked public class StyleContainer<Style extends BaseStyles> extends Object
StyleContainer is a container for ConditionalStyles that apply to a GuiElement.
  • Constructor Details

    • StyleContainer

      public StyleContainer(GuiElement<Style,?> guiElement)
      Creates a StyleContainer instance for a GuiElement.
      Parameters:
      guiElement - the gui element
  • Method Details

    • invalidate

      public void invalidate()
      Invalidates the cached condition evaluations if a change has happened.
    • setStyles

      public final void setStyles(List<ConditionalStyle<Style>> styles)
      Replaces the current internal List of ConditionalStyles with a new one.
      Parameters:
      styles - the new list of styles
    • addStyle

      public void addStyle(ConditionalStyle<Style> style)
      Appends another ConditionalStyle to the current list of styles.
      Parameters:
      style - the new style to add
    • addStyles

      public void addStyles(List<ConditionalStyle<Style>> styles)
      Appends a List of ConditionalStyles to the current list of styles.
      Parameters:
      styles - the styles to add
    • addStyles

      public void addStyles(List<ConditionalStyle<Style>> styles, boolean prepend)
      Appends or prepends a List of ConditionalStyles to the current list of styles.
      Parameters:
      styles - the styles to add
      prepend - whether to prepend the styles or not
    • removeStyle

      public void removeStyle(ConditionalStyle<Style> style)
      Removes all instances of ConditionalStyle from the current list of styles.
      Parameters:
      style - the style to remove
    • getPropertyValue

      public <R> @Nullable R getPropertyValue(Function<Style,@Nullable R> propertySupplier)
      Gets the computer property value based on the ConditionalStyles currently applied to the GuiElement. If no value is present in any of the styles then null is returned.
      Type Parameters:
      R - the return value type
      Parameters:
      propertySupplier - the method that supplies the property from BaseStyles classes
      Returns:
      the calculated style or null
    • getPropertyValue

      public <R> @Nullable R getPropertyValue(Function<Style,@Nullable R> propertySupplier, @Nullable R defaultValue)
      Gets the computer property value based on the ConditionalStyles currently applied to the GuiElement. If no value is present in any of the styles then the default value is returned.
      Type Parameters:
      R - the return value type
      Parameters:
      propertySupplier - the method that supplies the property from BaseStyles classes
      defaultValue - the default value to return if no style provides a value
      Returns:
      the calculated style or default value
    • getPropertyValue

      public <R extends MergeableProperty<R>> @Nullable R getPropertyValue(Function<Style,@Nullable R> propertySupplier, @Nullable R defaultValue)
      Gets the computer property value based on the ConditionalStyles currently applied to the GuiElement. If no value is present in any of the styles then the default value is returned. Properties defined in multiple styles will be merged based on their MergeableProperty.mergeWith(MergeableProperty) definition.
      Type Parameters:
      R - the return value type
      Parameters:
      propertySupplier - the method that supplies the property from BaseStyles classes
      defaultValue - the default value to return if no style provides a value
      Returns:
      the calculated style or default value
    • hasHoverCondition

      public boolean hasHoverCondition()
      Returns:
      true if any of the styles contain a GuiElement.isHovered() condition
    • hasActiveCondition

      public boolean hasActiveCondition()
      Returns:
      true if any of the styles contain a GuiElement.isActive() condition