TGUI  0.8-dev

Label widget. More...

#include <Label.hpp>

Inheritance diagram for tgui::Label:
tgui::ClickableWidget tgui::Widget tgui::Transformable tgui::SignalWidgetBase

Public Types

enum  HorizontalAlignment { HorizontalAlignment::Left, HorizontalAlignment::Center, HorizontalAlignment::Right }
 The horizontal text alignment. More...
 
enum  VerticalAlignment { VerticalAlignment::Top, VerticalAlignment::Center, VerticalAlignment::Bottom }
 The vertical text alignment. More...
 
typedef std::shared_ptr< LabelPtr
 Shared widget pointer.
 
typedef std::shared_ptr< const LabelConstPtr
 Shared constant widget pointer.
 
- Public Types inherited from tgui::ClickableWidget
typedef std::shared_ptr< ClickableWidgetPtr
 Shared widget pointer.
 
typedef std::shared_ptr< const ClickableWidgetConstPtr
 Shared constant widget pointer.
 
- Public Types inherited from tgui::Widget
typedef std::shared_ptr< WidgetPtr
 Shared widget pointer.
 
typedef std::shared_ptr< const WidgetConstPtr
 Shared constant widget pointer.
 

Public Member Functions

LabelRenderergetRenderer () const
 Returns the renderer, which gives access to functions that determine how the widget is displayed. More...
 
virtual void setSize (const Layout2d &size) override
 Changes the area of the text that will be drawn. More...
 
void setText (const sf::String &text)
 Changes the text. More...
 
const sf::String & getText () const
 Returns the text. More...
 
void setTextSize (unsigned int size)
 Changes the character size of the text. More...
 
unsigned int getTextSize () const
 Returns the character size of the text. More...
 
void setHorizontalAlignment (HorizontalAlignment alignment)
 Changes the horizontal text alignment. More...
 
HorizontalAlignment getHorizontalAlignment () const
 Gets the current horizontal text alignment. More...
 
void setVerticalAlignment (VerticalAlignment alignment)
 Changes the vertical text alignment. More...
 
VerticalAlignment getVerticalAlignment () const
 Gets the current vertical text alignment. More...
 
void setAutoSize (bool autoSize)
 Changes whether the label is auto-sized or not. More...
 
bool getAutoSize () const
 Returns whether the label is auto-sized or not. More...
 
void setMaximumTextWidth (float maximumWidth)
 Changes the maximum width that the text will have when auto-sizing. More...
 
float getMaximumTextWidth () const
 Returns the maximum width that the text will have. More...
 
virtual void draw (sf::RenderTarget &target, sf::RenderStates states) const override
 Draw the widget to a render target. More...
 
- Public Member Functions inherited from tgui::ClickableWidget
 ClickableWidget ()
 Default constructor.
 
- Public Member Functions inherited from tgui::Widget
 Widget ()
 Default constructor.
 
 Widget (const Widget &)
 Copy constructor.
 
 Widget (Widget &&)
 Move constructor.
 
 ~Widget ()
 Destructor.
 
Widgetoperator= (const Widget &)
 Overload of copy assignment operator.
 
Widgetoperator= (Widget &&)
 Move assignment.
 
void setRenderer (std::shared_ptr< RendererData > rendererData)
 Sets a new renderer for the widget. The renderer determines how the widget looks. More...
 
WidgetRenderergetRenderer () const
 Returns the renderer, which gives access to functions that determine how the widget is displayed. More...
 
virtual void setPosition (const Layout2d &position) override
 sets the position of the widget More...
 
virtual sf::Vector2f getAbsolutePosition () const
 Get the absolute position of the widget instead of the relative position to its parent. More...
 
virtual sf::Vector2f getWidgetOffset () const
 Returns the distance between the position where the widget is drawn and where the widget is placed. More...
 
virtual void show ()
 Shows the widget. More...
 
virtual void showWithEffect (ShowAnimationType type, sf::Time duration)
 Shows the widget by introducing it with an animation. More...
 
virtual void hide ()
 Hides the widget. More...
 
virtual void hideWithEffect (ShowAnimationType type, sf::Time duration)
 Hides the widget by making it leave with an animation. More...
 
bool isVisible () const
 Returns true when the widget is visible. More...
 
virtual void enable ()
 Enables the widget. More...
 
virtual void disable ()
 Disables the widget. More...
 
