Support Forum       G3D Web Page     
Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Friends | List of all members
G3D::GuiTextBox Class Reference

Text box for entering strings. More...

Inherits G3D::GuiControl.

Inherited by G3D::GuiMultiLineTextBox, and G3D::GuiNumberBox< Value >::MyTextBox.

Public Types

enum  Update {
  IMMEDIATE_UPDATE,
  DELAYED_UPDATE
}
 IMMEDIATE_UPDATE - Update the string and fire a GUI_ACTION every time the text is changed DELAYED_UPDATE - Wait until the box loses focus to fire an event and update the string. More...
 

Public Member Functions

 GuiTextBox (GuiContainer *parent, const GuiText &caption, const Pointer< String > &value, Update update, GuiTheme::TextBoxStyle style)
 For use when building larger controls out of GuiNumberBox. More...
 
const GuiTextcaption () const
 
float captionHeight () const
 For controls that have a caption outside the bounds of the control on the top or bottom, this is the size reserved for the caption. More...
 
float captionWidth () const
 For controls that have a caption outside the bounds of the control on the left, this is the size reserved for the caption. More...
 
const Rect2DclickRect () const
 Used by GuiContainers. More...
 
virtual float defaultCaptionHeight () const
 Default caption size for this control. More...
 
virtual float defaultCaptionWidth () const
 
bool enabled () const
 
virtual void findControlUnderMouse (Vector2 mouse, GuiControl *&control)
 Return the enabled, visible control containing the mouse. More...
 
bool focused () const
 
Vector2 fromOSWindowCoords (const Vector2 &v) const
 Transforms v from OS window coordinates to this control's coordinates. More...
 
String highlightedText ()
 Returns copy of highlighted text. More...
 
bool mouseOver () const
 
void moveBy (const Vector2 &delta)
 
void moveBy (float dx, float dy)
 
virtual void moveCursorEnd ()
 Moves cursor to end position (End key). More...
 
virtual void moveCursorHome ()
 Moves cursor to home position (Home key). More...
 
void moveRightOf (const GuiControl *control, const Vector2 &offset)
 If these two controls have the same parent, move this one immediately to the right of the argument. More...
 
void moveRightOf (const GuiControl *control, float offsetX=0.0f)
 
const Rect2Drect () const
 
virtual void render (RenderDevice *rd, const shared_ptr< GuiTheme > &theme, bool ancestorsEnabled) const override
 
Only methods on theme may be called from this method by default. More...
 
virtual void setCaption (const GuiText &caption)
 
virtual void setCaptionHeight (float c)
 
virtual void setCaptionWidth (float c)
 
virtual void setEnabled (bool e)
 
void setEventSource (GuiControl *c)
 
void setFocused (bool b)
 Grab or release keyboard focus. More...
 
void setHeight (float h)
 
void setPosition (const Vector2 &v)
 
void setPosition (float x, float y)
 
virtual void setRect (const Rect2D &) override
 If you explicitly change the rectangle of a control, the containing pane may clip its borders. More...
 
void setSize (const Vector2 &v)
 
void setSize (float x, float y)
 
void setVisible (bool b)
 
void setWidth (float w)
 
shared_ptr< GuiThemetheme () const
 
virtual bool toolStyle () const
 Return true if this is in tool button style. More...
 
Vector2 toOSWindowCoords (const Vector2 &v) const
 Returns the coordinates of v, which is in the coordinate system of this object, relative to the OSWindow on which it will be rendered. More...
 
Rect2D toOSWindowCoords (const Rect2D &r) const
 
bool visible () const
 
GuiWindowwindow () const
 Get the window containing this control. More...
 

Protected Types

enum  {
  LEFT_CAPTION_WIDTH = 80,
  TOP_CAPTION_HEIGHT = 20
}
 

Protected Member Functions

void backspaceCharacter ()
 
virtual void commit ()
 Called to change the value to the typed value. More...
 
virtual int coordsToCursorPos (Vector2 coords)
 
void deleteCharacter ()
 
void fireEvent (GEventType type)
 Fires an event. More...
 
Vector2int32 highlightedRange ()
 Returns begin and end indices of highlighted string in left-to-right order. More...
 
