FifeGUI 0.2.0
A C++ GUI library designed for games.
fcn::TextBox Class Reference

#include <textbox.hpp>

Inheritance diagram for fcn::TextBox:
fcn::Widget fcn::MouseListener fcn::KeyListener

Public Member Functions

virtual void addRow (std::string const &row)
void adjustSize () override
void draw (Graphics *graphics) override
void fontChanged () override
unsigned int getCaretColumn () const
unsigned int getCaretPosition () const
unsigned int getCaretRow () const
unsigned int getNumberOfRows () const
std::string getText () const
std::string getTextRow (int row) const
bool isEditable () const
bool isOpaque () const
void keyPressed (KeyEvent &keyEvent) override
void mouseDragged (MouseEvent &mouseEvent) override
void mousePressed (MouseEvent &mouseEvent) override
TextBoxoperator= (TextBox &&)=delete
TextBoxoperator= (TextBox const &)=delete
void resizeToContent ()
void resizeToContent (bool recursion) override
virtual void scrollToCaret ()
void setCaretColumn (int column)
void setCaretPosition (unsigned int position)
void setCaretRow (int row)
void setCaretRowColumn (int row, int column)
void setEditable (bool editable)
void setOpaque (bool opaque)
void setText (std::string const &text)
void setTextRow (int row, std::string const &text)
 TextBox (std::string const &text="")
 TextBox (TextBox &&)=delete
 TextBox (TextBox const &)=delete