bool isEnabled () const
 Returns true when the widget is enabled. More...
 
virtual void focus ()
 Focus the widget. More...
 
virtual void unfocus ()
 Unfocus the widget. More...
 
bool isFocused () const
 Returns true when the widget is focused and false otherwise. More...
 
const std::string & getWidgetType () const
 Returns the type of the widget. More...
 
ContainergetParent () const
 Returns a pointer to the parent widget. More...
 
virtual void moveToFront ()
 Places the widget before all other widgets.
 
virtual void moveToBack ()
 Places the widget behind all other widgets.
 
void setToolTip (Widget::Ptr toolTip)
 Sets the tool tip that should be displayed when hovering over the widget. More...
 
Widget::Ptr getToolTip ()
 Returns the tool tip that is displayed when hovering over the widget. More...
 
- Public Member Functions inherited from tgui::Transformable
virtual ~Transformable ()=default
 Virtual destructor.
 
void setPosition (const Layout &x, const Layout &y)
 Sets the position of the widget. More...
 
sf::Vector2f getPosition () const
 Gets the position of the widget. More...
 
void move (const Layout2d &offset)
 Moves the widget by a given offset. More...
 
void move (const Layout &x, const Layout &y)
 Moves the widget by a given offset. More...
 
void setSize (const Layout &width, const Layout &height)
 Changes the size of the widget. More...
 
virtual sf::Vector2f getSize () const
 Returns the size of the widget. More...
 
virtual sf::Vector2f getFullSize () const
 Returns the entire size that the widget is using. More...
 
void scale (const Layout2d &factors)
 Scales the widget. More...
 
void scale (const Layout &x, const Layout &y)
 Scales the widget. More...
 
- Public Member Functions inherited from tgui::SignalWidgetBase
virtual ~SignalWidgetBase ()
 Virtual destructor.
 
template<typename Func , typename... Args>
unsigned int connect (const std::string &signalNames, Func func, Args... args)
 Connects a signal handler function to one or more signals. More...
 
template<typename Func , typename... Args>
unsigned int connectEx (const std::string &signalName, Func func, Args... args)
 Connects a signal handler function to one or more signals. More...
 
void disconnect (unsigned int id)
 Disconnects a connection. More...
 
void disconnectAll (const std::string &signalName)
 Disconnects all connections from a certain signal. More...
 
void disconnectAll ()
 Disconnects all connections from a all signals.
 

Static Public Member Functions

static Label::Ptr create (sf::String text="")
 Creates a new label widget. More...
 
static Label::Ptr copy (Label::ConstPtr label)
 Makes a copy of another label. More...
 
- Static Public Member Functions inherited from tgui::ClickableWidget
static ClickableWidget::Ptr create (Layout2d size={100, 100})
 Creates a new clickable widget. More...
 
static ClickableWidget::Ptr copy (ClickableWidget::ConstPtr widget)
 Makes a copy of another clickable widget. More...
 

Protected Member Functions

virtual void rendererChanged (const std::string &property) override
 Function called when one of the properties of the renderer is changed. More...
 
virtual Widget::Ptr clone () const override
 Makes a copy of the widget if you don't know its exact type. More...
 
- Protected Member Functions inherited from tgui::Widget
virtual void mouseEnteredWidget ()
 This function is called when the mouse enters the widget.
 
virtual void mouseLeftWidget ()
 This function is called when the mouse leaves the widget.
 

Detailed Description

Label widget.

Signals:

  • DoubleClicked (double left clicked on top of the label)
    • Optional parameter sf::String: text of the label
    • Uses Callback member 'text'
  • Inherited signals from ClickableWidget

Member Enumeration Documentation

§ HorizontalAlignment

The horizontal text alignment.

Enumerator
Left 

Put the text on the left side (default)

Center 

Center the text horizontally.

Right 

Put the text on the right side (e.g. for numbers)

§ VerticalAlignment

The vertical text alignment.

Enumerator
Top 

Put the text at the top (default)

Center 

Center the text vertically.

Bottom 

Put the text at the bottom.

Member Function Documentation

§ clone()

virtual Widget::Ptr tgui::Label::clone ( ) const
inlineoverrideprotectedvirtual

Makes a copy of the widget if you don't know its exact type.

This function should only be used when you don't know the type of the widget. If you know what kind of widget you are copying, you should use the copy function.