void insertCharacter (char c)
 Inserts character at cursor position and fires update events. More...
 
void moveCursorLeft ()
 
void moveCursorRight ()
 
virtual bool onEvent (const GEvent &event) override
 Events are only delivered (by GuiWindow) to a GuiControl when the control has the key focus. More...
 
void processRepeatKeysym ()
 Called from render and onEvent to enact the action triggered by the repeat key. More...
 
void replaceHighlightedText (const String &s)
 
void setRepeatKeysym (GKeySym key)
 Called from onEvent when a key is pressed. More...
 
void stopHighlighting ()
 
void unsetRepeatKeysym ()
 Called from onEvent when the repeat key is released. More...
 

Protected Attributes

GuiText m_caption
 
float m_captionHeight
 
float m_captionWidth
 
Rect2D m_clickRect
 Rect bounds used for mouse actions. More...
 
GuiText m_cursor
 String to be used as the cursor character. More...
 
int m_cursorPos
 Character position in m_userValue of the cursor. More...
 
bool m_editing
 True if currently being edited, that is, if the user has changed the string more recently than the program has changed it. More...
 
bool m_enabled
 
GuiControlm_eventSource
 Sent events should appear to be from this object, which is usually "this". More...
 
GuiWindowm_gui
 The window that ultimately contains this control. More...
 
bool m_highlighting
 True if currently highlighting text with mouse button down. More...
 
int m_highlightPos
 Character position of the highlight start position. More...
 
RealTime m_keyDownTime
 Time at which setRepeatKeysym was called. More...
 
RealTime m_keyRepeatTime
 Time at which the key will repeat (if down). More...
 
String m_oldValue
 Original value before the user started editing. More...
 
GuiContainerm_parent
 Parent pane. More...
 
Rect2D m_rect
 Rect bounds used for rendering and layout. More...
 
GKeySym m_repeatKeysym
 Key that is currently auto-repeating. More...
 
GuiTheme::TextBoxStyle m_style
 
Update m_update
 
String m_userValue
 The value currently being set by the user. More...
 
Pointer< Stringm_value
 The string that this box is associated with. More...
 
bool m_visible
 

Friends

class GuiPane
 
class GuiWindow
 

Detailed Description

Text box for entering strings.

Events:

  1. GEventType::GUI_ACTION when enter is pressed or the box loses focus
  2. GEventType::GUI_CHANGE as text is entered (in IMMEDIATE_UPDATE mode)
  3. GEventType::GUI_CANCEL when ESC is pressed

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
protectedinherited
Enumerator
LEFT_CAPTION_WIDTH 
TOP_CAPTION_HEIGHT 

◆ Update

IMMEDIATE_UPDATE - Update the string and fire a GUI_ACTION every time the text is changed DELAYED_UPDATE - Wait until the box loses focus to fire an event and update the string.

Enumerator
IMMEDIATE_UPDATE 
DELAYED_UPDATE 

Constructor & Destructor Documentation

◆ GuiTextBox()

G3D::GuiTextBox::GuiTextBox ( GuiContainer parent,
const GuiText caption,
const Pointer< String > &  value,
Update  update,
GuiTheme::TextBoxStyle  style 
)

For use when building larger controls out of GuiNumberBox.

For making a regular GUI, use GuiPane::addTextBox.

Member Function Documentation

◆ backspaceCharacter()

void G3D::GuiTextBox::backspaceCharacter ( )
protected

◆ caption()

const GuiText& G3D::GuiControl::caption ( ) const
inherited

◆ captionHeight()

float G3D::GuiControl::captionHeight ( ) const
inherited

For controls that have a caption outside the bounds of the control on the top or bottom, this is the size reserved for the caption.

◆ captionWidth()

float G3D::GuiControl::captionWidth ( ) const
inherited

For controls that have a caption outside the bounds of the control on the left, this is the size reserved for the caption.

◆ clickRect()

const Rect2D& G3D::GuiControl::clickRect ( ) const
inlineinherited

Used by GuiContainers.

◆ commit()

virtual void G3D::GuiTextBox::commit ( )
protectedvirtual

Called to change the value to the typed value.