Public Member Functions inherited from fcn::Widget
virtual void _draw (Graphics *graphics)
virtual FocusHandler_getFocusHandler ()
virtual std::list< FocusListener * > const & _getFocusListeners ()
virtual FocusHandler_getInternalFocusHandler ()
virtual std::list< KeyListener * > const & _getKeyListeners ()
virtual std::list< MouseListener * > const & _getMouseListeners ()
virtual void _logic ()
virtual void _setFocusHandler (FocusHandler *focusHandler)
virtual void _setParent (Widget *parent)
void adaptLayout ()
virtual void adaptLayout (bool top)
void addActionListener (ActionListener *actionListener)
void addDeathListener (DeathListener *deathListener)
void addFocusListener (FocusListener *focusListener)
void addKeyListener (KeyListener *keyListener)
void addMouseListener (MouseListener *mouseListener)
void addWidgetListener (WidgetListener *widgetListener)
virtual void drawBorder (Graphics *graphics)
virtual void drawOutline (Graphics *graphics)
virtual void drawSelectionFrame (Graphics *graphics)
void expandContent ()
virtual void expandContent (bool recursion)
virtual void focusNext ()
virtual void focusPrevious ()
virtual void getAbsolutePosition (int &x, int &y) const
std::string const & getActionEventId () const
Color const & getBackgroundColor () const
Color const & getBaseColor () const
Color const & getBorderColor () const
unsigned int getBorderSize () const
virtual Rectangle getChildrenArea ()
unsigned int getChildrenCount () const
Rectangle const & getDimension () const
Size const & getFixedSize () const
FontgetFont () const
Color const & getForegroundColor () const
int getHeight () const
std::string const & getId () const
void getLastPosition (int &x, int &y) const
int getMarginBottom () const
int getMarginLeft () const
int getMarginRight () const
int getMarginTop () const
Size const & getMaxSize () const
Size const & getMinSize () const
Color const & getOutlineColor () const
unsigned int getOutlineSize () const
unsigned int getPaddingBottom () const
unsigned int getPaddingLeft () const
unsigned int getPaddingRight () const
unsigned int getPaddingTop () const
virtual WidgetgetParent () const
Color const & getSelectionColor () const
SelectionMode getSelectionMode () const
virtual WidgetgetTop () const
unsigned int getVisibleChildrenCount () const
WidgetgetWidgetAt (int x, int y)
virtual WidgetgetWidgetAt (int x, int y, Widget *exclude)
std::list< Widget * > getWidgetsIn (Rectangle const &area)
virtual std::list< Widget * > getWidgetsIn (Rectangle const &area, Widget *ignore)
int getWidth () const
int getX () const
int getY () const
bool isEnabled () const
bool isFixedSize () const
bool isFocusable () const
virtual bool isFocused () const
bool isHorizontalExpand () const
bool isLastPositionSet () const
virtual bool isLayouted ()
virtual bool isModalFocusable () const
virtual bool isModalFocused () const
virtual bool isModalMouseInputFocusable () const
virtual bool isModalMouseInputFocused () const
bool isSetVisible () const
bool isTabInEnabled () const
bool isTabOutEnabled () const
bool isVerticalExpand () const
bool isVisible () const
virtual void logic ()
virtual void moveToBottom (Widget *widget)
virtual void moveToTop (Widget *widget)
Widgetoperator= (Widget &&)=delete
Widgetoperator= (Widget const &)=delete
virtual void releaseModalFocus ()
virtual void releaseModalMouseInputFocus ()
void removeActionListener (ActionListener *actionListener)
void removeDeathListener (DeathListener *deathListener)
void removeFocusListener (FocusListener *focusListener)
void removeKeyListener (KeyListener *keyListener)
void removeMouseListener (MouseListener *mouseListener)
void removeWidgetListener (WidgetListener *widgetListener)
virtual void requestFocus ()
virtual void requestModalFocus ()
virtual void requestModalMouseInputFocus ()
virtual void requestMoveToBottom ()
virtual void requestMoveToTop ()
void resizeToContent ()
void setActionEventId (std::string const &actionEventId)
virtual void setBackgroundColor (Color const &color)
virtual void setBaseColor (Color const &color)
virtual void setBorderColor (Color const &color)
void setBorderSize (unsigned int size)
void setDimension (Rectangle const &dimension)
void setEnabled (bool enabled)
void setFixedSize (Size const &size)
void setFocusable (bool focusable)
virtual void setFont (Font *font)
virtual void setForegroundColor (Color const &color)
void setHeight (int height)
void setHorizontalExpand (bool expand)
void setId (std::string const &id)
void setInternalFocusHandler (FocusHandler *internalFocusHandler)
void setLastPosition (int x, int y)
void setMargin (int margin)
void setMarginBottom (int margin)
void setMarginLeft (int margin)
void setMarginRight (int margin)
void setMarginTop (int margin)
void setMaxSize (Size const &size)
void setMinSize (Size const &size)
virtual void setOutlineColor (Color const &color)
void setOutlineSize (unsigned int size)
void setPadding (unsigned int padding)
void setPaddingBottom (unsigned int padding)
void setPaddingLeft (unsigned int padding)
void setPaddingRight (unsigned int padding)
void setPaddingTop (unsigned int padding)
void setPosition (int x, int y)
virtual void setSelectionColor (Color const &color)
virtual void setSelectionMode (SelectionMode mode)
void setSize (int width, int height)
void setTabInEnabled (bool enabled)
void setTabOutEnabled (bool enabled)
void setVerticalExpand (bool expand)
void setVisible (bool visible)
void setWidth (int width)
void setX (int x)
void setY (int y)
virtual void showPart (Rectangle rectangle)
virtual void showWidgetPart (Widget *widget, Rectangle area)
 Widget ()
 Widget (Widget &&)=delete
 Widget (Widget const &)=delete
Public Member Functions inherited from fcn::MouseListener
virtual void mouseClicked (MouseEvent &mouseEvent)
virtual void mouseEntered (MouseEvent &mouseEvent)
virtual void mouseExited (MouseEvent &mouseEvent)
 MouseListener (MouseListener &&)=default
 MouseListener (MouseListener const &)=default
virtual void mouseMoved (MouseEvent &mouseEvent)
virtual void mouseReleased (MouseEvent &mouseEvent)
virtual void mouseWheelMovedDown (MouseEvent &mouseEvent)
virtual void mouseWheelMovedLeft (MouseEvent &mouseEvent)
virtual void mouseWheelMovedRight (MouseEvent &mouseEvent)
virtual void mouseWheelMovedUp (MouseEvent &mouseEvent)
MouseListener & operator= (MouseListener &&)=default
MouseListener & operator= (MouseListener const &)=default
Public Member Functions inherited from fcn::KeyListener
 KeyListener (KeyListener &&)=default
 KeyListener (KeyListener const &)=default
