Class ContainingComponent
-
- All Implemented Interfaces:
-
kotlin.Cloneable
public abstract class ContainingComponent extends Component
This component is used to contain other components.
You need to implement the render functions as usual (ensure to call super!), and you will need to place the components yourself either in calculateSize or calculateBounds, depending on your needs (if it always infers its size, pass
nullto size and use calculateSize).This is used for situations where there is a component with multiple parts, for example Button which contains two images and a text as well as itself. It allows for them to share rotation, skew, etc.
- Since:
0.17.4
-
-
Field Summary
Fields Modifier and Type Field Description private final ArrayList<Component>childrenprivate final Propertiespropertiesprivate transient PolyColor.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 ContainingComponent(Properties properties, Vec2<Unit> at, Vec2<Unit> size, Boolean rawResize, Boolean acceptInput, Array<out Component> children, Function1<EventDSL<ContainingComponent>, Unit> events)
-
Method Summary
Modifier and Type Method Description final ArrayList<Component>getChildren()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. final UnitaddComponents(Component component)Add components to this containing component. final UnitremoveComponents(Component component)UnitpreRender(Long deltaTimeNanos)pre-render functions, such as applying transforms. Unitrender()Render the children of this component. Unitreset()Use this function to reset your drawable's PolyText if it is using one. UnitdebugRender()add a debug render overlay for this drawable. Unitsetup(Renderer renderer, PolyUI polyUI)give this a renderer reference and a PolyUI reference. Unitrescale(Float scaleX, Float scaleY)Method that is called when the physical size of the total window area changes. BooleanrecolorRecolorsAll()Set this to truefor the recolor function to act as recolorAll.Unitrecolor(PolyColor toColor, Animation.Type animation, Long durationNanos, Function1<Component, Unit> onFinish)Changes the color of the component to the specified color. final UnitrecolorAll(PolyColor toColor, Animation.Type animation, Long durationNanos, Function1<Component, Unit> onFinish)UnitcalculateChildBounds()UnitcalculateBounds()Calculate the position and size of this drawable. BooleanisInside(Float x, Float y)UnitclipDrawables()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. UnitonParentInitComplete()This function is called when initialization of this parent is complete. -
Methods inherited from class org.polyfrost.polyui.component.Component
accept, addKeyframes, addOperation, canBeRemoved, draggable, every, getColor, getConsumesHover, getDisabled, getLayout, getParent, getProperties, getSize, setColor, setConsumesHover, setDisabled, setLayout, setParent, setProperties, setSize, toString, wantRedraw -
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, moveBy, moveTo, onInitComplete, postRender, removeOperation, 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
-
-
Method Detail
-
getChildren
final ArrayList<Component> getChildren()
-
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.
-
addComponents
final Unit addComponents(Component component)
Add components to this containing component.
- Since:
0.19.0
-
removeComponents
final Unit removeComponents(Component component)
-
preRender
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.
-
render
@MustBeInvokedByOverriders() Unit render()
Render the children of this component.
you must call super.render()!
-
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.
-
setup
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.
-
rescale
Unit rescale(Float scaleX, Float scaleY)
Method that is called when the physical size of the total window area changes.
-
recolorRecolorsAll
Boolean recolorRecolorsAll()
Set this to
truefor the recolor function to act as recolorAll.- Since:
0.21.4
-
recolor
Unit recolor(PolyColor 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.- Since:
0.19.1
-
recolorAll
final Unit recolorAll(PolyColor toColor, Animation.Type animation, Long durationNanos, Function1<Component, Unit> onFinish)
-
calculateChildBounds
Unit calculateChildBounds()
-
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.
-
isInside
Boolean isInside(Float x, Float y)
- Returns:
trueif the given point is inside this drawable.
-
clipDrawables
Unit clipDrawables()
-
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!
- Since:
0.17.5
-
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!
- Since:
0.22.0
-
onParentInitComplete
Unit onParentInitComplete()
This function is called when initialization of this parent is complete.
This function is called once, and only once.
- Since:
0.19.0
-
-
-
-