Reimplemented in G3D::GuiNumberBox< Value >::MyTextBox.

Referenced by G3D::GuiNumberBox< Value >::MyTextBox::commit().

◆ coordsToCursorPos()

virtual int G3D::GuiTextBox::coordsToCursorPos ( Vector2  coords)
protectedvirtual

Reimplemented in G3D::GuiMultiLineTextBox.

◆ defaultCaptionHeight()

virtual float G3D::GuiControl::defaultCaptionHeight ( ) const
inlinevirtualinherited

Default caption size for this control.

Reimplemented in G3D::GuiFunctionBox.

◆ defaultCaptionWidth()

virtual float G3D::GuiControl::defaultCaptionWidth ( ) const
inlinevirtualinherited

◆ deleteCharacter()

void G3D::GuiTextBox::deleteCharacter ( )
protected

◆ enabled()

bool G3D::GuiControl::enabled ( ) const
inherited

◆ findControlUnderMouse()

virtual void G3D::GuiControl::findControlUnderMouse ( Vector2  mouse,
GuiControl *&  control 
)
inlinevirtualinherited

Return the enabled, visible control containing the mouse.

The default implementation returns itself if the mouse is within its bounds. GuiContainers should override this to iterate through children. Since only one (non-overlapping) child will write to control, it is sufficient to call this on all children without testing to see if one already wrote to control.

Reimplemented in G3D::GuiNumberBox< Value >, G3D::GuiNumberBox< float >, G3D::GuiNumberBox< int >, G3D::GuiTextureBox, G3D::GuiPane, G3D::GuiScrollPane, G3D::GuiFrameBox, and G3D::GuiTabPane.

Referenced by G3D::GuiNumberBox< int >::findControlUnderMouse().

◆ fireEvent()

void G3D::GuiControl::fireEvent ( GEventType  type)
protectedinherited

Fires an event.

◆ focused()

bool G3D::GuiControl::focused ( ) const
inherited

◆ fromOSWindowCoords()

Vector2 G3D::GuiControl::fromOSWindowCoords ( const Vector2 v) const
inherited

Transforms v from OS window coordinates to this control's coordinates.

◆ highlightedRange()

Vector2int32 G3D::GuiTextBox::highlightedRange ( )
protected

Returns begin and end indices of highlighted string in left-to-right order.

◆ highlightedText()

String G3D::GuiTextBox::highlightedText ( )

Returns copy of highlighted text.

◆ insertCharacter()

void G3D::GuiTextBox::insertCharacter ( char  c)
protected

Inserts character at cursor position and fires update events.

◆ mouseOver()

bool G3D::GuiControl::mouseOver ( ) const
inherited

◆ moveBy() [1/2]

void G3D::GuiControl::moveBy ( const Vector2 delta)
inherited

◆ moveBy() [2/2]

void G3D::GuiControl::moveBy ( float  dx,
float  dy 
)
inherited

◆ moveCursorEnd()

virtual void G3D::GuiTextBox::moveCursorEnd ( )
virtual

Moves cursor to end position (End key).

Reimplemented in G3D::GuiMultiLineTextBox.

◆ moveCursorHome()

virtual void G3D::GuiTextBox::moveCursorHome ( )
virtual

Moves cursor to home position (Home key).

Reimplemented in G3D::GuiMultiLineTextBox.

◆ moveCursorLeft()

void G3D::GuiTextBox::moveCursorLeft ( )
protected

◆ moveCursorRight()

void G3D::GuiTextBox::moveCursorRight ( )
protected

◆ moveRightOf() [1/2]

void G3D::GuiControl::moveRightOf ( const GuiControl control,
const Vector2 offset 
)
inherited

If these two controls have the same parent, move this one immediately to the right of the argument.

Parameters
offsetMay be negative

Referenced by G3D::GuiControl::moveRightOf().

◆ moveRightOf() [2/2]

void G3D::GuiControl::moveRightOf ( const GuiControl control,
float  offsetX = 0.0f 
)
inlineinherited

◆ onEvent()

virtual bool G3D::GuiTextBox::onEvent ( const GEvent event)
overrideprotectedvirtual