virtual void keyReleased (KeyEvent &keyEvent)
KeyListener & operator= (KeyListener &&)=default
KeyListener & operator= (KeyListener const &)=default

Protected Member Functions

void adjustSizeImpl ()
virtual void drawCaret (Graphics *graphics, int x, int y)
void setCaretColumnUTF8 (int column)
void setCaretRowColumnUTF8 (int row, int column)
void setCaretRowUTF8 (int row)
Protected Member Functions inherited from fcn::Widget
void add (Widget *widget)
void calculateSize ()
void distributeActionEvent ()
void distributeAncestorHiddenEvent (Widget *ancestor)
void distributeAncestorMovedEvent (Widget *ancestor)
void distributeAncestorShownEvent (Widget *ancestor)
void distributeHiddenEvent ()
void distributeMovedEvent ()
void distributeResizedEvent ()
void distributeShownEvent ()
virtual WidgetfindWidgetById (std::string const &id)
std::list< Widget * > const & getChildren () const
virtual void remove (Widget *widget)
virtual void removeAllChildren ()
void resizeToChildren ()
Protected Member Functions inherited from fcn::MouseListener
 MouseListener ()=default
Protected Member Functions inherited from fcn::KeyListener
 KeyListener ()=default

Protected Attributes

bool mEditable {true}
bool mOpaque {true}
UTF8StringEditormStringEditor
TextmText
Protected Attributes inherited from fcn::Widget
std::string mActionEventId
std::list< ActionListener * > mActionListeners
Color mBackgroundColor {0xf9fafb}
Color mBaseColor {0xe5e7eb}
Color mBorderColor {0xd1d5db}
unsigned int mBorderSize {0}
std::list< Widget * > mChildren
FontmCurrentFont {nullptr}
std::list< DeathListener * > mDeathListeners
Rectangle mDimension
bool mEnabled {true}
Size mFixedSize {-1, -1}
bool mFixedSizeUsed {false}
bool mFocusable {false}
FocusHandlermFocusHandler {nullptr}
std::list< FocusListener * > mFocusListeners
Color mForegroundColor {0x1f2933}
bool mHExpand {false}
std::string mId
FocusHandlermInternalFocusHandler {nullptr}
std::list< KeyListener * > mKeyListeners
int mLastX {0}
int mLastY {0}
int mMarginBottom {0}
int mMarginLeft {0}
int mMarginRight {0}
int mMarginTop {0}
Size mMaxSize {std::numeric_limits<int>::max(), std::numeric_limits<int>::max()}
Size mMinSize {0, 0}
std::list< MouseListener * > mMouseListeners
Rectangle mOffsetRect
Color mOutlineColor {0x9ca3af}
unsigned int mOutlineSize {0}
unsigned int mPaddingBottom {0}
unsigned int mPaddingLeft {0}
unsigned int mPaddingRight {0}
unsigned int mPaddingTop {0}
WidgetmParent {nullptr}
Color mSelectionColor {0x3b82f6}
SelectionMode mSelectionMode {SelectionMode::None}
bool mTabIn {true}
bool mTabOut {true}
bool mVExpand {false}
bool mVisible {true}
std::list< WidgetListener * > mWidgetListeners

Additional Inherited Members

Public Types inherited from fcn::Widget
enum class  SelectionMode : uint8_t { None = 0 , Border = 1 , Background = 2 }
Static Public Member Functions inherited from fcn::Widget
static DeathListener_getGuiDeathListener ()
static VisibilityEventHandler_getVisibilityEventHandler ()
static void _setGuiDeathListener (DeathListener *deathListener)
static void _setVisibilityEventHandler (VisibilityEventHandler *visibilityEventHandler)
static void setGlobalFont (Font *font)
static bool widgetExists (Widget const *widget)
Static Protected Attributes inherited from fcn::Widget
static DefaultFont mDefaultFont
static FontmGlobalFont = nullptr
static DeathListenermGuiDeathListener = nullptr
static VisibilityEventHandlermVisibilityEventHandler = nullptr
static std::list< Widget * > mWidgetInstances

Detailed Description

A multi-line text input field.

Definition at line 27 of file textbox.hpp.

Constructor & Destructor Documentation

◆ TextBox()

fcn::TextBox::TextBox ( std::string const & text = "")
explicit

