Gamedev Framework (gf)  0.17.0
A C++14 framework for 2D games
Public Member Functions | Protected Member Functions | List of all members
gf::TextWidget Class Reference

A simple text widget. More...

#include <gf/Widgets.h>

Inheritance diagram for gf::TextWidget:
Inheritance graph
[legend]

Public Member Functions

 TextWidget (std::string text, Font &font, unsigned characterSize=30)
 Constructor. More...
 
void draw (RenderTarget &target, const RenderStates &states) override
 Draw the object to a render target. More...
 
bool contains (Vector2f coords) override
 Check if the widget contains the coordinates. More...
 
void setString (std::string string)
 Set the text's string. More...
 
const std::string & getString () const
 Get the text's string. More...
 
void setAlignment (Alignment align)
 Set the alignement of the text. More...
 
Alignment getAlignment () const
 Get the alignment of the text. More...
 
void setParagraphWidth (float paragraphWidth)
 Set the paragraph width for aligned text. More...
 
float getParagraphWidth () const
 Get the paragraph width. More...
 
void setLineSpacing (float spacingFactor)
 Set the line spacing factor. More...
 
float getLineSpacing () const
 Get the size of the line spacing factor. More...
 
void setLetterSpacing (float spacingFactor)
 Set the letter spacing factor. More...
 
float getLetterSpacing () const
 Get the size of the letter spacing factor. More...
 
void setCharacterSize (unsigned characterSize)
 Set the character size. More...
 
unsigned getCharacterSize () const
 Get the character size. More...
 
void setTextOutlineThickness (float thickness)
 Set the thickness of the outline. More...
 
void setDisabledTextColor (const Color4f &color)
 Set the text's color of the button when disabled. More...
 
void setDisabledTextOutlineColor (const Color4f &color)
 Set the outline's color of the button when disabled. More...
 
void setDefaultTextColor (const Color4f &color)
 Set the text's color of the button when it's in a normal state. More...
 
void setDefaultTextOutlineColor (const Color4f &color)
 Set the outline's color of the button when it's in a normal state. More...
 
void setSelectedTextColor (const Color4f &color)
 Set the text's color of the button when selected. More...
 
void setSelectedTextOutlineColor (const Color4f &color)
 Set the outline's color of the button when selected. More...
 
RectF getLocalBounds () const
 Get the local bounding rectangle of the entity. More...
 
void setAnchor (Anchor anchor)
 Set the anchor origin of the entity. More...
 
- Public Member Functions inherited from gf::Widget
 Widget ()
 Constructor. More...
 
void setDisabled ()
 Disable the widget. More...
 
bool isDisabled () const noexcept
 Check if the widget is disabled. More...
 
void setDefault ()
 Set the widget to it's default state. More...
 
bool isDefault () const noexcept
 Check if the widget is in default state. More...
 
void setSelected ()
 Select the widget. More...
 
bool isSelected () const
 Check if the widget is selected. More...
 
void setState (WidgetState state)
 Set the state of the widget directly. More...
 
WidgetState getState () const noexcept
 Get the state of the widget. More...
 
void setCallback (std::function< void()> callback)
 Set the callback of the widget. More...
 
void triggerCallback ()
 Execute the callback function. More...
 
- Public Member Functions inherited from gf::Transformable
 Transformable ()
 Default constructor. More...
 
void setOrigin (Vector2f origin)
 Set the local origin of the object. More...
 
Vector2f getOrigin () const
 Get the local origin of the object. More...
 
void setPosition (Vector2f position)
 Set the position of the object. More...
 
Vector2f getPosition () const
 Get the position of the object. More...
 
void move (Vector2f offset)
 Move the object by a given offset. More...
 
void setRotation (float angle)
 Set the orientation of the object. More...
 
float getRotation () const
 Get the orientation of the object. More...
 
void rotate (float angle)
 Rotate the object. More...
 
