Class Component
-
- All Implemented Interfaces:
public abstract class ComponentComponent is the base class of everything on the screen in PolyUI.
It itself contains no actual draw methods.
- Since:
1.6.0
-
-
Field Summary
Fields Modifier and Type Field Description private Stringnameprivate final PolyUIpolyUIprivate final Booleaninitializedprivate final ArrayList<Component>childrenprivate Component_parentprivate Componentparentprivate Floatxprivate Floatyprivate Vec2atprivate final Vec2screenAtprivate Floatwidthprivate Floatheightprivate Vec2sizeprivate final BooleansizeValidprivate final Vec2visibleSizeprivate Vec4paddingprivate BytelayoutFlagsprivate BooleanrawResizeprivate BooleanlayoutIgnoredprivate final BooleancreatedWithSetPositionprivate final BooleancreatedWithSetSizeprivate final Booleanpositionedprivate Booleanrendersprivate BooleanisEnabledprivate final ArrayList<ComponentOp>operationsprivate final BooleanisOperatingprivate final Alignalignment
-
Method Summary
Modifier and Type Method Description StringgetName()This is the name of this component, and you can use it to get components from a layout by ID, e. UnitsetName(String name)This is the name of this component, and you can use it to get components from a layout by ID, e. final PolyUIgetPolyUI()final BooleangetInitialized()final ArrayList<Component>getChildren()final ComponentgetParentOrNull()final Unitset_parent(@ApiStatus.Internal() Component _parent)final ComponentgetParent()final UnitsetParent(@SideEffects(values = {"_parent"}) Component parent)final FloatgetX()final UnitsetX(@SideEffects(values = {"x", "_x", "atValid", "this.children::x"}, when = "value != x") Float x)final FloatgetY()final UnitsetY(@SideEffects(values = {"y", "_y", "atValid", "this.children::y"}, when = "value != y") Float y)final Vec2getAt()final UnitsetAt(Vec2 at)Vec2getScreenAt()FloatgetWidth()UnitsetWidth(Float width)FloatgetHeight()UnitsetHeight(Float height)final Vec2getSize()final UnitsetSize(Vec2 size)final BooleanisSizeValid()Vec2getVisibleSize()final Vec4getPadding()final UnitsetPadding(Vec4 padding)final BytegetLayoutFlags()Flags that store various states of this component regarding the org.polyfrost.polyui.layout.LayoutController and resizing. final UnitsetLayoutFlags(@ApiStatus.Internal() Byte layoutFlags)Flags that store various states of this component regarding the org.polyfrost.polyui.layout.LayoutController and resizing. final BooleanisRawResize()final UnitsetRawResize(Boolean rawResize)final BooleanisLayoutIgnored()final UnitsetLayoutIgnored(Boolean layoutIgnored)final BooleancreatedWithSetPosition()final BooleancreatedWithSetSize()final BooleanisPositioned()BooleangetRenders()Whether this component should be rendered. UnitsetRenders(Boolean renders)BooleanisEnabled()Disabled flag for this component. UnitsetEnabled(Boolean isEnabled)Disabled flag for this component. final ArrayList<ComponentOp>getOperations()final BooleanisOperating()final AligngetAlignment()final Unitat(Integer index, Float value)Set the position of this component programmatically. Vec2calculateSize()Use this function to calculate the size of this component. final Unitsize(Integer index, Float value)Set the size of this component programmatically. UnitfixVisibleSize()Booleansetup(PolyUI polyUI)give this a PolyUI reference. final Unitrescale(Float scaleX, Float scaleY)Method that is called when the physical size of the total window area changes. Unitrescale0(Float scaleX, Float scaleY, Boolean withChildren)raw rescale method that does not check rawResize and uses the given scale factors directly. final UnitclipChildren()final BooleanisInside(Float x, Float y)final Booleancontains(Vec2 point)final Booleancontains(Vec4 box)final Booleanintersects(Float x, Float y, Float width, Float height)Unitposition()Reposition all the children of this component. Unitrecalculate()Fully recalculate this component's size, and any of its children's positions. Componentget(Integer index)final Componentget(String id)final Componentget(Float x, Float y)final Unitset(Integer old, Component new)final Unitset(Component old, Component new)Replace a child of this component with another component. final UnitaddChild(Component child, Boolean recalculate)the runtime equivalent of adding children to this component during the constructor. final UnitaddChild(Component children)final UnitremoveChild(Component child, Boolean recalculate)final UnitremoveChild(Integer index, Boolean recalculate)final Unitremove(Boolean recalculate)Remove this component from its parent. StringdebugString()Override this function to add things to the debug display of this component. final BooleanaddOperation(ComponentOp operation)Add a ComponentOp to this component. final UnitaddOperation(ComponentOp operations)final UnitremoveOperation(ComponentOp componentOp)Remove an operation from this drawable. StringextraToString()Supply extra information to the toString representation of this object. StringtoString()-
-
Method Detail
-
getName
String getName()
This is the name of this component, and you can use it to get components from a layout by ID, e.g:
val text = myLayout["Text@4cf777e8"] as Text
-
setName
Unit setName(String name)
This is the name of this component, and you can use it to get components from a layout by ID, e.g:
val text = myLayout["Text@4cf777e8"] as Text
-
getInitialized
final Boolean getInitialized()
-
getChildren
final ArrayList<Component> getChildren()
-
getParentOrNull
final Component getParentOrNull()
-
set_parent
final Unit set_parent(@ApiStatus.Internal() Component _parent)
-
setParent
final Unit setParent(@SideEffects(values = {"_parent"}) Component parent)
-
setX
final Unit setX(@SideEffects(values = {"x", "_x", "atValid", "this.children::x"}, when = "value != x") Float x)
-
setY
final Unit setY(@SideEffects(values = {"y", "_y", "atValid", "this.children::y"}, when = "value != y") Float y)
-
getScreenAt
Vec2 getScreenAt()
-
isSizeValid
final Boolean isSizeValid()
-
getVisibleSize
Vec2 getVisibleSize()
-
getPadding
final Vec4 getPadding()
-
setPadding
final Unit setPadding(Vec4 padding)
-
getLayoutFlags
final Byte getLayoutFlags()
Flags that store various states of this component regarding the org.polyfrost.polyui.layout.LayoutController and resizing. Currently, the following is stored here:
bit 0: rawResize
bit 1: createdWithSetSize
bit 2: createdWithSetPosition
bit 3: layoutIgnored
this means there are still 4 bits that can be used for simple boolean-type properties. this is protected so you can use it yourself, but more bits may be used internally in the future. In order to maintain forward compatability, you should use the highest indexes for your flags.
- Since:
1.4.4
-
setLayoutFlags
final Unit setLayoutFlags(@ApiStatus.Internal() Byte layoutFlags)
Flags that store various states of this component regarding the org.polyfrost.polyui.layout.LayoutController and resizing. Currently, the following is stored here:
bit 0: rawResize
bit 1: createdWithSetSize
bit 2: createdWithSetPosition
bit 3: layoutIgnored
this means there are still 4 bits that can be used for simple boolean-type properties. this is protected so you can use it yourself, but more bits may be used internally in the future. In order to maintain forward compatability, you should use the highest indexes for your flags.
- Since:
1.4.4
-
isRawResize
final Boolean isRawResize()
-
setRawResize
final Unit setRawResize(Boolean rawResize)
-
isLayoutIgnored
final Boolean isLayoutIgnored()
-
setLayoutIgnored
final Unit setLayoutIgnored(Boolean layoutIgnored)
-
createdWithSetPosition
final Boolean createdWithSetPosition()
-
createdWithSetSize
final Boolean createdWithSetSize()
-
isPositioned
final Boolean isPositioned()
-
getRenders
Boolean getRenders()
Whether this component should be rendered.
This is controlled by clipChildren to save resources by not drawing components which cannot be seen.
- Since:
0.21.4
-
setRenders
Unit setRenders(Boolean renders)
-
isEnabled
Boolean isEnabled()
Disabled flag for this component. Dispatches the Event.Lifetime.Disabled and Event.Lifetime.Enabled events.
- Since:
0.21.4
-
setEnabled
Unit setEnabled(Boolean isEnabled)
Disabled flag for this component. Dispatches the Event.Lifetime.Disabled and Event.Lifetime.Enabled events.
- Since:
0.21.4
-
getOperations
final ArrayList<ComponentOp> getOperations()
-
isOperating
final Boolean isOperating()
-
getAlignment
final Align getAlignment()
-
at
final Unit at(Integer index, Float value)
Set the position of this component programmatically. use this if you don't want to hardcode x or y (for example in mirroring or flipping).
- Since:
1.1.0
-
calculateSize
Vec2 calculateSize()
Use this function to calculate the size of this component. DO NOT include children in this calculation!
This function is only called if no size is supplied to this component at initialization. A return value of
nullindicates this component is not able to infer its own size, as it is for example, a Block with no reference. A component such as Text on the other hand, is able to infer its own size.This function is only ever called if sizeValid is false.
-
size
final Unit size(Integer index, Float value)
Set the size of this component programmatically. use this if you don't want to hardcode width or height (for example in mirroring or flipping).
- Since:
1.5.0
-
fixVisibleSize
Unit fixVisibleSize()
-
setup
@MustBeInvokedByOverriders() Boolean setup(PolyUI polyUI)
give this a PolyUI reference.
You can also use this method to do some calculations (such as text widths) that are not dependent on other sizes, or operations that require access to PolyUI things, like PolyUI.settings or PolyUI.translator
this method is called once, and only once.
-
rescale
@Locking() final Unit rescale(Float scaleX, Float scaleY)
Method that is called when the physical size of the total window area changes.
-
rescale0
@ApiStatus.Internal()@Locking()@MustBeInvokedByOverriders()@Synchronized() Unit rescale0(Float scaleX, Float scaleY, Boolean withChildren)
raw rescale method that does not check rawResize and uses the given scale factors directly.
- Parameters:
withChildren- iftrue, this method will also rescale its children.
-
clipChildren
final Unit clipChildren()
-
isInside
final Boolean isInside(Float x, Float y)
- Returns:
trueif the given point is inside this component.
-
intersects
final Boolean intersects(Float x, Float y, Float width, Float height)
- Returns:
trueif the component has at least one point inside the given box (x, y, width, height).- Since:
0.21.4
-
position
@Locking(when = "this.children != null")@Synchronized() Unit position()
Reposition all the children of this component.
Note that in most circumstances, recalculate is the method that you actually want.
- Since:
1.0.2
-
recalculate
@Locking(when = "this.children != null")@Synchronized() Unit recalculate()
Fully recalculate this component's size, and any of its children's positions.
- Since:
1.0.7
-
set
@Locking()@Synchronized() final Unit set(Component old, Component new)
Replace a child of this component with another component.
This will add a nice, smooth Fade animation to the transition.
- Since:
1.0.1
-
addChild
@Locking()@Synchronized() final Unit addChild(Component child, Boolean recalculate)
the runtime equivalent of adding children to this component during the constructor.
-
removeChild
@Locking() final Unit removeChild(Component child, Boolean recalculate)
-
removeChild
@Locking()@Synchronized() final Unit removeChild(Integer index, Boolean recalculate)
-
debugString
String debugString()
Override this function to add things to the debug display of this component.
- Since:
1.1.1
-
addOperation
@Locking(when = "operation.verify() == true") final Boolean addOperation(ComponentOp operation)
Add a ComponentOp to this component.
- Returns:
trueif the operation was added,falseif it was replaced.
-
addOperation
@Locking() final Unit addOperation(ComponentOp operations)
-
removeOperation
@Locking(when = "operations != null")@Synchronized() final Unit removeOperation(ComponentOp componentOp)
Remove an operation from this drawable.
-
extraToString
String extraToString()
Supply extra information to the toString representation of this object. Keep it short.
- Since:
1.7.1
-
-
-
-