Module technology.sola.engine
Class StyleContainer<Style extends BaseStyles>
java.lang.Object
technology.sola.engine.graphics.gui.style.StyleContainer<Style>
- Type Parameters:
Style
- theBaseStyles
type
StyleContainer is a container for
ConditionalStyle
s that apply to a GuiElement
.-
Constructor Summary
ConstructorsConstructorDescriptionStyleContainer
(GuiElement<Style, ?> guiElement) Creates a StyleContainer instance for aGuiElement
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addStyle
(ConditionalStyle<Style> style) Appends anotherConditionalStyle
to the current list of styles.void
addStyles
(List<ConditionalStyle<Style>> styles) Appends aList
ofConditionalStyle
s to the current list of styles.void
addStyles
(List<ConditionalStyle<Style>> styles, boolean prepend) Appends or prepends aList
ofConditionalStyle
s to the current list of styles.<R> @Nullable R
getPropertyValue
(Function<Style, @Nullable R> propertySupplier) Gets the computer property value based on theConditionalStyle
s currently applied to theGuiElement
.<R> @Nullable R
getPropertyValue
(Function<Style, @Nullable R> propertySupplier, @Nullable R defaultValue) Gets the computer property value based on theConditionalStyle
s currently applied to theGuiElement
.boolean
boolean
void
Invalidates the cached condition evaluations if a change has happened.void
removeStyle
(ConditionalStyle<Style> style) Removes all instances ofConditionalStyle
from the current list of styles.final void
setStyles
(List<ConditionalStyle<Style>> styles) Replaces the current internalList
ofConditionalStyle
s 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 internalList
ofConditionalStyle
s with a new one.- Parameters:
styles
- the new list of styles
-
addStyle
Appends anotherConditionalStyle
to the current list of styles.- Parameters:
style
- the new style to add
-
addStyles
Appends aList
ofConditionalStyle
s to the current list of styles.- Parameters:
styles
- the styles to add
-
addStyles
Appends or prepends aList
ofConditionalStyle
s to the current list of styles.- Parameters:
styles
- the styles to addprepend
- whether to prepend the styles or not
-
removeStyle
Removes all instances ofConditionalStyle
from the current list of styles.- Parameters:
style
- the style to remove
-
getPropertyValue
Gets the computer property value based on theConditionalStyle
s 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 fromBaseStyles
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 theConditionalStyle
s 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 fromBaseStyles
classesdefaultValue
- 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 theConditionalStyle
s 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 fromBaseStyles
classesdefaultValue
- 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
-