public abstract class UI2dComponent extends UIObject
Modifier and Type | Field and Description |
---|---|
protected float |
bottomMargin |
protected float |
height
Height of the object
|
protected float |
leftMargin |
protected float |
rightMargin |
protected int |
textAlignHorizontal |
protected int |
textAlignVertical |
protected float |
textOffsetX |
protected float |
textOffsetY |
protected float |
topMargin |
protected float |
width
Width of the object
|
protected float |
x
Position of the object, relative to parent, top left corner
|
protected float |
y
Position of the object, relative to parent, top left corner
|
children, hasFocus, mousePressContextMenu, visible
Modifier | Constructor and Description |
---|---|
protected |
UI2dComponent() |
protected |
UI2dComponent(float x,
float y,
float width,
float height) |
Modifier and Type | Method and Description |
---|---|
UI2dComponent |
addToContainer(UIContainer container)
Adds this component to a container, also removing it from any other container that
is currently holding it.
|
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.
|
static String |
breakTextToWidth(PGraphics pg,
String str,
float width)
Break a text into multiple lines to fit in the given width
|
static String |
clipTextToWidth(PGraphics pg,
String str,
float width)
Clip a text to fit in the given width
|
boolean |
contains(float x,
float y)
Whether the given coordinate, in the parent-space, is contained
by this object.
|
protected void |
drawBackground(UI ui,
PGraphics pg) |
protected void |
drawBorder(UI ui,
PGraphics pg) |
protected void |
drawFocus(UI ui,
PGraphics pg)
Draws focus on this object.
|
protected void |
drawFocusCorners(UI ui,
PGraphics pg,
int color) |
static void |
drawFocusCorners(UI ui,
PGraphics pg,
int color,
float x,
float y,
float width,
float height,
int focusSize) |
int |
getBackgroundColor()
The background color, if there is a background
|
int |
getBorderColor()
Current border color
|
int |
getBorderRounding() |
int |
getBorderWeight()
The weight of the border
|
UI2dContainer |
getContainer()
Returns the 2d container that this is in
|
protected int |
getFocusColor(UI ui) |
protected int |
getFocusSize()
Focus size for hashes drawn on the outline of the object.
|
PFont |
getFont()
Get default font, may be null
|
int |
getFontColor()
The font color, if there is a color specified
|
float |
getHeight()
Height
|
UI2dComponent |
getNextSibling()
Returns the adjacent object in the hierarchy
|
UIObject |
getParent()
Get the parent object that this is in
|
UI2dComponent |
getPrevSibling()
Returns the adjacent object in the hierarchy
|
float |
getWidth()
Width
|
float |
getX()
X position
|
float |
getY()
Y position
|
boolean |
hasBackground()
Whether this object has a background
|
boolean |
hasBorder()
Whether this object has a border
|
boolean |
hasFont()
Whether a font is set on this object
|
boolean |
hasFontColor()
Whether this object has a specific color
|
protected boolean |
isMappable()
Determines whether component is permitted to be a mappable control
|
protected void |
onResize()
Subclasses may override this method, invoked when the component is resized
|
UI2dComponent |
redraw()
Redraws this object.
|
UI2dComponent |
removeFromContainer()
Removes this components from the container is is held by
|
UI2dComponent |
setBackground(boolean hasBackground)
Sets whether the object has a background
|
UI2dComponent |
setBackgroundColor(int backgroundColor)
Sets a background color
|
UI2dComponent |
setBorder(boolean hasBorder)
Sets whether there is a border
|
UI2dComponent |
setBorderColor(int borderColor)
Sets the color of the border
|
UI2dComponent |
setBorderRounding(int borderRounding) |
UI2dComponent |
setBorderWeight(int borderWeight)
Sets the weight of the border
|
UI2dComponent |
setBottomMargin(float bottomMargin)
Sets the bottom margin around this object when inside a UI2dContainer with layout
|
UI2dComponent |
setContainerIndex(int index)
Sets the index of this object in its container.
|
UI2dComponent |
setDescription(String description) |
UI2dComponent |
setFocusBackground(boolean focusBackground)
Sets whether a focus background color is used
|
UI2dComponent |
setFocusBackgroundColor(int focusBackgroundColor)
Sets a background color to be used when the component is focused
|
UI2dComponent |
setFocusColor(int focusColor) |
UI2dComponent |
setFocusCorners(boolean focusCorners) |
UI2dComponent |
setFont(PFont font)
Sets the default font for this object to use, null indicates component may
use its own default behavior.
|
UI2dComponent |
setFontColor(boolean hasFontColor)
Sets whether the object has a font color
|
UI2dComponent |
setFontColor(int fontColor)
Sets a font color
|
UI2dComponent |
setHeight(float height)
Sets the height of this component
|
UI2dComponent |
setLeftMargin(float leftMargin)
Sets the left margin around this object when inside a UI2dContainer with layout
|
UI2dComponent |
setMappable(boolean mappable)
Sets whether this component can ever be used for mapping control
|
UI2dComponent |
setMargin(float margin)
Sets the margins around this object when inside of a UI2dContainer with layout
|
UI2dComponent |
setMargin(float yMargin,
float xMargin)
Sets the margins around this object when inside of a UI2dContainer with layout
|
UI2dComponent |
setMargin(float topMargin,
float rightMargin,
float bottomMargin,
float leftMargin)
Sets the margins around this object when inside of a UI2dContainer with layout
|
UI2dComponent |
setPosition(float[] position)
Sets position based upon an array of either 2 coordinates or 4
|
UI2dComponent |
setPosition(float x,
float y)
Set the position of this component in its parent coordinate space
|
UI2dComponent |
setPosition(float x,
float y,
float width,
float height)
Set the position of this component in its parent coordinate space
|
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
|
UI2dComponent |
setRightMargin(float rightMargin)
Sets the right margin around this object when inside a UI2dContainer with layout
|
UI2dComponent |
setSize(float width,
float height)
Set the dimensions of this component
|
UI2dComponent |
setTextAlignment(int horizontalAlignment)
Sets the text alignment
|
UI2dComponent |
setTextAlignment(int horizontalAlignment,
int verticalAlignment)
Sets the text alignment of this component
|
UI2dComponent |
setTextOffset(float textOffsetX,
float textOffsetY)
Sets an offset for text rendering position relative to alignment.
|
UI2dComponent |
setTopMargin(float topMargin)
Sets the top margin around this object when inside a UI2dContainer with layout
|
UI2dComponent |
setVisible(boolean visible)
Set the visibility state of this component
|
UI2dComponent |
setWidth(float width)
Sets the width of this component
|
UI2dComponent |
setX(float x)
Set the position of this component in its parent coordinate space
|
UI2dComponent |
setY(float y)
Set the position of this component in its parent coordinate space
|
addLoopTask, beginDraw, blur, bringToFront, consumeKeyEvent, consumeMousePress, consumeMouseWheelEvent, endDraw, focus, getDescription, getFocusedChild, getLX, getUI, hasDirectFocus, hasFocus, isVisible, keyEventConsumed, loop, mousePressConsumed, onBlur, onDraw, onFocus, onUIResize, removeLoopTask, toggleVisible
onKeyPressed, onKeyReleased, onKeyTyped, onMouseClicked, onMouseDragged, onMouseMoved, onMouseOut, onMouseOver, onMousePressed, onMouseReleased, onMouseWheel
protected float x
protected float y
protected float width
protected float height
protected float topMargin
protected float rightMargin
protected float bottomMargin
protected float leftMargin
protected int textAlignHorizontal
protected int textAlignVertical
protected float textOffsetX
protected float textOffsetY
protected UI2dComponent()
protected UI2dComponent(float x, float y, float width, float height)
public UI2dComponent setDescription(String description)
setDescription
in class UIObject
public final float getX()
public final float getY()
public final float getWidth()
public final float getHeight()
public boolean contains(float x, float y)
public UI2dComponent setVisible(boolean visible)
setVisible
in class UIObject
visible
- Whether this should be visiblepublic UI2dComponent setX(float x)
x
- X-position in parents coordinate spacepublic UI2dComponent setY(float y)
y
- Y-position in parents coordinate spacepublic UI2dComponent setPosition(float x, float y)
x
- X-position in parents coordinate spacey
- Y-position in parents coordinate spacepublic UI2dComponent setPosition(float[] position)
position
- length 2 array or x/y, or length 4 of x/y/width/heightpublic UI2dComponent setPosition(float x, float y, float width, float height)
x
- X-position in parents coordinate spacey
- Y-position in parents coordinate spacewidth
- Width of objectheight
- Height of objectpublic UI2dComponent setPosition(UIObject parent, float offsetX, float offsetY)
parent
- Parent objectoffsetX
- X offsetoffsetY
- Y offsetpublic UI2dComponent setHeight(float height)
height
- Heightpublic UI2dComponent setWidth(float width)
width
- Width of the componentpublic UI2dComponent setSize(float width, float height)
width
- Width of componentheight
- Height of componentpublic UI2dComponent setMargin(float margin)
margin
- Margin on all sidespublic UI2dComponent setMargin(float yMargin, float xMargin)
yMargin
- Vertical marginsxMargin
- Horizontal marginspublic UI2dComponent setTopMargin(float topMargin)
topMargin
- Top marginpublic UI2dComponent setBottomMargin(float bottomMargin)
bottomMargin
- Bottom marginpublic UI2dComponent setLeftMargin(float leftMargin)
leftMargin
- Left marginpublic UI2dComponent setRightMargin(float rightMargin)
rightMargin
- Right marginpublic UI2dComponent setMargin(float topMargin, float rightMargin, float bottomMargin, float leftMargin)
topMargin
- Top marginrightMargin
- Right marginbottomMargin
- Bottom marginleftMargin
- Left marginprotected void onResize()
public boolean hasBackground()
public int getBackgroundColor()
public UI2dComponent setBackground(boolean hasBackground)
hasBackground
- true or falsepublic UI2dComponent setBackgroundColor(int backgroundColor)
backgroundColor
- colorpublic UI2dComponent setFocusBackground(boolean focusBackground)
focusBackground
- Focus background colorpublic UI2dComponent setFocusBackgroundColor(int focusBackgroundColor)
focusBackgroundColor
- Colorpublic boolean hasBorder()
public int getBorderColor()
public int getBorderWeight()
public UI2dComponent setBorder(boolean hasBorder)
hasBorder
- true or falsepublic UI2dComponent setBorderColor(int borderColor)
borderColor
- colorpublic UI2dComponent setBorderWeight(int borderWeight)
borderWeight
- weightpublic UI2dComponent setBorderRounding(int borderRounding)
public int getBorderRounding()
public UI2dComponent setFocusCorners(boolean focusCorners)
public UI2dComponent setFocusColor(int focusColor)
public boolean hasFont()
public PFont getFont()
public UI2dComponent setFont(PFont font)
font
- Fontpublic boolean hasFontColor()
public int getFontColor()
public UI2dComponent setFontColor(boolean hasFontColor)
hasFontColor
- true or falsepublic UI2dComponent setFontColor(int fontColor)
fontColor
- colorpublic UI2dComponent setTextAlignment(int horizontalAlignment)
horizontalAlignment
- From PConstants LEFT/RIGHT/CENTERpublic UI2dComponent setTextOffset(float textOffsetX, float textOffsetY)
textOffsetX
- Text position x offsettextOffsetY
- Text position y offsetpublic UI2dComponent setTextAlignment(int horizontalAlignment, int verticalAlignment)
horizontalAlignment
- From PConstants LEFT/RIGHT/CENTERverticalAlignment
- From PConstants TOP/BOTTOM/BASELINE/CENTERpublic static String clipTextToWidth(PGraphics pg, String str, float width)
pg
- PGraphicsstr
- Stringwidth
- Width to fit inpublic static String breakTextToWidth(PGraphics pg, String str, float width)
pg
- PGraphicsstr
- Stringwidth
- Width to fit it inpublic UI2dComponent setMappable(boolean mappable)
mappable
- Whether this component is a mappable controlprotected boolean isMappable()
public UI2dComponent removeFromContainer()
public UIObject getParent()
public UI2dComponent getPrevSibling()
public UI2dComponent getNextSibling()
public UI2dContainer getContainer()
public final UI2dComponent addToContainer(UIContainer container)
container
- Container to place inpublic UI2dComponent addToContainer(UIContainer container, int index)
container
- Container to place inindex
- At which index to place this object in parent containerpublic UI2dComponent setContainerIndex(int index)
index
- Desired indexpublic final UI2dComponent redraw()
protected int getFocusColor(UI ui)
protected int getFocusSize()
protected void drawFocus(UI ui, PGraphics pg)
ui
- UIpg
- PGraphicsLX library by Mark C. Slee. © 2012-2020