Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
sf::ui::TextField Class Reference

A text field which stores a text

. More...

#include <TextField.hpp>

Inheritance diagram for sf::ui::TextField:
sf::ui::Focusable sf::ui::IText sf::ui::Component sf::ui::ComponentObservable sf::ui::FormattedTextField sf::ui::PasswordField

Public Member Functions

 TextField ()
 Creates an empty text field without texture, font ... More...
 
 TextField (sf::Texture const &texture, sf::Texture const &textureFocused, sf::String const &text="")
 Creates a text field without font Then do not forget to set the font before displaying it. More...
 
 TextField (sf::Texture const &texture, sf::Texture const &textureFocused, sf::Font const &font, sf::String text="")
 Creates a text field. More...
 
virtual void updateEvent (sf::Event const &event)
 Update the component each time an event has been polled. More...
 
virtual void updateFixed (sf::Time delta)
 Update the component with the main loop's frequency Can be useful for animation, or time's needed stuff. More...
 
const TextFieldModelgetModel () const
 
void setModel (TextFieldModel *model)
 Sets the model of the text field. More...
 
virtual const sf::String & getText () const
 
virtual void setText (sf::String const &text)
 Sets the text's string of the component Don't forget to set the font. More...
 
virtual const sf::Font * getFont () const
 
virtual void setFont (sf::Font const &font)
 Sets the font of the component's text. More...
 
virtual unsigned int getFontSize () const
 
virtual void setFontSize (unsigned int size)
 Set the font's size of the component. More...
 
virtual sf::Color getFontColor () const
 
virtual void setFontColor (sf::Color color)
 Sets the color's font of the text. More...
 
unsigned int getCursor () const
 
void setCursor (unsigned int cursor)
 Sets the cursor's position. More...
 
int getMaxLength () const
 
void setMaxLength (int maxLength)
 Sets the max length that the string can have -1 means the string has no length limit. More...
 
bool canBeEmpty () const
 
void setCanBeEmpty (bool canBeEmpty)
 Sets if the string can be empty. More...
 
bool isFocused () const
 
void setFocused (bool focused)
 Set if the component is focused. More...
 
const sf::Texture * getTextureFocused () const
 
void setTextureFocused (const sf::Texture &textureFocused)
 Set the texture that is displayed when the component is displayed. More...
 
void updateSize ()
 Update the size of the component Call it when you update your texture after it was set, to recalculate the component's size with new texture loaded. More...
 
void move (sf::Vector2f const &vector)
 Move the component. More...
 
void move (float x, float y)
 Move the component. More...
 
const sf::Texture * getTexture () const
 
void setTexture (const sf::Texture &texture)
 Set the texture of the component. More...
 
const sf::Vector2f & getPosition () const
 
void setPosition (sf::Vector2f const &position)
 Set the component's position. More...
 
void setPosition (float x, float y)
 Set the component's position. More...
 
virtual sf::Vector2f getSize () const
 
void addObserver (sf::ui::ComponentObserver *observer)
 Add an observer. More...
 
std::set
< sf::ui::ComponentObserver * >
::const_iterator 
getObserversBegin () const
 
std::set
< sf::ui::ComponentObserver * >
::const_iterator 
getObserversEnd () const
 
int countObservers ()
 
void removeObserver (sf::ui::ComponentObserver *observer)
 Remove the observer at the given index. More...
 
void removeAllObservers ()
 Remove all the observers. More...
 

Protected Member Functions

virtual void draw (sf::RenderTarget &target, sf::RenderStates states) const
 Draw the component to the render target. More...
 
virtual void updateCoord ()
 Called when the component need update its geometry Inherit when you need to update some sprite. More...
 
virtual bool insertText (sf::Uint32 text, unsigned int index)
 Insert a char at the given index Trigger a TextEnteredEvent. More...
 
virtual bool deleteText (unsigned int index)
 Delete the char at the given index Trigger a TextDeletedEvent. More...
 
virtual bool checkClickOn (int x, int y) const
 
virtual bool isCoordOnComponent (int x, int y) const
 
virtual void gainFocus ()
 Called when the component gain focus. More...
 
virtual void lostFocus ()
 Called when the component lost focus. More...
 
void triggerEvent (const sf::ui::ComponentEvent &event)
 Triggers the event and notify all observers. More...
 

Protected Attributes

sf::Text m_text
 
TextFieldModelm_model
 
unsigned int m_cursor
 