Events are only delivered (by GuiWindow) to a GuiControl when the control has the key focus.

If the control does not consume the event, the event is delivered to each of its GUI parents in order, back to the window's root pane.

Key focus is transferred during a mouse down event.

Reimplemented from G3D::GuiControl.

Reimplemented in G3D::GuiMultiLineTextBox.

◆ processRepeatKeysym()

void G3D::GuiTextBox::processRepeatKeysym ( )
protected

Called from render and onEvent to enact the action triggered by the repeat key.

◆ rect()

const Rect2D& G3D::GuiControl::rect ( ) const
inherited

◆ render()

virtual void G3D::GuiTextBox::render ( RenderDevice rd,
const shared_ptr< GuiTheme > &  theme,
bool  ancestorsEnabled 
) const
overridevirtual


Only methods on theme may be called from this method by default.

To make arbitrary RenderDevice calls, wrap them in GuiTheme::pauseRendering ... GuiTheme::resumeRendering.

Parameters
ancestorsEnabledDraw as disabled if this is false or if enabled() is false.

Implements G3D::GuiControl.

Reimplemented in G3D::GuiMultiLineTextBox.

Referenced by G3D::GuiNumberBox< int >::render().

◆ replaceHighlightedText()

void G3D::GuiTextBox::replaceHighlightedText ( const String s)
protected

◆ setCaption()

virtual void G3D::GuiControl::setCaption ( const GuiText caption)
virtualinherited

◆ setCaptionHeight()

virtual void G3D::GuiControl::setCaptionHeight ( float  c)
virtualinherited

◆ setCaptionWidth()

virtual void G3D::GuiControl::setCaptionWidth ( float  c)
virtualinherited

◆ setEnabled()

virtual void G3D::GuiControl::setEnabled ( bool  e)
virtualinherited

◆ setEventSource()

void G3D::GuiControl::setEventSource ( GuiControl c)
inlineinherited

◆ setFocused()

void G3D::GuiControl::setFocused ( bool  b)
inherited

Grab or release keyboard focus.

◆ setHeight()

void G3D::GuiControl::setHeight ( float  h)
inherited

◆ setPosition() [1/2]

void G3D::GuiControl::setPosition ( const Vector2 v)
inherited

◆ setPosition() [2/2]

void G3D::GuiControl::setPosition ( float  x,
float  y 
)
inherited

◆ setRect()

virtual void G3D::GuiTextBox::setRect ( const Rect2D rect)
overridevirtual

If you explicitly change the rectangle of a control, the containing pane may clip its borders.

Call pack() on the containing pane (or window) to resize that container appropriately.

Reimplemented from G3D::GuiControl.

Referenced by G3D::GuiNumberBox< int >::setRect().

◆ setRepeatKeysym()

void G3D::GuiTextBox::setRepeatKeysym ( GKeySym  key)
protected

Called from onEvent when a key is pressed.

◆ setSize() [1/2]

void G3D::GuiControl::setSize ( const Vector2 v)
inherited

◆ setSize() [2/2]

void G3D::GuiControl::setSize ( float  x,
float  y 
)
inherited

◆ setVisible()

void G3D::GuiControl::setVisible ( bool  b)
inherited

◆ setWidth()

void G3D::GuiControl::setWidth ( float  w)
inherited

◆ stopHighlighting()

void G3D::GuiTextBox::stopHighlighting ( )
protected

◆ theme()

shared_ptr<GuiTheme> G3D::GuiControl::theme ( ) const
inherited

◆ toolStyle()

virtual bool G3D::GuiControl::toolStyle ( ) const
inlinevirtualinherited

Return true if this is in tool button style.

Reimplemented in G3D::GuiRadioButton, G3D::GuiButton, and G3D::GuiCheckBox.

◆ toOSWindowCoords() [1/2]

Vector2 G3D::GuiControl::toOSWindowCoords ( const Vector2 v) const
inherited

Returns the coordinates of v, which is in the coordinate system of this object, relative to the OSWindow on which it will be rendered.

Referenced by G3D::GuiControl::toOSWindowCoords().

◆ toOSWindowCoords() [2/2]

Rect2D G3D::GuiControl::toOSWindowCoords ( const Rect2D r) const
inlineinherited

