Class Layout
-
- All Implemented Interfaces:
-
kotlin.Cloneable
public abstract class Layout extends Drawable
Layout is PolyUI's take on containers. They can contain components and other layouts, as children.
They can dynamically add and remove their children and components.
They are responsible for all their children's sizes, positions and rendering.
-
-
Field Summary
Fields Modifier and Type Field Description public final static ArrayList<Component>EMPTY_CMPLISTpublic final static ArrayList<Layout>EMPTY_CHLDLISTprivate transient PropertyManagerpropertyManagerprivate final transient Colorscolorsprivate final transient FontFamilyfontsprivate final ArrayList<Component>componentsprivate final ArrayList<Layout>childrenprivate BooleanconsumesHoverprivate transient BooleanneedsRedrawprivate BooleanrefuseFramebufferprivate transient Layoutlayoutprivate final transient ArrayList<Function1<Layout, Unit>>initCompleteHooksprivate final transient Booleandraggableprivate Vec2<Unit>visibleSizeprivate Vec2<Unit>sizeprivate final BooleanresizesChildrenprivate 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
-
Method Summary
Modifier and Type Method Description PropertyManagergetPropertyManager()UnitsetPropertyManager(PropertyManager propertyManager)final ColorsgetColors()final FontFamilygetFonts()final ArrayList<Component>getComponents()final ArrayList<Layout>getChildren()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.BooleangetNeedsRedraw()Weather this layout needs redrawing. UnitsetNeedsRedraw(Boolean needsRedraw)BooleangetRefuseFramebuffer()set this to true if you want this layout to never use a framebuffer. UnitsetRefuseFramebuffer(Boolean refuseFramebuffer)set this to true if you want this layout to never use a framebuffer. final LayoutgetLayout()reference to parent final UnitsetLayout(Layout layout)final ArrayList<Function1<Layout, Unit>>getInitCompleteHooks()These hooks are ran when the onInitComplete function is called. final BooleangetDraggable()Flag that is true if the layout can be dragged around. final Vec2<Unit>getVisibleSize()The visible area of this layout. final UnitsetVisibleSize(Vec2<Unit> visibleSize)The visible area of this layout. Vec2<Unit>getSize()size of this drawable. UnitsetSize(Vec2<Unit> size)size of this drawable. final BooleangetResizesChildren()If this layout resizes its children (components and layouts! FloattrueX()Calculate the true X value (i.e. FloattrueY()Calculate the true Y value (i.e. UnitreRenderIfNecessary()this is the function that is called every frame. final UnitonAll(Boolean onChildLayouts, Function1<Component, Unit> function)perform the given function on all this layout's components, and optionally on all child layouts. final UnitonAllLayouts(Boolean reversed, Function1<Layout, Unit> function)perform the given function on all this layout's children and itself. final <T extends Drawable> Tget(String simpleName)return a component in this layout, by its simple name. final <T extends Component> TgetComponent(Integer index)Returns the component at the specified index. final <T extends Layout> TgetLayout(Integer index)Retrieves a layout from the children at the specified index. final <T extends Drawable> TgetOrNull(String simpleName)return a component in this layout, by its simple name. final Unitadd(Collection<Drawable> drawables)adds the given components/layouts to this layout. final Unitadd(Drawable components)adds the given components/layouts to this layout. Unitadd(Drawable drawable, Integer index)adds the given component/layout to this layout. Unitremove(Drawable drawable)removes a component from this layout. Unitremove(Integer index)Removes a component from this layout at the specified index. UnitremoveNow(Integer index)Removes a component from this layout immediately. UnitremoveNow(Drawable drawable)removes a component immediately, without waiting for it to finish up. UnitcalculateBounds()Calculate the position and size of this drawable. UnitonInitComplete()This function is called when initialization of a drawable is complete, so it has been fully calculated. Unitrescale(Float scaleX, Float scaleY)Method that is called when the physical size of the total window area changes. Unitrender()render this layout's components, and remove them if they are ready to be removed. final IntegercountDrawables()count the amount of drawables this contains, including the drawables its children have UnitdebugPrint()debug print for this drawable. UnitdebugRender()add a debug render overlay for this drawable. Unitsetup(Renderer renderer, PolyUI polyUI)give this a renderer reference and a PolyUI reference. UnitclipDrawables()This function will enable/disable rendering of drawables inside this layout based on their position and size. BooleanisInside(Float x, Float y)BooleanisInside(Float x, Float y, Float width, Float height)Booleanintersects(Float x, Float y, Float width, Float height)final UnitchangeColors(Colors colors)final UnitchangeFonts(FontFamily fonts)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. final Unitreset()Use this function to reset your drawable's PolyText if it is using one. final Layoutevery(Long nanos, Integer repeats, Function1<Layout, Unit> func)add a function that is called every nanos nanoseconds. StringtoString()final Layoutdraggable()Makes the layout draggable. final Layoutscrolling(Vec2<Unit> size, Boolean withScrollbars)add scrolling functionality to the layout and optionally scrollbars. final Layoutbackground(Boolean transparent, Boolean drags, FloatArray cornerRadii)Adds a background block to the layout. final static Array<out Drawable>drawables(Drawable drawables)wrapper for varargs, when arguments are in the wrong order -
Methods inherited from class org.polyfrost.polyui.component.Drawable
accept, addEventHandler, addEventhandler, addOperation, animateBy, animateTo, calculateSize, canBeRemoved, clone, 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, isDynamic, moveBy, moveTo, onParentInitComplete, postRender, preRender, 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
-
getPropertyManager
PropertyManager getPropertyManager()
-
setPropertyManager
Unit setPropertyManager(PropertyManager propertyManager)
-
getFonts
final FontFamily getFonts()
-
getComponents
final ArrayList<Component> getComponents()
-
getChildren
final ArrayList<Layout> getChildren()
-
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.- Since:
0.21.3
-
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.- Since:
0.21.3
-
getNeedsRedraw
Boolean getNeedsRedraw()
Weather this layout needs redrawing.
-
setNeedsRedraw
Unit setNeedsRedraw(Boolean needsRedraw)
-
getRefuseFramebuffer
Boolean getRefuseFramebuffer()
set this to true if you want this layout to never use a framebuffer. Recommended in situations with chroma colors
-
setRefuseFramebuffer
Unit setRefuseFramebuffer(Boolean refuseFramebuffer)
set this to true if you want this layout to never use a framebuffer. Recommended in situations with chroma colors
-
getInitCompleteHooks
final ArrayList<Function1<Layout, Unit>> getInitCompleteHooks()
These hooks are ran when the onInitComplete function is called.
- Since:
0.19.2
-
getDraggable
final Boolean getDraggable()
Flag that is true if the layout can be dragged around.
- Since:
0.19.2
-
getVisibleSize
final Vec2<Unit> getVisibleSize()
The visible area of this layout. If this is set, it is used for isInside checks.
If this layout is a scrolling layout, this is the size of the scrollable area.
- Since:
0.19.2
-
setVisibleSize
final Unit setVisibleSize(Vec2<Unit> visibleSize)
The visible area of this layout. If this is set, it is used for isInside checks.
If this layout is a scrolling layout, this is the size of the scrollable area.
- Since:
0.19.2
-
getResizesChildren
final Boolean getResizesChildren()
If this layout resizes its children (components and layouts!) when it is resized.
- Since:
0.19.0
-
trueX
Float trueX()
Calculate the true X value (i.e. not relative to the layout)
This method will NOT assign the value to the trueX field.
- Since:
0.19.0
-
trueY
Float trueY()
Calculate the true Y value (i.e. not relative to the layout)
This method will NOT assign the value to the trueY field.
- Since:
0.19.0
-
reRenderIfNecessary
Unit reRenderIfNecessary()
this is the function that is called every frame. It decides whether the layout needs to be entirely re-rendered. If so, the render function is called which will redraw all its' and components, and this function will redraw all its child layouts as well.
If this layout is using a framebuffer, it will be drawn to the framebuffer, and then drawn to the screen.
Note: Do not call this function yourself.
-
onAll
final Unit onAll(Boolean onChildLayouts, Function1<Component, Unit> function)
perform the given function on all this layout's components, and optionally on all child layouts.
-
onAllLayouts
final Unit onAllLayouts(Boolean reversed, Function1<Layout, Unit> function)
perform the given function on all this layout's children and itself.
- Since:
0.18.0
-
get
final <T extends Drawable> T get(String simpleName)
return a component in this layout, by its simple name. This can be accessed using debugPrint or using the field.
Note that the simpleName is NOT consistent between updates to PolyUI, or changes to the content of the layout.
-
getComponent
final <T extends Component> T getComponent(Integer index)
Returns the component at the specified index.
- Parameters:
index- The index of the component to retrieve.- Returns:
The component at the specified index.
- Since:
0.19.2
-
getLayout
final <T extends Layout> T getLayout(Integer index)
Retrieves a layout from the children at the specified index.
- Parameters:
index- The index of the layout to retrieve.- Returns:
The requested layout at the specified index.
- Since:
0.19.2
-
getOrNull
final <T extends Drawable> T getOrNull(String simpleName)
return a component in this layout, by its simple name. This can be accessed using debugPrint or using the field.
Note that the simpleName is NOT consistent between updates to PolyUI, or changes to the content of the layout. Returns null if not found.
-
add
final Unit add(Collection<Drawable> drawables)
adds the given components/layouts to this layout.
this will add the drawables to the Layout.components or children list, and invoke its added event function.
-
add
final Unit add(Drawable components)
adds the given components/layouts to this layout.
this will add the drawables to the Layout.components or children list, and invoke its added event function.
-
add
Unit add(Drawable drawable, Integer index)
adds the given component/layout to this layout.
this will add the drawable to the Layout.components or children list, and invoke its Added if it is present.
-
remove
Unit remove(Drawable drawable)
removes a component from this layout.
this will add the component to the removal queue, and invoke its removal event function.
This removal queue is used so that component can finish up any animations they're doing before being removed.
-
remove
Unit remove(Integer index)
Removes a component from this layout at the specified index.
- Parameters:
index- The index of the component to be removed.- Since:
0.19.2
-
removeNow
Unit removeNow(Integer index)
Removes a component from this layout immediately.
- Parameters:
index- The index of the component to be removed.- Since:
0.19.2
-
removeNow
@ApiStatus.Internal() Unit removeNow(Drawable drawable)
removes a component immediately, without waiting for it to finish up.
This is marked as internal because you should be using remove for most cases to remove a component, as it waits for it to finish and play any removal animations.
-
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.
-
onInitComplete
Unit onInitComplete()
This function is called when initialization of a drawable is complete, so it has been fully calculated.
This function is called once, and only once.
- Since:
0.19.0
-
rescale
Unit rescale(Float scaleX, Float scaleY)
Method that is called when the physical size of the total window area changes.
-
render
Unit render()
render this layout's components, and remove them if they are ready to be removed.
-
countDrawables
final Integer countDrawables()
count the amount of drawables this contains, including the drawables its children have
-
debugPrint
Unit debugPrint()
debug print for this drawable.
-
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.
-
clipDrawables
Unit clipDrawables()
This function will enable/disable rendering of drawables inside this layout based on their position and size.
If they lie outside the bounds of this layout, they will not be drawn to save resources.
- Since:
0.21.4
-
isInside
Boolean isInside(Float x, Float y)
- Returns:
trueif the given point is inside this drawable.
-
isInside
Boolean isInside(Float x, Float y, Float width, Float height)
- Returns:
trueif all the points of this drawable are inside the given box (x, y, width, height).- Since:
0.21.4
-
intersects
Boolean intersects(Float x, Float y, Float width, Float height)
- Returns:
trueif the drawable has at least one point inside the given box (x, y, width, height).- Since:
0.21.4
-
changeColors
final Unit changeColors(Colors colors)
-
changeFonts
final Unit changeFonts(FontFamily fonts)
-
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
-
every
final Layout every(Long nanos, Integer repeats, Function1<Layout, Unit> func)
add a function that is called every nanos nanoseconds.
- Since:
0.17.1
-
draggable
final Layout draggable()
Makes the layout draggable.
When the layout is made draggable, it can be moved around by dragging it with the mouse. This method adds an internal block component to the layout that handles the dragging functionality.
This function should only be called in the initialization of your layout, and not programmatically.
- Since:
0.19.2
-
scrolling
final Layout scrolling(Vec2<Unit> size, Boolean withScrollbars)
add scrolling functionality to the layout and optionally scrollbars.
- Parameters:
size- the scrollable area to set.- Since:
0.19.2
-
background
final Layout background(Boolean transparent, Boolean drags, FloatArray cornerRadii)
Adds a background block to the layout.
While there is nothing stopping you adding a background more than once, don't do it. It will cause problems.
- Parameters:
transparent- whether the background should be transparent or not.drags- whether this background should handle dragging the layout around.- Returns:
this- Since:
0.19.2
-
-
-
-