sf::RectangleShape m_cursorShape
 
int m_maxLength
 
bool m_canBeEmpty
 
sf::Texture const * m_textureFocused
 
bool m_focused
 
sf::Sprite m_sprite
 
sf::Texture const * m_texture
 
std::set
< sf::ui::ComponentObserver * > 
m_observers
 

Detailed Description

A text field which stores a text

.

Definition at line 30 of file TextField.hpp.

Constructor & Destructor Documentation

sf::ui::TextField::TextField ( )

Creates an empty text field without texture, font ...

Then do not forget to set its before displaying it

sf::ui::TextField::TextField ( sf::Texture const &  texture,
sf::Texture const &  textureFocused,
sf::String const &  text = "" 
)

Creates a text field without font Then do not forget to set the font before displaying it.

Parameters
texturethe texture of the text field
textureFocusedthe texture when the text field is focused
textthe default text of the text field
sf::ui::TextField::TextField ( sf::Texture const &  texture,
sf::Texture const &  textureFocused,
sf::Font const &  font,
sf::String  text = "" 
)

Creates a text field.

Parameters
texturethe texture of the text field
textureFocusedthe texture when the text field is focused
fontthe text's font
textthe default text of the text field

Member Function Documentation

void sf::ui::ComponentObservable::addObserver ( sf::ui::ComponentObserver observer)
inherited

Add an observer.

bool sf::ui::TextField::canBeEmpty ( ) const
Returns
if the string can be empty
virtual bool sf::ui::Focusable::checkClickOn ( int  x,
int  y 
) const
protectedvirtualinherited
Returns
whether the click should focus the component or not
Parameters
button- the mouse's button
x- the x coord
y- the y coord
int sf::ui::ComponentObservable::countObservers ( )
inherited
Returns
the number of observers
virtual bool sf::ui::TextField::deleteText ( unsigned int  index)
protectedvirtual

Delete the char at the given index Trigger a TextDeletedEvent.

Parameters
indexthe index of the char to delete
Returns
if the text has been successfully deleted

Reimplemented in sf::ui::PasswordField.

virtual void sf::ui::TextField::draw ( sf::RenderTarget &  target,
sf::RenderStates  states 
) const
protectedvirtual

Draw the component to the render target.

Reimplemented from sf::ui::Component.

virtual void sf::ui::Focusable::gainFocus ( )
protectedvirtualinherited

Called when the component gain focus.

unsigned int sf::ui::TextField::getCursor ( ) const
Returns
the position of the cursor
virtual const sf::Font* sf::ui::TextField::getFont ( ) const
virtual
Returns
the font of the component, or null if any

Implements sf::ui::IText.

virtual sf::Color sf::ui::TextField::getFontColor ( ) const
virtual
Returns
the font's color of the text

Implements sf::ui::IText.

virtual unsigned int sf::ui::TextField::getFontSize ( ) const
virtual
Returns
the font's size of the component

Implements sf::ui::IText.

int sf::ui::TextField::getMaxLength ( ) const
Returns
the max length that the string can have Or -1 if the string has no length limit
const TextFieldModel* sf::ui::TextField::getModel ( ) const
Returns
the object that defines what can be typed in the text field
std::set<sf::ui::ComponentObserver*>::const_iterator sf::ui::ComponentObservable::getObserversBegin ( ) const
inherited
Returns
the begin of the observers' iterator
std::set<sf::ui::ComponentObserver*>::const_iterator sf::ui::ComponentObservable::getObserversEnd ( ) const
inherited
Returns
the end of the observers' iterator
const sf::Vector2f& sf::ui::Component::getPosition ( ) const
inherited
Returns
the position of the component
virtual sf::Vector2f sf::ui::Component::getSize ( ) const
virtualinherited
Returns
the size of the component

Reimplemented in sf::ui::Label, and sf::ui::CheckBox.

virtual const sf::String& sf::ui::TextField::getText ( ) const
virtual
Returns
the text's string

Implements sf::ui::IText.

const sf::Texture* sf::ui::Component::getTexture ( ) const
inherited
Returns
the texture of the component
const sf::Texture* sf::ui::Focusable::getTextureFocused ( ) const
inherited
Returns
the texture when the component is focused
virtual bool sf::ui::TextField::insertText ( sf::Uint32  text,
unsigned int  index 
)
protectedvirtual

Insert a char at the given index Trigger a TextEnteredEvent.