void setScale (Vector2f factors)
 Set the scale factors of the object. More...
 
void setScale (float factor)
 Set the scale factor of the object. More...
 
Vector2f getScale () const
 Get the current scale of the object. More...
 
void scale (Vector2f factors)
 Scale the object. More...
 
void scale (float factor)
 Scale the object. More...
 
Matrix3f getTransform () const
 Get the combined transform of the object. More...
 
Matrix3f getInverseTransform () const
 Get the inverse of the combined transform of the object. More...
 
- Public Member Functions inherited from gf::Drawable
virtual ~Drawable ()
 Virtual desctructor. More...
 

Protected Member Functions

void updateCurrentStateColors ()
 
void updateColors (Color4f textColor, Color4f outlineColor)
 
void updateGeometry ()
 
void onStateChanged () override
 Function called when the state changes. More...
 
BasicTextgetText ()
 
- Protected Member Functions inherited from gf::Widget
virtual void triggered ()
 Function called when the callback is triggered. More...
 
- Protected Member Functions inherited from gf::Transformable
void setOriginFromAnchorAndBounds (Anchor anchor, const RectF &bounds)
 Set the origin from an anchor and bounds. More...
 

Detailed Description

A simple text widget.

See also
gf::Text

Constructor & Destructor Documentation

◆ TextWidget()

gf::TextWidget::TextWidget ( std::string  text,
Font font,
unsigned  characterSize = 30 
)

Constructor.

Parameters
textA text to convert to a widget.
fontFont used to draw the text
characterSizeBase size of characters, in pixels

Member Function Documentation

◆ contains()

bool gf::TextWidget::contains ( Vector2f  coords)
overridevirtual

Check if the widget contains the coordinates.

Parameters
coordsThe coordinates to check
Returns
True if the coordinates are inside the widget

Implements gf::Widget.

Reimplemented in gf::TextButtonWidget.

◆ draw()

void gf::TextWidget::draw ( RenderTarget target,
const RenderStates states 
)
overridevirtual

Draw the object to a render target.

This is a pure virtual function that has to be implemented by the derived class to define how the drawable should be drawn.

Parameters
targetRender target to draw to
statesCurrent render states

Implements gf::Drawable.

Reimplemented in gf::TextButtonWidget.

◆ getAlignment()

Alignment gf::TextWidget::getAlignment ( ) const

Get the alignment of the text.

Returns
Current alignment of the text
See also
setAlignment()

◆ getCharacterSize()

unsigned gf::TextWidget::getCharacterSize ( ) const

Get the character size.

Returns
Size of the characters, in pixels
See also
setCharacterSize()

◆ getLetterSpacing()

float gf::TextWidget::getLetterSpacing ( ) const

Get the size of the letter spacing factor.

Returns
The size of the letter spacing factor
See also
setLetterSpacing()

◆ getLineSpacing()

float gf::TextWidget::getLineSpacing ( ) const

Get the size of the line spacing factor.

Returns
The size of the line spacing factor
See also
setLineSpacing

◆ getLocalBounds()

RectF gf::TextWidget::getLocalBounds ( ) const
inline

Get the local bounding rectangle of the entity.

The returned rectangle is in local coordinates, which means that it ignores the transformations (translation, rotation, scale, ...) that are applied to the entity. In other words, this function returns the bounds of the entity in the entity's coordinate system.

Returns
Local bounding rectangle of the entity

◆ getParagraphWidth()

float gf::TextWidget::getParagraphWidth ( ) const

Get the paragraph width.

Returns
Paragraph width in pixels
See also
setParagraphWidth()

◆ getString()

const std::string& gf::TextWidget::getString ( ) const

Get the text's string.

The text string is in UTF-8 format.

Returns
Text's string
See also
setString()

◆ getText()

BasicText& gf::TextWidget::getText ( )
inlineprotected

◆ onStateChanged()

void gf::TextWidget::onStateChanged ( )
overrideprotectedvirtual

