Class Component
-
- All Implemented Interfaces:
-
kotlin.Cloneable
public abstract class Component extends Drawable
A component is a drawable object that can be interacted with. <br>
It has a properties attached to it, which contains various pieces of information about how this component should look, and its default responses to event.
-
-
Field Summary
Fields Modifier and Type Field Description private final Propertiespropertiesprivate transient Color.Animatedcolorprivate transient Drawableparentprivate transient Layoutlayoutprivate transient BooleanconsumesHoverprivate Booleandisabledprivate Vec2<Unit>sizeprivate final transient HashMap<Event, Function2<Drawable, Event, Boolean>>eventHandlersprivate transient StringsimpleNameprivate transient Rendererrendererprivate transient PolyUIpolyUIprivate BooleanacceptsInputprivate final transient ByteinitStageprivate final transient BooleanmouseOverprivate Booleanrendersprivate Floatxprivate Floatyprivate Floatwidthprivate Floatheightprivate Booleanexistsprivate transient FloattrueXprivate transient FloattrueYprivate final Unit.TypeatTypeprivate final Unit.TypesizeTypeprivate final BooleanisDynamicprivate Doublerotationprivate DoubleskewXprivate DoubleskewYprivate FloatscaleXprivate FloatscaleYprivate Floatalphaprivate transient Floatacxprivate transient Floatacyprivate final Vec2<Unit>atprivate final BooleanrawResize
-
Constructor Summary
Constructors Constructor Description Component(Properties properties, Vec2<Unit> at, Vec2<Unit> size, Boolean rawResize, Boolean acceptInput, Function1<EventDSL<Component>, Unit> events)Component(Properties properties, Vec2<Unit> at, Vec2<Unit> size, Boolean rawResize, Boolean acceptInput)Component(Properties properties, Vec2<Unit> at, Vec2<Unit> size, Boolean rawResize)Component(Properties properties, Vec2<Unit> at, Vec2<Unit> size)Component(Properties properties, Vec2<Unit> at)Component(Vec2<Unit> at)
-
Method Summary
Modifier and Type Method Description PropertiesgetProperties()final Color.AnimatedgetColor()the color of this component. final UnitsetColor(Color.Animated color)the color of this component. final DrawablegetParent()This is a reference to the parent of this component. final UnitsetParent(@ApiStatus.Internal() Drawable parent)This is a reference to the parent of this component. LayoutgetLayout()Reference to the layout encapsulating this drawable. UnitsetLayout(Layout layout)Reference to the layout encapsulating this drawable. BooleangetConsumesHover()If this is true, the drawable will be the only drawable that is allowed to be hovered at once.UnitsetConsumesHover(Boolean consumesHover)If this is true, the drawable will be the only drawable that is allowed to be hovered at once.final BooleangetDisabled()Disabled flag for this component. final UnitsetDisabled(Boolean disabled)Vec2<Unit>getSize()size of this drawable. UnitsetSize(Vec2<Unit> size)size of this drawable. FloattrueX()Note that this method will return the x if this method is called before the component is added to a layout. FloattrueY()Note that this method will return the y if this method is called before the component is added to a layout. Booleanaccept(Event event)called when this drawable receives an event. Unitrecolor(Color toColor, Animation.Type animation, Long durationNanos, Function1<Component, Unit> onFinish)Changes the color of the component to the specified color. UnitonColorsChanged(Colors colors)Function that is called when the colors attached to this drawable change. UnitonFontsChanged(FontFamily fonts)Function that is called when the fonts attached to this drawable change. UnitcalculateBounds()Calculate the position and size of this drawable. UnitaddOperation(DrawableOp drawableOp, Function1<Drawable, Unit> onFinish)Add a DrawableOp to this drawable. final UnitsetProperties(Properties properties)change the properties attached to this component. Unitsetup(Renderer renderer, PolyUI polyUI)give this a renderer reference and a PolyUI reference. UnitpreRender(Long deltaTimeNanos)pre-render functions, such as applying transforms. UnitdebugRender()add a debug render overlay for this drawable. BooleancanBeRemoved()function that should return true if it is ready to be removed from its parent. StringtoString()final Componentdraggable(Boolean consumesEvent)Make this component draggable. final UnitaddKeyframes(KeyFrames k)final Componentevery(Long nanos, Integer repeats, Function1<Component, Unit> func)add a function that is called every nanos nanoseconds. final UnitwantRedraw()-
Methods inherited from class org.polyfrost.polyui.component.Drawable
addEventHandler, addEventhandler, animateBy, animateTo, calculateSize, clone, debugPrint, doDynamicSize, events, fadeBy, fadeTo, getAcceptsInput, getAcx, getAcy, getAlpha, getAt, getAtType, getContainingLayout, getEventHandlers, getExists, getHeight, getInitStage, getMouseOver, getPolyUI, getRawResize, getRenderer, getRenders, getRotation, getScaleX, getScaleY, getSimpleName, getSizeType, getSkewX, getSkewY, getTrueX, getTrueY, getWidth, getX, getY, intersects, isDynamic, isInside, isInside, moveBy, moveTo, onInitComplete, onParentInitComplete, postRender, removeOperation, render, rescale, reset, resize, rotateBy, rotateTo, scaleBy, scaleTo, setAcceptsInput, setAcx, setAcy, setAlpha, setExists, setHeight, setPolyUI, setRenderer, setRenders, setRotation, setScaleX, setScaleY, setSimpleName, setSkewX, setSkewY, setTrueX, setTrueY, setWidth, setX, setY, skewBy, skewTo -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
Component
Component(Properties properties, Vec2<Unit> at, Vec2<Unit> size, Boolean rawResize, Boolean acceptInput, Function1<EventDSL<Component>, Unit> events)
-
Component
Component(Properties properties, Vec2<Unit> at, Vec2<Unit> size, Boolean rawResize, Boolean acceptInput)
-
Component
Component(Properties properties, Vec2<Unit> at, Vec2<Unit> size)
-
Component
Component(Properties properties, Vec2<Unit> at)
-
-
Method Detail
-
getProperties
Properties getProperties()
-
getColor
final Color.Animated getColor()
the color of this component.
-
setColor
final Unit setColor(Color.Animated color)
the color of this component.
-
getParent
final Drawable getParent()
This is a reference to the parent of this component. It is currently only used by trueX and trueY.
Controlled by ContainingComponent
-
setParent
final Unit setParent(@ApiStatus.Internal() Drawable parent)
This is a reference to the parent of this component. It is currently only used by trueX and trueY.
Controlled by ContainingComponent
-
getLayout
Layout getLayout()
Reference to the layout encapsulating this drawable. For components, this is never null, but for layout, it can be null (meaning its parent is the polyui).
In pretty much every situation it is safe to
!!this, as any layout you create will have parent of PolyUI.master. If you are doingthis.layout.layoutor deeper, you should null-check.
-
setLayout
Unit setLayout(Layout layout)
Reference to the layout encapsulating this drawable. For components, this is never null, but for layout, it can be null (meaning its parent is the polyui).
In pretty much every situation it is safe to
!!this, as any layout you create will have parent of PolyUI.master. If you are doingthis.layout.layoutor deeper, you should null-check.
-
getConsumesHover
Boolean getConsumesHover()
If this is
true, the drawable will be the only drawable that is allowed to be hovered at once.There are essentially two modes for hovering in PolyUI, and by default, components are in the "normal" (
false) mode, where only one of them can be hovered as once as would be expected, but layouts are in the "group" (true) mode, so will still receive the events even if another drawable is hovered, for example scrolling.
-
setConsumesHover
Unit setConsumesHover(Boolean consumesHover)
If this is
true, the drawable will be the only drawable that is allowed to be hovered at once.There are essentially two modes for hovering in PolyUI, and by default, components are in the "normal" (
false) mode, where only one of them can be hovered as once as would be expected, but layouts are in the "group" (true) mode, so will still receive the events even if another drawable is hovered, for example scrolling.
-
getDisabled
final Boolean getDisabled()
Disabled flag for this component. Dispatches the Disabled and Enabled events by default, leaving it to the Properties implementation to handle the disabled state.
-
setDisabled
final Unit setDisabled(Boolean disabled)
-
trueX
Float trueX()
Note that this method will return the x if this method is called before the component is added to a layout.
-
trueY
Float trueY()
Note that this method will return the y if this method is called before the component is added to a layout.
-
accept
Boolean accept(Event event)
called when this drawable receives an event.
make sure to call super.accept()!
-
recolor
Unit recolor(Color toColor, Animation.Type animation, Long durationNanos, Function1<Component, Unit> onFinish)
Changes the color of the component to the specified color. Supports animation and callback function on finish.
If the color is a Color.Gradient, this component's color will be changed to a gradient between the current color and the specified color.
If the color is a Color.Chroma, this component's color will be changed to a chroma color, keeping its current hue for consistency. Note: This will look wierd if the current color is a gradient, and the brightness, saturation and alpha are NOT animated, so will change instantly.
- Parameters:
toColor- The color to change the component to.animation- The type of animation to use.durationNanos- The duration of the animation in nanoseconds.onFinish- The callback function to execute when the color change animation finishes.
-
onColorsChanged
Unit onColorsChanged(Colors colors)
Function that is called when the colors attached to this drawable change.
If this is a layout, the colors will change, and all its children and components will be notified and updated accordingly.
Make sure to call super.onColorsChanged() if you override this!
-
onFontsChanged
Unit onFontsChanged(FontFamily fonts)
Function that is called when the fonts attached to this drawable change.
If this is a layout, the fonts will change, and all its children and components will be notified and updated accordingly.
Make sure to call super.onFontsChanged() if you override this!
-
calculateBounds
Unit calculateBounds()
Calculate the position and size of this drawable. Make sure to call doDynamicSize in this method to avoid issues with sizing.
This method is called once the layout is populated for children and component, and when a recalculation is requested.
The value of layout's bounds will be updated after this method is called, so do not use layout's bounds as an updated value in this method.
-
addOperation
Unit addOperation(DrawableOp drawableOp, Function1<Drawable, Unit> onFinish)
Add a DrawableOp to this drawable.
-
setProperties
final Unit setProperties(Properties properties)
change the properties attached to this component.
-
setup
@MustBeInvokedByOverriders() Unit setup(Renderer renderer, PolyUI polyUI)
give this a renderer reference and a PolyUI reference.
You can also use this method to do some calculations (such as text widths) that are not dependent on other sizes.
If you need a method that has access to component's sizes, see here or here (if you are operating on yourself only).
this method is called once, and only once.
-
preRender
@MustBeInvokedByOverriders() Unit preRender(Long deltaTimeNanos)
pre-render functions, such as applying transforms. In this method, you should set needsRedraw to true if you have something to redraw for the next frame.
- Parameters:
deltaTimeNanos- the time in nanoseconds since the last frame.
-
debugRender
Unit debugRender()
add a debug render overlay for this drawable. This is always rendered regardless of the layout re-rendering if debug mode is on.
-
canBeRemoved
Boolean canBeRemoved()
function that should return true if it is ready to be removed from its parent.
This is used for drawables that need to wait for an animation to finish before being removed.
-
draggable
final Component draggable(Boolean consumesEvent)
Make this component draggable.
- Parameters:
consumesEvent- weather beginning/ending dragging should cancel the corresponding mouse event
-
addKeyframes
final Unit addKeyframes(KeyFrames k)
-
every
final Component every(Long nanos, Integer repeats, Function1<Component, Unit> func)
add a function that is called every nanos nanoseconds.
-
wantRedraw
final Unit wantRedraw()
-
-
-
-