Constructor.

Parameters
textThe default text of the text box.

Definition at line 20 of file textbox.cpp.

References fcn::Widget::addKeyListener(), fcn::Widget::addMouseListener(), adjustSizeImpl(), mStringEditor, mText, and fcn::Widget::setFocusable().

◆ ~TextBox()

fcn::TextBox::~TextBox ( )
override

Definition at line 29 of file textbox.cpp.

Member Function Documentation

◆ addRow()

void fcn::TextBox::addRow ( std::string const & row)
virtual

Adds a row of text to the end of the text.

Parameters
rowThe row to add.

Definition at line 285 of file textbox.cpp.

References adjustSizeImpl(), and mText.

◆ adjustSize()

void fcn::TextBox::adjustSize ( )
overridevirtual

Adjusts the text box's size to fit the text.

Reimplemented from fcn::Widget.

Definition at line 197 of file textbox.cpp.

References adjustSizeImpl().

◆ adjustSizeImpl()

void fcn::TextBox::adjustSizeImpl ( )
protected

Adjusts the size of the button to fit the caption.

The public adjustSize() method serves as a virtual entry point for polymorphism, while this adjustSizeImpl() method contains the concrete implementation of the resizing logic.

See also
adjustSize (virtual entry point for polymorphism)

Definition at line 202 of file textbox.cpp.

References fcn::Widget::getFont(), fcn::Rectangle::height, mText, fcn::Widget::setSize(), and fcn::Rectangle::width.

Referenced by addRow(), adjustSize(), fontChanged(), keyPressed(), resizeToContent(), setText(), setTextRow(), and TextBox().

◆ draw()

void fcn::TextBox::draw ( Graphics * graphics)
overridevirtual

Draws the widget.

The call to draw is initiated by the widget's parent. The graphics object is set up so that all drawing is relative to the widget, i.e coordinate (0,0) is the top left corner of the widget. It is not possible to draw outside of a widget's dimension. If a widget has children, the parent's draw function will always be called before the children's draw functions are called.

NOTE: A widget with children won't draw its children unless the children area given by Widget::getChildrenArea returns a none empty rectangle inside the widgets dimension. The children area is considered relative to the widget's position.

Parameters
Graphics & RenderingA graphics object to draw with.
See also
getChildrenArea, drawOutline, drawBorder

Implements fcn::Widget.

Definition at line 41 of file textbox.cpp.

References drawCaret(), fcn::Graphics::drawText(), fcn::Graphics::fillRectangle(), fcn::Widget::getBackgroundColor(), fcn::Widget::getFont(), fcn::Widget::getForegroundColor(), fcn::Widget::getHeight(), fcn::Widget::getWidth(), isEditable(), fcn::Widget::isFocused(), mOpaque, mText, fcn::Graphics::setColor(), and fcn::Graphics::setFont().

◆ drawCaret()

void fcn::TextBox::drawCaret ( Graphics * graphics,
int x,
int y )
protectedvirtual

Draws the caret.

Overloaded this method if you want to change the style of the caret.

Parameters
Graphics & Renderinga Graphics object to draw with.
xthe x position.
ythe y position.

Definition at line 62 of file textbox.cpp.

References fcn::Graphics::drawLine(), fcn::Widget::getFont(), fcn::Widget::getForegroundColor(), fcn::Widget::getHeight(), and fcn::Graphics::setColor().

Referenced by draw().

◆ fontChanged()

void fcn::TextBox::fontChanged ( )
overridevirtual

Called when the font has changed.

If the change is global, this function will only be called if the widget doesn't have a font already set.

Reimplemented from fcn::Widget.

Definition at line 265 of file textbox.cpp.

References adjustSizeImpl().

◆ getCaretColumn()

unsigned int fcn::TextBox::getCaretColumn ( ) const

Gets the column where the caret is currently located.

Returns
The column where the caret is currently located.
See also
setCaretColumn

Definition at line 239 of file textbox.cpp.

References mText.

Referenced by keyPressed(), and setCaretRowUTF8().

◆ getCaretPosition()

unsigned int fcn::TextBox::getCaretPosition ( ) const

Gets the caret position in the text.

Returns
The caret position in the text.
See also
setCaretPosition