Function called when the state changes.

Reimplemented from gf::Widget.

Reimplemented in gf::TextButtonWidget.

◆ setAlignment()

void gf::TextWidget::setAlignment ( Alignment  align)

Set the alignement of the text.

By default, the text is not aligned.

Parameters
alignNew alignement
See also
getAlignment()

◆ setAnchor()

void gf::TextWidget::setAnchor ( Anchor  anchor)

Set the anchor origin of the entity.

Compute the origin of the entity based on the local bounds and the specified anchor. Internally, this function calls Transformable::setOrigin().

Parameters
anchorThe anchor of the entity
See also
getLocalBounds(), Transformable::setOrigin()

◆ setCharacterSize()

void gf::TextWidget::setCharacterSize ( unsigned  characterSize)

Set the character size.

Parameters
characterSizeNew character size, in pixels

◆ setDefaultTextColor()

void gf::TextWidget::setDefaultTextColor ( const Color4f color)

Set the text's color of the button when it's in a normal state.

Parameters
colorThe new color to apply

◆ setDefaultTextOutlineColor()

void gf::TextWidget::setDefaultTextOutlineColor ( const Color4f color)

Set the outline's color of the button when it's in a normal state.

Parameters
colorThe new color to apply

◆ setDisabledTextColor()

void gf::TextWidget::setDisabledTextColor ( const Color4f color)

Set the text's color of the button when disabled.

Parameters
colorThe new color to apply

◆ setDisabledTextOutlineColor()

void gf::TextWidget::setDisabledTextOutlineColor ( const Color4f color)

Set the outline's color of the button when disabled.

Parameters
colorThe new color to apply

◆ setLetterSpacing()

void gf::TextWidget::setLetterSpacing ( float  spacingFactor)

Set the letter spacing factor.

The default spacing between letters is defined by the font. This factor doesn't directly apply to the existing spacing between each character, it rather adds a fixed space between them which is calculated from the font metrics and the character size. Note that factors below 1 (including negative numbers) bring characters closer to each other. By default the letter spacing factor is 1.

Parameters
spacingFactorNew letter spacing factor
See also
getLetterSpacing()

◆ setLineSpacing()

void gf::TextWidget::setLineSpacing ( float  spacingFactor)

Set the line spacing factor.

The default spacing between lines is defined by the font. This method enables you to set a factor for the spacing between lines. By default the line spacing factor is 1.

Parameters
spacingFactorNew line spacing factor
See also
getLineSpacing()

◆ setParagraphWidth()

void gf::TextWidget::setParagraphWidth ( float  paragraphWidth)

Set the paragraph width for aligned text.

By default, the paragraph width is 0.

Parameters
paragraphWidthNew paragraph width in pixels
See also
getParagraphWidth()

◆ setSelectedTextColor()

void gf::TextWidget::setSelectedTextColor ( const Color4f color)

Set the text's color of the button when selected.

Parameters
colorThe new color to apply

◆ setSelectedTextOutlineColor()

void gf::TextWidget::setSelectedTextOutlineColor ( const Color4f color)

Set the outline's color of the button when selected.

Parameters
colorThe new color to apply

◆ setString()

void gf::TextWidget::setString ( std::string  string)

Set the text's string.

The text string is in UTF-8 format. A text's string is empty by default.

Parameters
stringNew string in UTF-8 format

◆ setTextOutlineThickness()

void gf::TextWidget::setTextOutlineThickness ( float  thickness)

Set the thickness of the outline.

Parameters
thicknessThe new value of the outline thickness.

◆ updateColors()

void gf::TextWidget::updateColors ( Color4f  textColor,
Color4f  outlineColor 
)
protected

◆ updateCurrentStateColors()

void gf::TextWidget::updateCurrentStateColors ( )
protected

◆ updateGeometry()

void gf::TextWidget::updateGeometry ( )
protected