Module technology.sola.engine
Class StyleContainer<Style extends BaseStyles>
java.lang.Object
technology.sola.engine.graphics.gui.style.StyleContainer<Style>
- Type Parameters:
Style- theBaseStylestype
StyleContainer is a container for
ConditionalStyles that apply to a GuiElement.-
Constructor Summary
ConstructorsConstructorDescriptionStyleContainer(GuiElement<Style, ?> guiElement) Creates a StyleContainer instance for aGuiElement. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddStyle(ConditionalStyle<Style> style) Appends anotherConditionalStyleto the current list of styles.voidaddStyles(List<ConditionalStyle<Style>> styles) Appends aListofConditionalStyles to the current list of styles.voidaddStyles(List<ConditionalStyle<Style>> styles, boolean prepend) Appends or prepends aListofConditionalStyles to the current list of styles.<R> @Nullable RgetPropertyValue(Function<Style, @Nullable R> propertySupplier) Gets the computer property value based on theConditionalStyles currently applied to theGuiElement.<R> @Nullable RgetPropertyValue(Function<Style, @Nullable R> propertySupplier, @Nullable R defaultValue) Gets the computer property value based on theConditionalStyles currently applied to theGuiElement.booleanbooleanvoidInvalidates the cached condition evaluations if a change has happened.voidremoveStyle(ConditionalStyle<Style> style) Removes all instances ofConditionalStylefrom the current list of styles.final voidsetStyles(List<ConditionalStyle<Style>> styles) Replaces the current internalListofConditionalStyles with a new one.
-
Constructor Details
-
StyleContainer
Creates a StyleContainer instance for aGuiElement.- Parameters:
guiElement- the gui element
-
-
Method Details
-
invalidate
public void invalidate()Invalidates the cached condition evaluations if a change has happened. -
setStyles
Replaces the current internalListofConditionalStyles with a new one.- Parameters:
styles- the new list of styles
-
addStyle
Appends anotherConditionalStyleto the current list of styles.- Parameters:
style- the new style to add
-
addStyles
Appends aListofConditionalStyles to the current list of styles.- Parameters:
styles- the styles to add
-
addStyles
Appends or prepends aListofConditionalStyles to the current list of styles.- Parameters:
styles- the styles to addprepend- whether to prepend the styles or not
-
removeStyle
Removes all instances ofConditionalStylefrom the current list of styles.- Parameters:
style- the style to remove
-
getPropertyValue
Gets the computer property value based on theConditionalStyles currently applied to theGuiElement. 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 fromBaseStylesclasses- 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 theConditionalStyles currently applied to theGuiElement. 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 fromBaseStylesclassesdefaultValue- 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 theConditionalStyles currently applied to theGuiElement. 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 theirMergeableProperty.mergeWith(MergeableProperty)definition.- Type Parameters:
R- the return value type- Parameters:
propertySupplier- the method that supplies the property fromBaseStylesclassesdefaultValue- 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
-