Parameters
textthe text to insert
indexthe index of the insertion
Returns
if the text has been successfully inserted

Reimplemented in sf::ui::PasswordField.

virtual bool sf::ui::Focusable::isCoordOnComponent ( int  x,
int  y 
) const
protectedvirtualinherited
Returns
whether the given coordinate is on the component or out
Parameters
x- the x coord
y- the y coord
bool sf::ui::Focusable::isFocused ( ) const
inherited
Returns
whether the component is focused or not
virtual void sf::ui::Focusable::lostFocus ( )
protectedvirtualinherited

Called when the component lost focus.

Reimplemented in sf::ui::FormattedTextField.

void sf::ui::Component::move ( sf::Vector2f const &  vector)
inherited

Move the component.

Parameters
vectorthe move's vector
void sf::ui::Component::move ( float  x,
float  y 
)
inherited

Move the component.

Parameters
xthe x movement
ythe y movement
void sf::ui::ComponentObservable::removeAllObservers ( )
inherited

Remove all the observers.

void sf::ui::ComponentObservable::removeObserver ( sf::ui::ComponentObserver observer)
inherited

Remove the observer at the given index.

Parameters
observerthe observer to remove
void sf::ui::TextField::setCanBeEmpty ( bool  canBeEmpty)

Sets if the string can be empty.

void sf::ui::TextField::setCursor ( unsigned int  cursor)

Sets the cursor's position.

Parameters
cursorthe cursor's position
void sf::ui::Focusable::setFocused ( bool  focused)
inherited

Set if the component is focused.

Parameters
focused- is focused
virtual void sf::ui::TextField::setFont ( sf::Font const &  font)
virtual

Sets the font of the component's text.

Implements sf::ui::IText.

virtual void sf::ui::TextField::setFontColor ( sf::Color  color)
virtual

Sets the color's font of the text.

Parameters
colorthe text's color

Implements sf::ui::IText.

virtual void sf::ui::TextField::setFontSize ( unsigned int  size)
virtual

Set the font's size of the component.

Parameters
sizethe font's size

Implements sf::ui::IText.

void sf::ui::TextField::setMaxLength ( int  maxLength)

Sets the max length that the string can have -1 means the string has no length limit.

void sf::ui::TextField::setModel ( TextFieldModel model)

Sets the model of the text field.

Parameters
modelthe object that defines which characters can be typed
void sf::ui::Component::setPosition ( sf::Vector2f const &  position)
inherited

Set the component's position.

Parameters
position- the position vector
void sf::ui::Component::setPosition ( float  x,
float  y 
)
inherited

Set the component's position.

Parameters
x- the x coordinate
y- the y coordinate
virtual void sf::ui::TextField::setText ( sf::String const &  text)
virtual

Sets the text's string of the component Don't forget to set the font.

Parameters
text- the new string of the component

Implements sf::ui::IText.

void sf::ui::Component::setTexture ( const sf::Texture &  texture)
inherited

Set the texture of the component.

void sf::ui::Focusable::setTextureFocused ( const sf::Texture &  textureFocused)
inherited

Set the texture that is displayed when the component is displayed.

Parameters
textureFocused- the texture when the component is focused
void sf::ui::ComponentObservable::triggerEvent ( const sf::ui::ComponentEvent event)
protectedinherited

Triggers the event and notify all observers.

Parameters
event- the event to push
virtual void sf::ui::TextField::updateCoord ( )
protectedvirtual

Called when the component need update its geometry Inherit when you need to update some sprite.

Reimplemented from sf::ui::Component.

virtual void sf::ui::TextField::updateEvent ( sf::Event const &  event)
virtual

Update the component each time an event has been polled.

Parameters
eventthe window's event polled

Implements sf::ui::Component.

virtual void sf::ui::TextField::updateFixed ( sf::Time  delta)
virtual

Update the component with the main loop's frequency Can be useful for animation, or time's needed stuff.

Parameters
deltathe time between this update and the last

Implements sf::ui::Component.

void sf::ui::Component::updateSize ( )
inherited

Update the size of the component Call it when you update your texture after it was set, to recalculate the component's size with new texture loaded.

Example:

sf::Texture texture;
sf::Label label(texture); // Now label has a pointer to texture, moreover its size is (0;0)
texture.loadFromFile("texture.png"); // New texture loaded, and so its size has changed
label.updateSize(); // Tell label that it have to change its size, and calculate it with the updated texture's size

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