◆ unsetRepeatKeysym()

void G3D::GuiTextBox::unsetRepeatKeysym ( )
protected

Called from onEvent when the repeat key is released.

◆ visible()

bool G3D::GuiControl::visible ( ) const
inherited

◆ window()

GuiWindow* G3D::GuiControl::window ( ) const
inherited

Get the window containing this control.

Friends And Related Function Documentation

◆ GuiPane

friend class GuiPane
friend

◆ GuiWindow

friend class GuiWindow
friend

Member Data Documentation

◆ m_caption

GuiText G3D::GuiControl::m_caption
protectedinherited

◆ m_captionHeight

float G3D::GuiControl::m_captionHeight
protectedinherited

◆ m_captionWidth

float G3D::GuiControl::m_captionWidth
protectedinherited

◆ m_clickRect

Rect2D G3D::GuiControl::m_clickRect
protectedinherited

Rect bounds used for mouse actions.

Updated by setRect.

Referenced by G3D::GuiControl::clickRect().

◆ m_cursor

GuiText G3D::GuiTextBox::m_cursor
protected

String to be used as the cursor character.

◆ m_cursorPos

int G3D::GuiTextBox::m_cursorPos
protected

Character position in m_userValue of the cursor.

◆ m_editing

bool G3D::GuiTextBox::m_editing
protected

True if currently being edited, that is, if the user has changed the string more recently than the program has changed it.

◆ m_enabled

bool G3D::GuiControl::m_enabled
protectedinherited

◆ m_eventSource

GuiControl* G3D::GuiControl::m_eventSource
protectedinherited

Sent events should appear to be from this object, which is usually "this".

Other controls can set the event source to create compound controls that seem atomic from the outside.

Referenced by G3D::GuiSlider< int >::GuiSlider(), G3D::GuiNumberBox< Value >::MyTextBox::MyTextBox(), and G3D::GuiControl::setEventSource().

◆ m_gui

GuiWindow* G3D::GuiControl::m_gui
protectedinherited

The window that ultimately contains this control.

◆ m_highlighting

bool G3D::GuiTextBox::m_highlighting
protected

True if currently highlighting text with mouse button down.

◆ m_highlightPos

int G3D::GuiTextBox::m_highlightPos
protected

Character position of the highlight start position.

-1 when not highlighting.

◆ m_keyDownTime

RealTime G3D::GuiTextBox::m_keyDownTime
protected

Time at which setRepeatKeysym was called.

◆ m_keyRepeatTime

RealTime G3D::GuiTextBox::m_keyRepeatTime
protected

Time at which the key will repeat (if down).

◆ m_oldValue

String G3D::GuiTextBox::m_oldValue
protected

Original value before the user started editing.

This is used to detect changes in m_value while the user is editing.

◆ m_parent

GuiContainer* G3D::GuiControl::m_parent
protectedinherited

Parent pane.

◆ m_rect

Rect2D G3D::GuiControl::m_rect
protectedinherited

Rect bounds used for rendering and layout.

Relative to the enclosing pane's clientRect.

Referenced by G3D::GuiControl::findControlUnderMouse(), G3D::GuiNumberBox< int >::render(), G3D::GuiNumberBox< int >::setCaption(), and G3D::GuiNumberBox< int >::setRect().

◆ m_repeatKeysym

GKeySym G3D::GuiTextBox::m_repeatKeysym
protected

Key that is currently auto-repeating.

◆ m_style

GuiTheme::TextBoxStyle G3D::GuiTextBox::m_style
protected

◆ m_update

Update G3D::GuiTextBox::m_update
protected

◆ m_userValue

String G3D::GuiTextBox::m_userValue
protected

The value currently being set by the user.

When in IMMEDIATE_UPDATE mode, this is continually synchronized with m_value.

◆ m_value

Pointer<String> G3D::GuiTextBox::m_value
protected

The string that this box is associated with.

This may be out of date if editing and in DELAYED_UPDATE mode.

◆ m_visible

bool G3D::GuiControl::m_visible
protectedinherited

documentation generated on Wed Nov 24 2021 08:01:57 using doxygen 1.8.15