public final class GuiTitleBar
extends net.risingworld.api.gui.GuiPanel
A title bar is made of a title text and of an optional close button.
Important: due to the way Rising World plug-ins are loaded, this class cannot instantiated or used in any way from within the onEnable() method of a plug-in, as it is impossible to be sure that, at that moment, the RWGui plug-in has already been loaded.
The first moment one can be sure that all plug-ins have been loaded, and it is safe to use this class, is when (or after) the first player connects to the server (either dedicated or local).
Modifier and Type | Field and Description |
---|---|
static int |
TITLEBAR_HEIGHT |
Constructor and Description |
---|
GuiTitleBar(net.risingworld.api.gui.GuiElement parent,
java.lang.String titleText,
boolean hasCancelButton)
Creates a new title bar as a child of an existing GuiElement (typically
a GuiPanel).
|
Modifier and Type | Method and Description |
---|---|
void |
addToPlayer(net.risingworld.api.objects.Player player)
Displays the title bar on the screen of a player.
|
protected void |
free()
Releases all the resources used by the title bar.
|
int |
getMinWidth()
Returns a minimal width (in pixels) suitable to contain the whole title bar.
|
protected java.lang.String |
getTitleText()
Returns the current title text.
|
boolean |
isCancelButton(net.risingworld.api.gui.GuiElement element)
Checks if the given element is the cancel button or not.
|
void |
relayout()
Updates the width and the position of the title bar to match the current
width and height of the parent GuiElement.
|
void |
removeFromPlayer(net.risingworld.api.objects.Player player)
Removes the title bar from the screen of a player.
|
addChild, destroy, equals, getAlpha, getBorderColor, getBorderThickness, getColor, getHeight, getHoverColor, getID, getParent, getParentID, getPivot, getPositionX, getPositionY, getWidth, hashCode, isRelativeBorderThickness, isRelativePosition, isRelativeSize, isVisible, refresh, removeChild, removeFromParent, setAlpha, setBorderColor, setBorderColor, setBorderThickness, setColor, setColor, setPivot, setPosition, setSize, setVisible
public static final int TITLEBAR_HEIGHT
public GuiTitleBar(net.risingworld.api.gui.GuiElement parent, java.lang.String titleText, boolean hasCancelButton)
The bar is added to the given parent, is given a specific background colour and pivot position (TopLeft); its title text is given a specific font colour and size.
If the close button is required, the image element for it is also created.
parent
- the GuiElement to which to add the title bartitleText
- the text of the titlehasCancelButton
- whether the title bar should have a cancel
button or not.public boolean isCancelButton(net.risingworld.api.gui.GuiElement element)
element
- the GuiElement to check.protected java.lang.String getTitleText()
protected void free()
After calling this method, the title bar cannot be used any longer.
public int getMinWidth()
public void relayout()
To be used after the parent GuiElement has reached its definitive width and height, typically right before displaying the parent to a player.
The title bar is placed at the top of the parent and inset a few pixels from the parent left, top and right border.
public void addToPlayer(net.risingworld.api.objects.Player player)
To be used instead of player.addGuiElement(titleBar), as this method manages the addition of all the elements making the bar up at once.
player
- the player to show this title bar to.public void removeFromPlayer(net.risingworld.api.objects.Player player)
To be used instead of player.removeGuiElement(titleBar), as this method removes all the elements making the bar up at once.
player
- the player to remove this title bar from.