Class Drawable

  • All Implemented Interfaces:
    kotlin.Cloneable

    
    public abstract class Drawable
     implements Cloneable
                        

    The most basic thing in the PolyUI rendering system.

    This class is implemented for both Layout and Drawable, and you should use them as bases if you are creating a UI in most cases.

    • Method Detail

      • getSimpleName

         String getSimpleName()

        This is the name of this drawable, and it will be consistent over reboots of the program, so you can use it to get drawables from a layout by ID, e.g:

        val text = myLayout["Text@4cf777e8"] as Text

      • setSimpleName

         Unit setSimpleName(String simpleName)

        This is the name of this drawable, and it will be consistent over reboots of the program, so you can use it to get drawables from a layout by ID, e.g:

        val text = myLayout["Text@4cf777e8"] as Text

      • getInitStage

         final Byte getInitStage()

        This is the initialization stage of this drawable.

      • setRenders

         Unit setRenders(Boolean renders)

        weather or not this drawable should be rendered.

        This is controlled by Layout.clipDrawables to save resources by not drawing drawables which cannot be seen.

        It is only respected by Layout by default. This means that if you are calling render yourself (which you really shouldn't), you should check this value.

      • getLayout

         abstract 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 doing this.layout.layout or deeper, you should null-check.

      • getConsumesHover

         abstract 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

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

      • getExists

         final Boolean getExists()

        This flag controls weather this drawable exists, meaning if it accepts events and renders.

        Additionally:

        • In layouts, they will display as empty (no drawables) if this is false.

        • In components, they will be excluded from calculations.

      • setExists

         final Unit setExists(Boolean exists)

        This flag controls weather this drawable exists, meaning if it accepts events and renders.

        Additionally:

        • In layouts, they will display as empty (no drawables) if this is false.

        • In components, they will be excluded from calculations.

      • getTrueX

         final Float getTrueX()

        true X value (i.e. not relative to the layout)

      • setTrueX

         final Unit setTrueX(Float trueX)

        true X value (i.e. not relative to the layout)

      • getTrueY

         final Float getTrueY()

        true Y value (i.e. not relative to the layout)

      • setTrueY

         final Unit setTrueY(Float trueY)

        true Y value (i.e. not relative to the layout)

      • getRotation

         final Double getRotation()

        current rotation of this drawable (radians).

      • getSkewX

         final Double getSkewX()

        current skew in x dimension of this drawable (radians).

      • setSkewX

         final Unit setSkewX(Double skewX)

        current skew in x dimension of this drawable (radians).

      • getSkewY

         final Double getSkewY()

        current skew in y dimension of this drawable (radians).

      • setSkewY

         final Unit setSkewY(Double skewY)

        current skew in y dimension of this drawable (radians).

      • getScaleX

         final Float getScaleX()

        current scale in x dimension of this drawable.

      • setScaleX

         final Unit setScaleX(Float scaleX)

        current scale in x dimension of this drawable.

      • getScaleY

         final Float getScaleY()

        current scale in y dimension of this drawable.

      • setScaleY

         final Unit setScaleY(Float scaleY)

        current scale in y dimension of this drawable.

      • getAlpha

         final Float getAlpha()

        The alpha value of this drawable.

      • getAcx

         final Float getAcx()

        at cache x for transformations.

      • setAcx

         final Unit setAcx(@ApiStatus.Internal() Float acx)

        at cache x for transformations.

      • getAcy

         final Float getAcy()

        at cache y for transformations.

      • setAcy

         final Unit setAcy(@ApiStatus.Internal() Float acy)

        at cache y for transformations.

      • getRawResize

         final Boolean getRawResize()

        This property controls weather this drawable resizes "raw", meaning it will not respect the aspect ratio.

        By default, it is false, so when resized, the smallest increase is used for both width and height. This means that it will stay at the same aspect ratio.

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

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

         abstract Unit render()

        draw script for this drawable.

      • calculateBounds

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

      • rescale

         Unit rescale(Float scaleX, Float scaleY)

        Method that is called when the physical size of the total window area changes.

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

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

      • reset

         Unit reset()

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

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

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

      • onParentInitComplete

         Unit onParentInitComplete()

        This function is called when initialization of this parent is complete.

        This function is called once, and only once.

      • getContainingLayout

         final Layout getContainingLayout()

        Return the layout of the highest order (the one inside the master layout) that contains this drawable.

        If this is the master layout, it is returned.

      • clone

         Drawable clone()

        Implement this function to enable cloning of your Drawable.

        If this function is not implemented, attempts to clone the drawable will not compile due to type erasure, but if this is ignored a CloneNotSupportedException will be thrown.

      • calculateSize

         Vec2<Unit> calculateSize()

        Implement this function to return the size of this drawable, if no size is specified during construction.

        This should be so that if the drawable can determine its own size (for example, it is an image), then the size parameter in the constructor can be omitted using:

        size: Vec2<org.polyfrost.polyui.unit.Unit>? = null; and this method needs to be implemented!

        Otherwise, the size parameter in the constructor must be specified.

      • onColorsChanged

        @MustBeInvokedByOverriders() abstract 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

        @MustBeInvokedByOverriders() abstract 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!

      • scaleBy

         final Unit scaleBy(Float xFactor, Float yFactor, Animation.Type animation, Long durationNanos, Function1<Drawable, Unit> onFinish)

        Scale this drawable by the given amount, in the X and Y dimensions.

        Please note that this ignores all bounds, and will simply scale this drawable, meaning that it can be clipped by its layout, and overlap nearby drawable.

      • scaleTo

         final Unit scaleTo(Float xFactor, Float yFactor, Animation.Type animation, Long durationNanos, Function1<Drawable, Unit> onFinish)

        Scale this drawable to the given amount, in the X and Y dimensions.

        Please note that this ignores all bounds, and will simply scale this drawable, meaning that it can be clipped by its layout, and overlap nearby drawable.

      • rotateTo

         final Unit rotateTo(Double degrees, Animation.Type animation, Long durationNanos, Function1<Drawable, Unit> onFinish)

        Rotate this drawable to the given amount, in degrees. The amount is MOD 360 to return a value between 0-360 always.

        Please note that this ignores all bounds, and will simply scale this drawable, meaning that it can be clipped by its layout, and overlap nearby drawable.

      • rotateBy

         final Unit rotateBy(Double degrees, Animation.Type animation, Long durationNanos, Function1<Drawable, Unit> onFinish)

        Rotate this drawable by the given amount, in degrees.

        Please note that this ignores all bounds, and will simply scale this drawable, meaning that it can be clipped by its layout, and overlap nearby drawable.

      • skewTo

         final Unit skewTo(Double skewX, Double skewY, Animation.Type animation, Long durationNanos)

        Skew this drawable to the given amount, in degrees.

        Please note that this ignores all bounds, and will simply scale this drawable, meaning that it can be clipped by its layout, and overlap nearby drawable.

      • skewBy

         final Unit skewBy(Double skewX, Double skewY, Animation.Type animation, Long durationNanos)

        Skew this drawable by the given amount, in degrees.

        Please note that this ignores all bounds, and will simply scale this drawable, meaning that it can be clipped by its layout, and overlap nearby drawable.

      • moveTo

         final Unit moveTo(Vec2<Unit> to, Animation.Type animation, Long durationNanos, Function1<Drawable, Unit> onFinish)

        move this drawable to the provided point.

        Please note that this ignores all bounds, and will simply scale this drawable, meaning that it can be clipped by its layout, and overlap nearby drawable.

      • moveBy

         final Unit moveBy(Vec2<Unit> by, Animation.Type animation, Long durationNanos, Function1<Drawable, Unit> onFinish)

        move this drawable by the given amount.

        Please note that this ignores all bounds, and will simply scale this drawable, meaning that it can be clipped by its layout, and overlap nearby drawable.