public class SwapContainer<T extends java.lang.Enum<T>> extends AbstractWidget<SwapContainer<T>>
hasInteractivity, hb, isHovered, leftClickStarted, onLeftClick, onMouseEnter, onMouseLeave, onRightClick, rightClickStarted
Constructor and Description |
---|
SwapContainer(java.lang.Class<T> clz) |
Modifier and Type | Method and Description |
---|---|
SwapContainer<T> |
anchoredAt(float x,
float y,
AnchorPosition anchorPosition,
InterpolationSpeed movementSpeed)
Moves the widget towards a specific spot.
|
SwapContainer<T> |
forceChildAnchors(AnchorPosition forcedChildAnchorPosition) |
float |
getContentHeight()
The internal content height of the widget (excludes margins).
|
float |
getContentWidth()
The internal content width of the widget (excludes margins).
|
void |
hide() |
SwapContainer<T> |
nextView() |
protected void |
renderWidget(com.badlogic.gdx.graphics.g2d.SpriteBatch sb)
Custom widgets should implement this method for rendering.
|
void |
show() |
SwapContainer<T> |
updateAnchorAt(T view,
AnchorPosition newAnchor) |
protected void |
updateWidget()
Required for interactive components.
|
SwapContainer<T> |
withDefaultChildAnchor(AnchorPosition defaultChildAnchor) |
SwapContainer<T> |
withView(T choice) |
SwapContainer<T> |
withWidget(T option,
AbstractWidget widget) |
SwapContainer<T> |
withWidget(T option,
AbstractWidget widget,
boolean activeView) |
SwapContainer<T> |
withWidget(T view,
AbstractWidget widget,
boolean activeView,
AnchorPosition childAnchor) |
anchoredAt, anchoredAtClamped, anchoredAtClamped, anchoredCenteredOnMouse, anchoredCenteredOnMouse, anchoredCenteredOnMouseClamped, anchoredCenteredOnMouseClamped, anchoredCenteredOnScreen, anchoredCenteredOnScreen, cancelMovementQueue, cancelMovementQueueForAllChildren, delayedTranslate, getBottom, getContentBottom, getContentCenterX, getContentCenterY, getContentLeft, getContentRight, getContentTop, getHeight, getLeft, getRight, getTop, getWidth, initializeInteractivity, isMouseInBounds, isMouseInContentBounds, leftMouseClick, mouseEnter, mouseLeave, onLeftClick, onMouseEnter, onMouseLeave, onRightClick, refreshAnchor, render, renderTopLevel, resolveMovementQueue, rightMouseClick, scaleHitboxToContent, setAllDelayedMovement, setChildrenDelayedMovement, toString, translate, update, updateInteractivity, withMargins, withMargins, withMargins
public SwapContainer(java.lang.Class<T> clz)
public SwapContainer<T> withWidget(T option, AbstractWidget widget)
public SwapContainer<T> withWidget(T option, AbstractWidget widget, boolean activeView)
public SwapContainer<T> withWidget(T view, AbstractWidget widget, boolean activeView, AnchorPosition childAnchor)
public SwapContainer<T> withDefaultChildAnchor(AnchorPosition defaultChildAnchor)
public SwapContainer<T> forceChildAnchors(AnchorPosition forcedChildAnchorPosition)
public SwapContainer<T> updateAnchorAt(T view, AnchorPosition newAnchor)
public SwapContainer<T> withView(T choice)
public SwapContainer<T> nextView()
public SwapContainer<T> anchoredAt(float x, float y, AnchorPosition anchorPosition, InterpolationSpeed movementSpeed)
AbstractWidget
Moves the widget towards a specific spot. The anchorPosition
defines the point on the widget that will be placed at the position (x, y)
.
For example, anchoredAt(100, 200, AnchorPosition.LEFT_BOTTOM, InterpolationSpeed.FAST)
will set the bottom-left corner of the widget to 100 pixels from the left side of the screen and 200 pixels from the bottom of the screen. The widget then renders up and to the right of this point since we anchored at an AnchorPosition.LEFT_BOTTOM
. As a second example, using AnchorPosition.CENTER
ensures that (x, y)
will be the center of the widget.
The interpolation speed movementSpeed
determines how quickly the widget moves to the target location. Using a speed other than InterpolationSpeed.INSTANT
makes the widget move towards the desired position over the next few frames in a smoothly animated manner. For convenience since instant moving is often the desired effect, see AbstractWidget.anchoredAt(float, float, AnchorPosition)
.
Note: you should always anchor at least once before rendering. For more dynamic widgets that move a lot (e.g. a tooltip dependent on the mouse cursor location using InputHelper.mX
and InputHelper.mY
), a general pattern is to call anchoredAt
right before rendering in your main render function, e.g.:
widget.anchoredAt(x, y, AnchorPosition.CENTER, InterpolationSpeed.INSTANT)
.render(sb);
anchoredAt
in class AbstractWidget<SwapContainer<T extends java.lang.Enum<T>>>
x
- the x position in pixels from the left edge of the screeny
- the y position in pixels from the bottom edge of the screenanchorPosition
- what piece of the widget will be moved to (x, y)
movementSpeed
- how quickly the widget will move towards the desired positionAbstractWidget.anchoredAt(float, float, AnchorPosition)
,
AbstractWidget.anchoredAtClamped(float, float, AnchorPosition, float)
,
AbstractWidget.anchoredAtClamped(float, float, AnchorPosition, InterpolationSpeed, float)
public float getContentWidth()
AbstractWidget
getContentWidth
in class AbstractWidget<SwapContainer<T extends java.lang.Enum<T>>>
AbstractWidget.getWidth()
,
AbstractWidget.getContentHeight()
public float getContentHeight()
AbstractWidget
getContentHeight
in class AbstractWidget<SwapContainer<T extends java.lang.Enum<T>>>
AbstractWidget.getHeight()
,
AbstractWidget.getContentWidth()
protected void renderWidget(com.badlogic.gdx.graphics.g2d.SpriteBatch sb)
AbstractWidget
Custom widgets should implement this method for rendering. Use the inner content positions (e.g. AbstractWidget.getContentLeft()
, AbstractWidget.getContentWidth()
, etc.) to determine any position information necessary for rendering at a specific location. If the library is used as intended, these content locations should be accurate to where the widget needs to be rendered, as they reflect the most up to date location set by an anchoredAt call (this automatically will be interpolated if the anchorAt move is set to occur over several frames).
Note: you NEED to revert any changes you make to the SpriteBatch (e.g. setting a shader, changing the perspective matrix, etc.) by the time this function returns, as the SpriteBatch will be reused for rendering other widgets which will not expect those changes. You also don't technically need to render to this particular SpriteBatch (e.g. you can render to your own batch if you know what you're doing), as long as you follow the general intent of this function to render the widget.
renderWidget
in class AbstractWidget<SwapContainer<T extends java.lang.Enum<T>>>
sb
- the SpriteBatch the widget should be rendered onAbstractWidget.renderTopLevel(SpriteBatch)
protected void updateWidget()
AbstractWidget
update()
on all children. For widgets that require some sort of updates each frame, you can do so here.updateWidget
in class AbstractWidget<SwapContainer<T extends java.lang.Enum<T>>>
public void show()
show
in class AbstractWidget<SwapContainer<T extends java.lang.Enum<T>>>
public void hide()
hide
in class AbstractWidget<SwapContainer<T extends java.lang.Enum<T>>>