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.

    • Method Detail

      • 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 doing this.layout.layout or 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 doing this.layout.layout or 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.

        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

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

        Since:

        0.21.4

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

        Returns:

        true if the event should be consumed (cancelled so no more handlers are called), false otherwise.

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

        0.19.1

      • 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

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

      • 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