Returns
Copy of the widget

Reimplemented from tgui::ClickableWidget.

§ copy()

static Label::Ptr tgui::Label::copy ( Label::ConstPtr  label)
static

Makes a copy of another label.

Parameters
labelThe other label
Returns
The new label

§ create()

static Label::Ptr tgui::Label::create ( sf::String  text = "")
static

Creates a new label widget.

Parameters
textThe text to display
Returns
The new label

§ draw()

virtual void tgui::Label::draw ( sf::RenderTarget &  target,
sf::RenderStates  states 
) const
overridevirtual

Draw the widget to a render target.

Parameters
targetRender target to draw to
statesCurrent render states

Reimplemented from tgui::ClickableWidget.

§ getAutoSize()

bool tgui::Label::getAutoSize ( ) const

Returns whether the label is auto-sized or not.

Returns
Is the size of the label changed when the text changes?

§ getHorizontalAlignment()

HorizontalAlignment tgui::Label::getHorizontalAlignment ( ) const

Gets the current horizontal text alignment.

Returns
Horizontal text alignment

§ getMaximumTextWidth()

float tgui::Label::getMaximumTextWidth ( ) const

Returns the maximum width that the text will have.

Returns
  • The width of the label minus the padding when a specific size was set.
  • The maximum text width when auto-sizing and a maximum was set.
  • 0 when auto-sizing but there is no maximum width.

§ getRenderer()

LabelRenderer* tgui::Label::getRenderer ( ) const
inline

Returns the renderer, which gives access to functions that determine how the widget is displayed.

Returns
Temporary pointer to the renderer

§ getText()

const sf::String& tgui::Label::getText ( ) const

Returns the text.

Returns
Text that is currently used

§ getTextSize()

unsigned int tgui::Label::getTextSize ( ) const

Returns the character size of the text.

Returns
The current text size

§ getVerticalAlignment()

VerticalAlignment tgui::Label::getVerticalAlignment ( ) const

Gets the current vertical text alignment.

Returns
Vertical text alignment

§ rendererChanged()

virtual void tgui::Label::rendererChanged ( const std::string &  property)
overrideprotectedvirtual

Function called when one of the properties of the renderer is changed.

Parameters
propertyLowercase name of the property that was changed

Reimplemented from tgui::Widget.

§ setAutoSize()

void tgui::Label::setAutoSize ( bool  autoSize)

Changes whether the label is auto-sized or not.

Parameters
autoSizeShould the size of the label be changed when the text changes?

When the label is in auto-size mode, the width and height of the label will be changed to fit the text. Otherwise, only the part defined by the size will be visible.

The label is auto-sized by default.

§ setHorizontalAlignment()

void tgui::Label::setHorizontalAlignment ( HorizontalAlignment  alignment)

Changes the horizontal text alignment.

Parameters
alignmentThe new horizontal text alignment

By default the text is aligned to the left.

§ setMaximumTextWidth()

void tgui::Label::setMaximumTextWidth ( float  maximumWidth)

Changes the maximum width that the text will have when auto-sizing.

Parameters
maximumWidthThe new maximum text width

This property is ignored when an exact size has been given. Pass 0 to this function to disable the maximum.

When the text is auto-sizing then the text will be split over several lines when its width would exceed the value passed to this function.

§ setSize()

virtual void tgui::Label::setSize ( const Layout2d size)
overridevirtual

Changes the area of the text that will be drawn.

Parameters
sizeSize of the part to draw

Only the part of the text that lies within the size will be drawn.

When a background color is set, the drawn background will have this size. So setting a size that is bigger than the text will result in a bigger area being filled.

When this function is called, the label will no longer be auto-sizing.

See also
setAutoSize

Reimplemented from tgui::Widget.

§ setText()

void tgui::Label::setText ( const sf::String &  text)

Changes the text.

Parameters
textThe new text

When the text is auto-sized (default), then the size of the label will be changed to fit the whole text.

See also
setAutoSize

§ setTextSize()

void tgui::Label::setTextSize ( unsigned int  size)

Changes the character size of the text.

Parameters
sizeThe new text size

§ setVerticalAlignment()

void tgui::Label::setVerticalAlignment ( VerticalAlignment  alignment)

Changes the vertical text alignment.

Parameters
alignmentThe new vertical text alignment

By default the text is aligned to the top.


The documentation for this class was generated from the following file: