Package heronarts.glx.ui
Class UI2dComponent
java.lang.Object
heronarts.glx.ui.UIEventHandler
heronarts.glx.ui.UIObject
heronarts.glx.ui.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
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
static interface
Marker interface for components whose drawing should be scissoredstatic interface
Marker interface for components which can be dragged to reorder them within their container. -
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
protected String
protected float
Height of the objectprotected float
protected float
protected float
protected float
final LXParameterListener
protected final UI2dComponent.Scissor
protected VGraphics.Align
protected VGraphics.Align
protected float
protected float
protected float
Width of the objectprotected float
Position of the object, relative to parent, top left cornerprotected float
Position of the object, relative to parent, top left corner -
Constructor Summary
ModifierConstructorDescriptionprotected
protected
UI2dComponent
(float x, float y, float width, float height) -
Method Summary
Modifier and TypeMethodDescriptionfinal 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.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.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.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.final UI2dComponent
addToContainer
(UIContainer container) Adds this component to a container, also removing it from any other container that is currently holding it.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.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.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.protected void
assertValidContainer
(UIContainer container) Subclasses may override and throw an exception if they don't want to be added to this container typestatic String
clipTextToWidth
(VGraphics vg, String str, float width) Clip a text to fit in the given widthstatic String
clipTextToWidth
(VGraphics vg, String str, float width, boolean fromEnd) Clip a text to fit in the given widthboolean
contains
(float x, float y) Whether the given coordinate, in the parent-space, is contained by this object.dbch
(boolean reverse) protected void
drawBackground
(UI ui, VGraphics vg) protected void
drawBorder
(UI ui, VGraphics vg) protected void
Draws focus on this object.protected void
drawFocusCorners
(UI ui, VGraphics vg, int color) static void
drawFocusCorners
(UI ui, VGraphics vg, int color, float x, float y, float width, float height, float focusSize) protected void
drawParentBackground
(UI ui, VGraphics vg) final float
Gets the absolute X position of this component relative to the entire UIfinal float
Gets the absolute Y position of this component relative to the entire UIThe background color, if there is a backgroundCurrent border colorint
The weight of the borderReturns the 2d container that this is ingetDebugClassHierarchy
(boolean reverse) protected UIColor
getFocusColor
(UI ui) protected int
Focus size for hashes drawn on the outline of the object.getFont()
Get default font, may be nullThe font color, if there is a color specifiedfinal float
HeightgetMappableParameter
(LXNormalizedParameter parameter) Returns a valid mappable parameter or nullReturns the adjacent object in the hierarchyGet the parent object that this is inReturns the adjacent object in the hierarchyfinal float
getWidth()
Widthfinal float
getX()
X positionfinal float
getY()
Y positionboolean
Whether this object has a backgroundboolean
Whether this object has a borderboolean
hasFont()
Whether a font is set on this objectboolean
Whether this object has a specific colorprotected boolean
Determines whether component is permitted to be a mappable controlprotected void
Subclasses should override this method to perform their drawing functions.protected void
onResize()
Subclasses may override this method, invoked when the component is resizedfinal UI2dComponent
redraw()
Redraws this object.Removes this component from the container it is held byremoveFromContainer
(boolean redraw) Removes this component from the container it is held bysetBackground
(boolean hasBackground) Sets whether the object has a backgroundsetBackgroundColor
(int backgroundColor) Sets a background colorsetBackgroundColor
(UIColor backgroundColor) Sets a background colorsetBorder
(boolean hasBorder) Sets whether there is a bordersetBorderColor
(int borderColor) Sets the color of the bordersetBorderColor
(UIColor borderColor) Sets the color of the bordersetBorderRounding
(int borderRounding) setBorderRounding
(int borderRoundingTopLeft, int borderRoundingTopRight, int borderRoundingBottomRight, int borderRoundingBottomLeft) setBorderWeight
(int borderWeight) Sets the weight of the bordersetBottomMargin
(float bottomMargin) Sets the bottom margin around this object when inside a UI2dContainer with layoutsetContainerIndex
(int index) Sets the index of this object in its container.setContainerPosition
(UI2dContainer.Position containerPosition) Sets the position of this object in its containersetDebug
(boolean debug) setDescription
(String description) setFocusBackground
(boolean focusBackground) Sets whether a focus background color is usedsetFocusBackgroundColor
(int focusBackgroundColor) Sets a background color to be used when the component is focusedsetFocusBackgroundColor
(UIColor focusBackgroundColor) Sets a background color to be used when the component is focusedsetFocusColor
(int focusColor) setFocusColor
(UIColor focusColor) setFocusCorners
(boolean focusCorners) setFont
(VGraphics.Font font) Sets the default font for this object to use, null indicates component may use its own default behavior.setFontColor
(boolean hasFontColor) Sets whether the object has a font colorsetFontColor
(int fontColor) Sets a font colorsetFontColor
(UIColor fontColor) Sets a font colorsetHeight
(float height) Sets the height of this componentsetLeftMargin
(float leftMargin) Sets the left margin around this object when inside a UI2dContainer with layoutsetMappable
(boolean mappable) Sets whether this component can ever be used for mapping controlsetMargin
(float margin) Sets the margins around this object when inside of a UI2dContainer with layoutsetMargin
(float yMargin, float xMargin) Sets the margins around this object when inside of a UI2dContainer with layoutsetMargin
(float topMargin, float rightMargin, float bottomMargin, float leftMargin) Sets the margins around this object when inside of a UI2dContainer with layoutsetPosition
(float[] position) Sets position based upon an array of either 2 coordinates or 4setPosition
(float x, float y) Set the position of this component in its parent coordinate spacesetPosition
(float x, float y, float width, float height) Set the position of this component in its parent coordinate spacesetPosition
(UIObject parent, float offsetX, float offsetY) Sets the position of this object in the global space, relative to a parent object with a defined offsetsetRightMargin
(float rightMargin) Sets the right margin around this object when inside a UI2dContainer with layoutsetSize
(float width, float height) Set the dimensions of this componentsetTextAlignment
(VGraphics.Align horizontalAlignment) Sets the text alignmentsetTextAlignment
(VGraphics.Align horizontalAlignment, VGraphics.Align verticalAlignment) Sets the text alignment of this componentsetTextOffset
(float textOffsetX, float textOffsetY) Sets an offset for text rendering position relative to alignment.setTopMargin
(float topMargin) Sets the top margin around this object when inside a UI2dContainer with layoutsetVisible
(boolean visible) Set the visibility state of this componentsetWidth
(float width) Sets the width of this componentsetX
(float x) Set the position of this component in its parent coordinate spacesetY
(float y) Set the position of this component in its parent coordinate spaceprotected void
vgRoundedRect
(UI2dComponent that, VGraphics vg, float x, float y, float w, float h) protected void
protected void
vgRoundedRect
(VGraphics vg, float x, float y, float w, float h) Methods inherited from class heronarts.glx.ui.UIObject
addListener, addListener, addLoopTask, blur, bringToFront, dispose, focus, getDescription, getFocusedChild, getLX, getUI, hasDirectFocus, hasFocus, isVisible, loop, onBlur, onFocus, onUIResize, removeLoopTask, requireUIThread, setConsumeMousePress, setDebugId, toggleVisible, toString
Methods inherited from class heronarts.glx.ui.UIEventHandler
onKeyPressed, onKeyReleased, onMouseDragged, onMouseMoved, onMouseOut, onMouseOver, onMousePressed, onMouseReleased, onMouseScroll
-
Field Details
-
scissor
-
x
protected float xPosition of the object, relative to parent, top left corner -
y
protected float yPosition of the object, relative to parent, top left corner -
width
protected float widthWidth of the object -
height
protected float heightHeight of the object -
marginTop
protected float marginTop -
marginRight
protected float marginRight -
marginBottom
protected float marginBottom -
marginLeft
protected float marginLeft -
textAlignHorizontal
-
textAlignVertical
-
textOffsetX
protected float textOffsetX -
textOffsetY
protected float textOffsetY -
debug
protected boolean debug -
debugName
-
redraw
-
-
Constructor Details
-
UI2dComponent
protected UI2dComponent() -
UI2dComponent
protected UI2dComponent(float x, float y, float width, float height)
-
-
Method Details
-
setDebug
-
setDebug
-
getDebugClassHierarchy
-
dbch
-
getDebugClassHierarchy
-
setDescription
- Overrides:
setDescription
in classUIObject
-
getX
public final float getX()X position -
getY
public final float getY()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 -
getHeight
public final float getHeight()Height -
contains
public boolean contains(float x, float y) Whether the given coordinate, in the parent-space, is contained by this object. -
setVisible
Set the visibility state of this component- Overrides:
setVisible
in classUIObject
- Parameters:
visible
- Whether this should be visible- Returns:
- this
-
setX
Set the position of this component in its parent coordinate space- Parameters:
x
- X-position in parents coordinate space- Returns:
- this
-
setY
Set the position of this component in its parent coordinate space- Parameters:
y
- Y-position in parents coordinate space- Returns:
- this
-
setPosition
Set the position of this component in its parent coordinate space- Parameters:
x
- X-position in parents coordinate spacey
- Y-position in parents coordinate space- Returns:
- this
-
setPosition
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
Set the position of this component in its parent coordinate space- Parameters:
x
- X-position in parents coordinate spacey
- Y-position in parents coordinate spacewidth
- Width of objectheight
- Height of object- Returns:
- this
-
setPosition
Sets the position of this object in the global space, relative to a parent object with a defined offset- Parameters:
parent
- Parent objectoffsetX
- X offsetoffsetY
- Y offset- Returns:
- this
-
setHeight
Sets the height of this component- Parameters:
height
- Height- Returns:
- this
-
setWidth
Sets the width of this component- Parameters:
width
- Width of the component- Returns:
- Width of this component
-
setSize
Set the dimensions of this component- Parameters:
width
- Width of componentheight
- Height of component- Returns:
- this
-
setMargin
Sets the margins around this object when inside of a UI2dContainer with layout- Parameters:
margin
- Margin on all sides- Returns:
- this
-
setMargin
Sets the margins around this object when inside of a UI2dContainer with layout- Parameters:
yMargin
- Vertical marginsxMargin
- Horizontal margins- Returns:
- this
-
setTopMargin
Sets the top margin around this object when inside a UI2dContainer with layout- Parameters:
topMargin
- Top margin- Returns:
- this
-
setBottomMargin
Sets the bottom margin around this object when inside a UI2dContainer with layout- Parameters:
bottomMargin
- Bottom margin- Returns:
- this
-
setLeftMargin
Sets the left margin around this object when inside a UI2dContainer with layout- Parameters:
leftMargin
- Left margin- Returns:
- this
-
setRightMargin
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 marginrightMargin
- Right marginbottomMargin
- Bottom marginleftMargin
- 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
The background color, if there is a background- Returns:
- color
-
setBackground
Sets whether the object has a background- Parameters:
hasBackground
- true or false- Returns:
- this
-
setBackgroundColor
Sets a background color- Parameters:
backgroundColor
- color- Returns:
- this
-
setBackgroundColor
Sets a background color- Parameters:
backgroundColor
- color- Returns:
- this
-
setFocusBackground
Sets whether a focus background color is used- Parameters:
focusBackground
- Focus background color- Returns:
- this
-
setFocusBackgroundColor
Sets a background color to be used when the component is focused- Parameters:
focusBackgroundColor
- Color- Returns:
- this
-
setFocusBackgroundColor
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
Current border color- Returns:
- color
-
getBorderWeight
public int getBorderWeight()The weight of the border- Returns:
- weight
-
setBorder
Sets whether there is a border- Parameters:
hasBorder
- true or false- Returns:
- this
-
setBorderColor
Sets the color of the border- Parameters:
borderColor
- color- Returns:
- this
-
setBorderColor
Sets the color of the border- Parameters:
borderColor
- color- Returns:
- this
-
setBorderWeight
Sets the weight of the border- Parameters:
borderWeight
- weight- Returns:
- this
-
setBorderRounding
-
setBorderRounding
public UI2dComponent setBorderRounding(int borderRoundingTopLeft, int borderRoundingTopRight, int borderRoundingBottomRight, int borderRoundingBottomLeft) -
setFocusCorners
-
setFocusColor
-
setFocusColor
-
hasFont
public boolean hasFont()Whether a font is set on this object- Returns:
- true or false
-
getFont
Get default font, may be null- Returns:
- The default font, or null
-
setFont
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
The font color, if there is a color specified- Returns:
- color
-
setFontColor
Sets whether the object has a font color- Parameters:
hasFontColor
- true or false- Returns:
- this
-
setFontColor
Sets a font color- Parameters:
fontColor
- color- Returns:
- this
-
setFontColor
Sets a font color- Parameters:
fontColor
- color- Returns:
- this
-
setTextAlignment
Sets the text alignment- Parameters:
horizontalAlignment
- From VGraphics.Align- Returns:
- this
-
setTextOffset
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 offsettextOffsetY
- 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.AlignverticalAlignment
- From VGraphics.Align- Returns:
- this
-
clipTextToWidth
Clip a text to fit in the given width- Parameters:
vg
- VGraphicsstr
- Stringwidth
- Width to fit in- Returns:
- Clipped version of the string that will fit in the bounds
-
clipTextToWidth
Clip a text to fit in the given width- Parameters:
vg
- VGraphicsstr
- Stringwidth
- Width to fit infromEnd
- True clips from end, false clips from the start- Returns:
- Clipped version of the string that will fit in the bounds
-
setMappable
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
Returns a valid mappable parameter or null- Parameters:
parameter
- Parameter to test- Returns:
- Parameter if eligible for mapping
-
removeFromContainer
Removes this component from the container it is held by- Returns:
- this
-
removeFromContainer
Removes this component from the container it is held by- Parameters:
redraw
- Whether to reflow and redraw the container- Returns:
- this
-
getParent
Get the parent object that this is in -
getPrevSibling
Returns the adjacent object in the hierarchy- Returns:
- The previous UI object in the hierarchy adjacent to this one
-
getNextSibling
Returns the adjacent object in the hierarchy- Returns:
- The next UI object in the hierarchy adjacent to this one
-
getContainer
Returns the 2d container that this is in- Returns:
- Container of this component, or null if not in a 2d container
-
addToContainer
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
Adds this component to a container, also removing it from any other container that is currently holding it.- Parameters:
container
- Container to place inredraw
- Whether to reflow and redraw the parent container- Returns:
- this
-
addToContainer
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 inindex
- At which index to place this object in parent container- Returns:
- this
-
addToContainer
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 inindex
- At which index to place this object in parent containerredraw
- Whether to reflow and redraw the parent container- Returns:
- this
-
addToContainer
Adds this component to a container, also removing it from any other container that is currently holding it.- Parameters:
container
- Container to place inposition
- 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 inindex
- At which index to place this object in parent containerposition
- 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 inposition
- Placement in this containerredraw
- 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 inindex
- At which index to place this object in parent containerposition
- Position in the container at which to place the object, or nullredraw
- Whether to reflow and redraw the parent container- Returns:
- this
-
assertValidContainer
Subclasses may override and throw an exception if they don't want to be added to this container type- Parameters:
container
- Container
-
setContainerPosition
Sets the position of this object in its container- Parameters:
containerPosition
- Position relative to container- Returns:
- this
-
setContainerIndex
Sets the index of this object in its container.- Parameters:
index
- Desired index- Returns:
- this
-
redraw
Redraws this object.- Returns:
- this object
-
onDraw
Subclasses should override this method to perform their drawing functions.- Parameters:
ui
- UI contextvg
- Graphics context
-
vgRoundedRect
-
vgRoundedRect
-
vgRoundedRect
-
drawBackground
-
drawParentBackground
-
drawBorder
-
getFocusColor
-
getFocusSize
protected int getFocusSize()Focus size for hashes drawn on the outline of the object. May be overridden.- Returns:
- Focus hash line size
-
drawFocus
Draws focus on this object. May be overridden by subclasses to provide custom focus-drawing behavior.- Parameters:
ui
- UIvg
- VGraphics
-
drawFocusCorners
-
drawFocusCorners
-