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.

    • Method Detail

      • 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.

      • 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

      • getDraggable

         final Boolean getDraggable()

        Flag that is true if the layout can be dragged around.

      • getResizesChildren

         final Boolean getResizesChildren()

        If this layout resizes its children (components and layouts!) when it is resized.

      • 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.

      • 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.

      • 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.

      • 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.
      • 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.
      • 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.

      • 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.
      • removeNow

         Unit removeNow(Integer index)

        Removes a component from this layout immediately.

        Parameters:
        index - The index of the component to be removed.
      • 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.

      • 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

      • 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.

      • 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!

      • reset

         final Unit reset()

        Use this function to reset your drawable's PolyText if it is using one.

      • 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.

      • 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.