Class UI2dComponent

All Implemented Interfaces:
LXLoopTask
Direct Known Subclasses:
UI2dContainer, UIAudio.Meter, UIColorPicker, UIColorSlider, UIContextButton, UIDiscreteColorBox, UIGradientPattern.UIPaletteGradient, UIImage, UIIndicator, UILabel, UIMeter, UIMidiFilter, UIParameterComponent, UISceneButton, UISceneStrip.UIClipViewToggle, UISoundObject.UILocation, UIStop

public abstract class UI2dComponent extends UIObject
  • Field Details

    • scissor

      protected final UI2dComponent.Scissor scissor
    • x

      protected float x
      Position of the object, relative to parent, top left corner
    • y

      protected float y
      Position of the object, relative to parent, top left corner
    • width

      protected float width
      Width of the object
    • height

      protected float height
      Height of the object
    • marginTop

      protected float marginTop
    • marginRight

      protected float marginRight
    • marginBottom

      protected float marginBottom
    • marginLeft

      protected float marginLeft
    • textAlignHorizontal

      protected VGraphics.Align textAlignHorizontal
    • textAlignVertical

      protected VGraphics.Align textAlignVertical
    • textOffsetX

      protected float textOffsetX
    • textOffsetY

      protected float textOffsetY
    • debug

      protected boolean debug
    • debugName

      protected String debugName
    • redraw

      public final LXParameterListener redraw
  • Constructor Details

    • UI2dComponent

      protected UI2dComponent()
    • UI2dComponent

      protected UI2dComponent(float x, float y, float width, float height)
  • Method Details

    • setDebug

      public UI2dComponent setDebug(boolean debug)
    • setDebug

      public UI2dComponent setDebug(boolean debug, String debugName)
    • getDebugClassHierarchy

      public String getDebugClassHierarchy()
    • dbch

      public String dbch(boolean reverse)
    • getDebugClassHierarchy

      public String getDebugClassHierarchy(boolean reverse)
    • setDescription

      public UI2dComponent setDescription(String description)
      Overrides:
      setDescription in class UIObject
    • getX

      public final float getX()
      X position
      Overrides:
      getX in class UIObject
      Returns:
      x position
    • getY

      public final float getY()
      Y position
      Overrides:
      getY in class UIObject
      Returns:
      y position
    • getAbsoluteX

      public final float getAbsoluteX()
      Gets the absolute X position of this component relative to the entire UI
      Returns:
      X position in absolute UI space
    • getAbsoluteY

      public final float getAbsoluteY()
      Gets the absolute Y position of this component relative to the entire UI
      Returns:
      Y position in absolute UI space
    • getWidth

      public final float getWidth()
      Width
      Specified by:
      getWidth in class UIObject
      Returns:
      width
    • getHeight

      public final float getHeight()
      Height
      Specified by:
      getHeight in class UIObject
      Returns:
      height
    • contains

      public boolean contains(float x, float y)
      Whether the given coordinate, in the parent-space, is contained by this object.
      Overrides:
      contains in class UIObject
      Parameters:
      x - X-coordinate in parent's coordinate space
      y - Y-coordinate in parent's coordinate space
      Returns:
      Whether this object's bounds contain that point
    • setVisible

      public UI2dComponent setVisible(boolean visible)
      Set the visibility state of this component
      Overrides:
      setVisible in class UIObject
      Parameters:
      visible - Whether this should be visible
      Returns:
      this
    • setX

      public UI2dComponent setX(float x)
      Set the position of this component in its parent coordinate space
      Parameters:
      x - X-position in parents coordinate space
      Returns:
      this
    • setY

      public UI2dComponent setY(float y)
      Set the position of this component in its parent coordinate space
      Parameters:
      y - Y-position in parents coordinate space
      Returns:
      this
    • setPosition

      public UI2dComponent setPosition(float x, float y)
      Set the position of this component in its parent coordinate space
      Parameters:
      x - X-position in parents coordinate space
      y - Y-position in parents coordinate space
      Returns:
      this
    • setPosition

      public UI2dComponent setPosition(float[] position)
      Sets position based upon an array of either 2 coordinates or 4
      Parameters:
      position - length 2 array or x/y, or length 4 of x/y/width/height
      Returns:
      this
    • setPosition

      public UI2dComponent setPosition(float x, float y, float width, float height)
      Set the position of this component in its parent coordinate space
      Parameters:
      x - X-position in parents coordinate space
      y - Y-position in parents coordinate space
      width - Width of object
      height - Height of object
      Returns:
      this
    • setPosition

      public UI2dComponent setPosition(UIObject parent, float offsetX, float offsetY)
      Sets the position of this object in the global space, relative to a parent object with a defined offset
      Parameters:
      parent - Parent object
      offsetX - X offset
      offsetY - Y offset
      Returns:
      this
    • setHeight

      public UI2dComponent setHeight(float height)
      Sets the height of this component
      Parameters:
      height - Height
      Returns:
      this
    • setWidth

      public UI2dComponent setWidth(float width)
      Sets the width of this component
      Parameters:
      width - Width of the component
      Returns:
      Width of this component
    • setSize

      public UI2dComponent setSize(float width, float height)
      Set the dimensions of this component
      Parameters:
      width - Width of component
      height - Height of component
      Returns:
      this
    • setMargin

      public UI2dComponent setMargin(float margin)
      Sets the margins around this object when inside of a UI2dContainer with layout
      Parameters:
      margin - Margin on all sides
      Returns:
      this
    • setMargin

      public UI2dComponent setMargin(float yMargin, float xMargin)
      Sets the margins around this object when inside of a UI2dContainer with layout
      Parameters:
      yMargin - Vertical margins
      xMargin - Horizontal margins
      Returns:
      this
    • setTopMargin

      public UI2dComponent setTopMargin(float topMargin)
      Sets the top margin around this object when inside a UI2dContainer with layout
      Parameters:
      topMargin - Top margin
      Returns:
      this
    • setBottomMargin

      public UI2dComponent setBottomMargin(float bottomMargin)
      Sets the bottom margin around this object when inside a UI2dContainer with layout
      Parameters:
      bottomMargin - Bottom margin
      Returns:
      this
    • setLeftMargin

      public UI2dComponent setLeftMargin(float leftMargin)
      Sets the left margin around this object when inside a UI2dContainer with layout
      Parameters:
      leftMargin - Left margin
      Returns:
      this
    • setRightMargin

      public UI2dComponent setRightMargin(float rightMargin)
      Sets the right margin around this object when inside a UI2dContainer with layout
      Parameters:
      rightMargin - Right margin
      Returns:
      this
    • setMargin

      public UI2dComponent setMargin(float topMargin, float rightMargin, float bottomMargin, float leftMargin)
      Sets the margins around this object when inside of a UI2dContainer with layout
      Parameters:
      topMargin - Top margin
      rightMargin - Right margin
      bottomMargin - Bottom margin
      leftMargin - Left margin
      Returns:
      this
    • onResize

      protected void onResize()
      Subclasses may override this method, invoked when the component is resized
    • hasBackground

      public boolean hasBackground()
      Whether this object has a background
      Returns:
      true or false
    • getBackgroundColor

      public UIColor getBackgroundColor()
      The background color, if there is a background
      Returns:
      color
    • setBackground

      public UI2dComponent setBackground(boolean hasBackground)
      Sets whether the object has a background
      Parameters:
      hasBackground - true or false
      Returns:
      this
    • setBackgroundColor

      public UI2dComponent setBackgroundColor(int backgroundColor)
      Sets a background color
      Parameters:
      backgroundColor - color
      Returns:
      this
    • setBackgroundColor

      public UI2dComponent setBackgroundColor(UIColor backgroundColor)
      Sets a background color
      Parameters:
      backgroundColor - color
      Returns:
      this
    • setFocusBackground

      public UI2dComponent setFocusBackground(boolean focusBackground)
      Sets whether a focus background color is used
      Parameters:
      focusBackground - Focus background color
      Returns:
      this
    • setFocusBackgroundColor

      public UI2dComponent setFocusBackgroundColor(int focusBackgroundColor)
      Sets a background color to be used when the component is focused
      Parameters:
      focusBackgroundColor - Color
      Returns:
      this
    • setFocusBackgroundColor

      public UI2dComponent setFocusBackgroundColor(UIColor focusBackgroundColor)
      Sets a background color to be used when the component is focused
      Parameters:
      focusBackgroundColor - Color
      Returns:
      this
    • hasBorder

      public boolean hasBorder()
      Whether this object has a border
      Returns:
      true or false
    • getBorderColor

      public UIColor getBorderColor()
      Current border color
      Returns:
      color
    • getBorderWeight

      public int getBorderWeight()
      The weight of the border
      Returns:
      weight
    • setBorder

      public UI2dComponent setBorder(boolean hasBorder)
      Sets whether there is a border
      Parameters:
      hasBorder - true or false
      Returns:
      this
    • setBorderColor

      public UI2dComponent setBorderColor(int borderColor)
      Sets the color of the border
      Parameters:
      borderColor - color
      Returns:
      this
    • setBorderColor

      public UI2dComponent setBorderColor(UIColor borderColor)
      Sets the color of the border
      Parameters:
      borderColor - color
      Returns:
      this
    • setBorderWeight

      public UI2dComponent setBorderWeight(int borderWeight)
      Sets the weight of the border
      Parameters:
      borderWeight - weight
      Returns:
      this
    • setBorderRounding

      public UI2dComponent setBorderRounding(int borderRounding)
    • setBorderRounding

      public UI2dComponent setBorderRounding(int borderRoundingTopLeft, int borderRoundingTopRight, int borderRoundingBottomRight, int borderRoundingBottomLeft)
    • setFocusCorners

      public UI2dComponent setFocusCorners(boolean focusCorners)
    • setFocusColor

      public UI2dComponent setFocusColor(int focusColor)
    • setFocusColor

      public UI2dComponent setFocusColor(UIColor focusColor)
    • hasFont

      public boolean hasFont()
      Whether a font is set on this object
      Returns:
      true or false
    • getFont

      public VGraphics.Font getFont()
      Get default font, may be null
      Returns:
      The default font, or null
    • setFont

      public UI2dComponent setFont(VGraphics.Font font)
      Sets the default font for this object to use, null indicates component may use its own default behavior.
      Parameters:
      font - Font
      Returns:
      this
    • hasFontColor

      public boolean hasFontColor()
      Whether this object has a specific color
      Returns:
      true or false
    • getFontColor

      public UIColor getFontColor()
      The font color, if there is a color specified
      Returns:
      color
    • setFontColor

      public UI2dComponent setFontColor(boolean hasFontColor)
      Sets whether the object has a font color
      Parameters:
      hasFontColor - true or false
      Returns:
      this
    • setFontColor

      public UI2dComponent setFontColor(int fontColor)
      Sets a font color
      Parameters:
      fontColor - color
      Returns:
      this
    • setFontColor

      public UI2dComponent setFontColor(UIColor fontColor)
      Sets a font color
      Parameters:
      fontColor - color
      Returns:
      this
    • setTextAlignment

      public UI2dComponent setTextAlignment(VGraphics.Align horizontalAlignment)
      Sets the text alignment
      Parameters:
      horizontalAlignment - From VGraphics.Align
      Returns:
      this
    • setTextOffset

      public UI2dComponent setTextOffset(float textOffsetX, float textOffsetY)
      Sets an offset for text rendering position relative to alignment. Note that adherence to this offset is not strictly enforced by all subclasses, it is up to them to implement it.
      Parameters:
      textOffsetX - Text position x offset
      textOffsetY - Text position y offset
      Returns:
      this
    • setTextAlignment

      public UI2dComponent setTextAlignment(VGraphics.Align horizontalAlignment, VGraphics.Align verticalAlignment)
      Sets the text alignment of this component
      Parameters:
      horizontalAlignment - From VGraphics.Align
      verticalAlignment - From VGraphics.Align
      Returns:
      this
    • clipTextToWidth

      public static String clipTextToWidth(VGraphics vg, String str, float width)
      Clip a text to fit in the given width
      Parameters:
      vg - VGraphics
      str - String
      width - Width to fit in
      Returns:
      Clipped version of the string that will fit in the bounds
    • clipTextToWidth

      public static String clipTextToWidth(VGraphics vg, String str, float width, boolean fromEnd)
      Clip a text to fit in the given width
      Parameters:
      vg - VGraphics
      str - String
      width - Width to fit in
      fromEnd - True clips from end, false clips from the start
      Returns:
      Clipped version of the string that will fit in the bounds
    • setMappable

      public UI2dComponent setMappable(boolean mappable)
      Sets whether this component can ever be used for mapping control
      Parameters:
      mappable - Whether this component is a mappable control
      Returns:
      this
    • isMappable

      protected boolean isMappable()
      Determines whether component is permitted to be a mappable control
      Returns:
      Whether this component is a mappable control
    • getMappableParameter

      public LXNormalizedParameter getMappableParameter(LXNormalizedParameter parameter)
      Returns a valid mappable parameter or null
      Parameters:
      parameter - Parameter to test
      Returns:
      Parameter if eligible for mapping
    • removeFromContainer

      public UI2dComponent removeFromContainer()
      Removes this component from the container it is held by
      Returns:
      this
    • removeFromContainer

      public UI2dComponent removeFromContainer(boolean redraw)
      Removes this component from the container it is held by
      Parameters:
      redraw - Whether to reflow and redraw the container
      Returns:
      this
    • getParent

      public UIObject getParent()
      Get the parent object that this is in
      Overrides:
      getParent in class UIObject
      Returns:
      Parent of this component
    • getPrevSibling

      public UI2dComponent getPrevSibling()
      Returns the adjacent object in the hierarchy
      Returns:
      The previous UI object in the hierarchy adjacent to this one
    • getNextSibling

      public UI2dComponent getNextSibling()
      Returns the adjacent object in the hierarchy
      Returns:
      The next UI object in the hierarchy adjacent to this one
    • getContainer

      public UI2dContainer getContainer()
      Returns the 2d container that this is in
      Returns:
      Container of this component, or null if not in a 2d container
    • addToContainer

      public final UI2dComponent addToContainer(UIContainer container)
      Adds this component to a container, also removing it from any other container that is currently holding it.
      Parameters:
      container - Container to place in
      Returns:
      this
    • addToContainer

      public final UI2dComponent addToContainer(UIContainer container, boolean redraw)
      Adds this component to a container, also removing it from any other container that is currently holding it.
      Parameters:
      container - Container to place in
      redraw - Whether to reflow and redraw the parent container
      Returns:
      this
    • addToContainer

      public final UI2dComponent addToContainer(UIContainer container, int index)
      Adds this component to a container at a specified index, also removing it from any other container that is currently holding it.
      Parameters:
      container - Container to place in
      index - At which index to place this object in parent container
      Returns:
      this
    • addToContainer

      public final UI2dComponent addToContainer(UIContainer container, int index, boolean redraw)
      Adds this component to a container at a specified index, also removing it from any other container that is currently holding it. Reflow behavior is controlled by a flag.
      Parameters:
      container - Container to place in
      index - At which index to place this object in parent container
      redraw - Whether to reflow and redraw the parent container
      Returns:
      this
    • addToContainer

      public final UI2dComponent addToContainer(UI2dContainer container, UI2dContainer.Position position)
      Adds this component to a container, also removing it from any other container that is currently holding it.
      Parameters:
      container - Container to place in
      position - Placement in this container
      Returns:
      this
    • addToContainer

      public final UI2dComponent addToContainer(UI2dContainer container, int index, UI2dContainer.Position position)
      Adds this component to a container at a specified index, also removing it from any other container that is currently holding it.
      Parameters:
      container - Container to place in
      index - At which index to place this object in parent container
      position - Position in the container to place this object
      Returns:
      this
    • addToContainer

      public final UI2dComponent addToContainer(UI2dContainer container, UI2dContainer.Position position, boolean redraw)
      Adds this component to a container, also removing it from any other container that is currently holding it.
      Parameters:
      container - Container to place in
      position - Placement in this container
      redraw - Whether to reflow and redraw the parent container
      Returns:
      this
    • addToContainer

      public final UI2dComponent addToContainer(UI2dContainer container, int index, UI2dContainer.Position position, boolean redraw)
      Adds this component to a container at a specified index, also removing it from any other container that is currently holding it. Reflow behavior is controlled by a flag.
      Parameters:
      container - Container to place in
      index - At which index to place this object in parent container
      position - Position in the container at which to place the object, or null
      redraw - Whether to reflow and redraw the parent container
      Returns:
      this
    • assertValidContainer

      protected void assertValidContainer(UIContainer container)
      Subclasses may override and throw an exception if they don't want to be added to this container type
      Parameters:
      container - Container
    • setContainerPosition

      public UI2dComponent setContainerPosition(UI2dContainer.Position containerPosition)
      Sets the position of this object in its container
      Parameters:
      containerPosition - Position relative to container
      Returns:
      this
    • setContainerIndex

      public UI2dComponent setContainerIndex(int index)
      Sets the index of this object in its container.
      Parameters:
      index - Desired index
      Returns:
      this
    • redraw

      public final UI2dComponent redraw()
      Redraws this object.
      Returns:
      this object
    • onDraw

      protected void onDraw(UI ui, VGraphics vg)
      Subclasses should override this method to perform their drawing functions.
      Parameters:
      ui - UI context
      vg - Graphics context
    • vgRoundedRect

      protected void vgRoundedRect(VGraphics vg)
    • vgRoundedRect

      protected void vgRoundedRect(VGraphics vg, float x, float y, float w, float h)
    • vgRoundedRect

      protected void vgRoundedRect(UI2dComponent that, VGraphics vg, float x, float y, float w, float h)
    • drawBackground

      protected void drawBackground(UI ui, VGraphics vg)
    • drawParentBackground

      protected void drawParentBackground(UI ui, VGraphics vg)
    • drawBorder

      protected void drawBorder(UI ui, VGraphics vg)
    • getFocusColor

      protected UIColor getFocusColor(UI ui)
    • getFocusSize

      protected int getFocusSize()
      Focus size for hashes drawn on the outline of the object. May be overridden.
      Returns:
      Focus hash line size
    • drawFocus

      protected void drawFocus(UI ui, VGraphics vg)
      Draws focus on this object. May be overridden by subclasses to provide custom focus-drawing behavior.
      Parameters:
      ui - UI
      vg - VGraphics
    • drawFocusCorners

      protected void drawFocusCorners(UI ui, VGraphics vg, int color)
    • drawFocusCorners

      public static void drawFocusCorners(UI ui, VGraphics vg, int color, float x, float y, float width, float height, float focusSize)