Definition at line 213 of file textbox.cpp.

References mText.

◆ getCaretRow()

unsigned int fcn::TextBox::getCaretRow ( ) const

Gets the row number where the caret is currently located.

Returns
The row number where the caret is currently located.
See also
setCaretRow

Definition at line 229 of file textbox.cpp.

References mText.

Referenced by keyPressed(), setCaretColumnUTF8(), and setCaretRowUTF8().

◆ getNumberOfRows()

unsigned int fcn::TextBox::getNumberOfRows ( ) const

Gets the number of rows in the text.

Returns
The number of rows in the text.

Definition at line 255 of file textbox.cpp.

References mText.

Referenced by keyPressed(), and setCaretRowUTF8().

◆ getText()

std::string fcn::TextBox::getText ( ) const

Gets the text of the text box.

Returns
The text of the text box.
See also
setText

Definition at line 260 of file textbox.cpp.

References mText.

◆ getTextRow()

std::string fcn::TextBox::getTextRow ( int row) const

Gets a certain row from the text.

Parameters
rowThe number of the row to get from the text.
Returns
A row from the text of the text box.
See also
setTextRow

Definition at line 244 of file textbox.cpp.

References mText.

Referenced by keyPressed(), setCaretColumnUTF8(), and setCaretRowUTF8().

◆ isEditable()

bool fcn::TextBox::isEditable ( ) const

Checks if the text box is editable.

Returns
True it the text box is editable, false otherwise.
See also
setEditable

Definition at line 280 of file textbox.cpp.

References mEditable.

Referenced by draw().

◆ isOpaque()

bool fcn::TextBox::isOpaque ( ) const

Checks if the text box is opaque.

An opaque text box will draw it's background and it's text. A non opaque text box only draw it's text making it transparent.

Returns
True if the text box is opaque, false otherwise.
See also
setOpaque

Definition at line 291 of file textbox.cpp.

References mOpaque.

◆ keyPressed()

◆ mouseDragged()

void fcn::TextBox::mouseDragged ( MouseEvent & mouseEvent)
overridevirtual

Called when the mouse has moved and the mouse has previously been pressed on the widget.

Parameters
mouseEventDescribes the event.

Reimplemented from fcn::MouseListener.

Definition at line 76 of file textbox.cpp.

References fcn::InputEvent::consume().

◆ mousePressed()

void fcn::TextBox::mousePressed ( MouseEvent & mouseEvent)
overridevirtual

Called when a mouse button has been pressed on the widget area.

NOTE: A mouse press is NOT equal to a mouse click. Use mouseClickMessage to check for mouse clicks.

Parameters
mouseEventDescribes the event.

Reimplemented from fcn::MouseListener.

Definition at line 68 of file textbox.cpp.

References fcn::InputEvent::consume(), fcn::MouseEvent::getButton(), fcn::Widget::getFont(), fcn::MouseEvent::getX(), fcn::MouseEvent::getY(), and mText.

◆ resizeToContent() [1/2]

Resizes the widget's size to fit the content exactly, calls recursively all childs.

This is a convenience wrapper that calls resizeToContent(true).

Definition at line 1417 of file widget.hpp.

◆ resizeToContent() [2/2]

void fcn::TextBox::resizeToContent ( bool recursion)
overridevirtual

Resize this widget to fit its content.

Parameters
recursionIf true, perform the resize operation recursively on children.

Reimplemented from fcn::Widget.

Definition at line 191 of file textbox.cpp.

References adjustSizeImpl().

◆ scrollToCaret()

void fcn::TextBox::scrollToCaret ( )
virtual

Scrolls the text to the caret if the text box is in a scroll area.

See also
ScrollArea

Definition at line 270 of file textbox.cpp.

References fcn::Widget::getFont(), mText, and fcn::Widget::showPart().

Referenced by keyPressed().

◆ setCaretColumn()

void fcn::TextBox::setCaretColumn ( int column)

Sets the column where the caret should be currently located.

Parameters
columnThe column where the caret should be currently located.
See also
getCaretColumn

Definition at line 234 of file textbox.cpp.

References mText.

Referenced by keyPressed(), setCaretColumnUTF8(), and setCaretRowUTF8().

◆ setCaretColumnUTF8()

void fcn::TextBox::setCaretColumnUTF8 ( int column)
protected

Sets caret column (UTF-8 aware).

Parameters
columnCaret column.

Definition at line 301 of file textbox.cpp.

References getCaretRow(), fcn::UTF8StringEditor::getOffset(), getTextRow(), and setCaretColumn().

Referenced by setCaretRowColumnUTF8().

◆ setCaretPosition()

void fcn::TextBox::setCaretPosition ( unsigned int position)

Sets the position of the caret in the text.

Parameters
positionthe position of the caret.
See also
getCaretPosition

Definition at line 208 of file textbox.cpp.

References mText.

◆ setCaretRow()

void fcn::TextBox::setCaretRow ( int row)

Sets the row where the caret should be currently located.

Parameters
rowThe row where the caret should be currently located.
See also
getCaretRow

Definition at line 224 of file textbox.cpp.

References mText.

Referenced by keyPressed(), and setCaretRowUTF8().

◆ setCaretRowColumn()

void fcn::TextBox::setCaretRowColumn ( int row,
int column )

Sets the row and the column where the caret should be currently located.

Parameters
rowThe row where the caret should be currently located.
columnThe column where the caret should be currently located.
See also
getCaretRow, getCaretColumn

Definition at line 218 of file textbox.cpp.

References mText.

◆ setCaretRowColumnUTF8()

void fcn::TextBox::setCaretRowColumnUTF8 ( int row,
int column )
protected

Sets the caret row and column (UTF-8 aware).

Parameters
rowCaret row (UTF-8 aware index).
columnCaret column (UTF-8 aware index).

Definition at line 319 of file textbox.cpp.

References setCaretColumnUTF8(), and setCaretRowUTF8().

◆ setCaretRowUTF8()

void fcn::TextBox::setCaretRowUTF8 ( int row)
protected

Sets caret row (UTF-8 aware).

Parameters
rowCaret row.

Definition at line 307 of file textbox.cpp.

References fcn::UTF8StringEditor::countChars(), getCaretColumn(), getCaretRow(), getNumberOfRows(), fcn::UTF8StringEditor::getOffset(), getTextRow(), setCaretColumn(), and setCaretRow().

Referenced by keyPressed(), and setCaretRowColumnUTF8().

◆ setEditable()

void fcn::TextBox::setEditable ( bool editable)

Sets the text box to be editable or not.

Parameters
editableTrue if the text box should be editable, false otherwise.

Definition at line 275 of file textbox.cpp.

References mEditable.

◆ setOpaque()

void fcn::TextBox::setOpaque ( bool opaque)

Sets the text box to be opaque or not.

An opaque text box will draw it's background and it's text. A non opaque text box only draw it's text making it transparent.

Parameters
opaqueTrue if the text box should be opaque, false otherwise.
See also
isOpaque

Definition at line 296 of file textbox.cpp.

References mOpaque.

◆ setText()

void fcn::TextBox::setText ( std::string const & text)

Sets the text of the text box.

Parameters
textThe text of the text box.
See also
getText

Definition at line 35 of file textbox.cpp.

References adjustSizeImpl(), and mText.

◆ setTextRow()

void fcn::TextBox::setTextRow ( int row,
std::string const & text )

Sets the text of a certain row of the text.

Parameters
rowThe number of the row to set in the text.
textThe text to set in the given row number.
See also
getTextRow

Definition at line 249 of file textbox.cpp.

References adjustSizeImpl(), and mText.

Member Data Documentation

◆ mEditable

bool fcn::TextBox::mEditable {true}
protected

True if the text box is editable, false otherwise.

Definition at line 266 of file textbox.hpp.

Referenced by isEditable(), keyPressed(), and setEditable().

◆ mOpaque

bool fcn::TextBox::mOpaque {true}
protected

True if the text box is opaque, false otherwise.

Definition at line 271 of file textbox.hpp.

Referenced by draw(), isOpaque(), and setOpaque().

◆ mStringEditor

UTF8StringEditor* fcn::TextBox::mStringEditor
protected

UTF8StringEditor for UTF8 support.

Definition at line 276 of file textbox.hpp.

Referenced by TextBox().

◆ mText


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