GG: GG::TextControl Class Reference

GG

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

List of all members
GG::TextControl Class Reference

`#include <TextControl.h>`

Inheritance diagram for GG::TextControl:

## Structors
| TextControl (X x, Y y, X w, Y h, const std::string &str, const boost::shared_ptr< Font > &font, Clr color=CLR_BLACK, Flags< TextFormat > format=FORMAT_NONE, Flags< WndFlag > flags=Flags< WndFlag >())
| TextControl (X x, Y y, const std::string &str, const boost::shared_ptr< Font > &font, Clr color=CLR_BLACK, Flags< TextFormat > format=FORMAT_NONE, Flags< WndFlag > flags=Flags< WndFlag >())
| TextControl ()

## Accessors
virtual Pt | MinUsableSize () const
const std::string & | Text () const
Flags< TextFormat > | GetTextFormat () const
Clr | TextColor () const
bool | ClipText () const
bool | SetMinSize () const
template<class T >
void | operator>> (T &t) const
template<class T >
T | GetValue () const
| operator const std::string & () const
bool | Empty () const
CPSize | Length () const
Pt | TextUpperLeft () const
Pt | TextLowerRight () const
const std::vector < Font::LineData > & | GetLineData () const
const boost::shared_ptr< Font > & | GetFont () const
bool | FitToText () const

## Mutators
virtual void | Render ()
virtual void | SetText (const std::string &str)
virtual void | SizeMove (const Pt &ul, const Pt &lr)
void | SetTextFormat (Flags< TextFormat > format)
void | SetTextColor (Clr color)
virtual void | SetColor (Clr c)
void | ClipText (bool b)
void | SetMinSize (bool b)
template<class T >
void | operator<< (T t)
void | operator+= (const std::string &s)
void | operator+= (char c)
void | Clear ()
void | Insert (CPSize pos, char c)
void | Insert (CPSize pos, const std::string &s)
void | Erase (CPSize pos, CPSize num=CP1)
void | Insert (std::size_t line, CPSize pos, char c)
void | Insert (std::size_t line, CPSize pos, const std::string &s)
void | Erase (std::size_t line, CPSize pos, CPSize num=CP1)

## Additional Inherited Members
Public Types inherited from GG::Wnd
enum | ChildClippingMode { DontClip, ClipToClient, ClipToWindow, ClipToClientAndWindowSeparately }
typedef std::map< const Wnd *, bool >::iterator | DropsAcceptableIter
Public Member Functions inherited from GG::Control
virtual void | DropsAcceptable (DropsAcceptableIter first, DropsAcceptableIter last, const Pt &pt) const
Clr | Color () const
bool | Disabled () const
virtual void | AcceptDrops (const std::vector< Wnd * > &wnds, const Pt &pt)
virtual void | Disable (bool b=true)
Public Member Functions inherited from GG::Wnd
virtual | ~Wnd ()
bool | Interactive () const
bool | RepeatButtonDown () const
bool | Dragable () const
bool | Resizable () const
bool | OnTop () const
bool | Modal () const
ChildClippingMode | GetChildClippingMode () const
bool | NonClientChild () const
bool | Visible () const
const std::string & | Name () const
const std::string & | DragDropDataType () const
Pt | UpperLeft () const
Pt | LowerRight () const
Pt | RelativeUpperLeft () const
Pt | RelativeLowerRight () const
X | Width () const
Y | Height () const
int | ZOrder () const
Pt | Size () const
Pt | MinSize () const
Pt | MaxSize () const
virtual Pt | ClientUpperLeft () const
virtual Pt | ClientLowerRight () const
Pt | ClientSize () const
X | ClientWidth () const
Y | ClientHeight () const
Pt | ScreenToWindow (const Pt &pt) const
Pt | ScreenToClient (const Pt &pt) const
virtual bool | InWindow (const Pt &pt) const
virtual bool | InClient (const Pt &pt) const
const std::list< Wnd * > & | Children () const
Wnd * | Parent () const
Wnd * | RootParent () const
Layout * | GetLayout () const
Layout * | ContainingLayout () const
const std::vector < BrowseInfoMode > & | BrowseModes () const
const std::string & | BrowseInfoText (std::size_t mode) const
const boost::shared_ptr < StyleFactory > & | GetStyleFactory () const
virtual WndRegion | WindowRegion (const Pt &pt) const
void | SetDragDropDataType (const std::string &data_type)
virtual void | StartingChildDragDrop (const Wnd *wnd, const Pt &offset)
virtual void | CancellingChildDragDrop (const std::vector< const Wnd * > &wnds)
virtual void | ChildrenDraggedAway (const std::vector< Wnd * > &wnds, const Wnd *destination)
void | SetName (const std::string &name)
void | Hide (bool children=true)
void | Show (bool children=true)
virtual void | ModalInit ()
void | SetChildClippingMode (ChildClippingMode mode)
void | NonClientChild (bool b)
void | MoveTo (const Pt &pt)
void | OffsetMove (const Pt &pt)
void | Resize (const Pt &sz)
void | SetMinSize (const Pt &sz)
void | SetMaxSize (const Pt &sz)
void | AttachChild (Wnd *wnd)
void | MoveChildUp (Wnd *wnd)
void | MoveChildDown (Wnd *wnd)
void | DetachChild (Wnd *wnd)
void | DetachChildren ()
void | DeleteChild (Wnd *wnd)
void | DeleteChildren ()
void | InstallEventFilter (Wnd *wnd)
void | RemoveEventFilter (Wnd *wnd)
void | HorizontalLayout ()
void | VerticalLayout ()
void | GridLayout ()
void | SetLayout (Layout *layout)
void | RemoveLayout ()
Layout * | DetachLayout ()
void | SetLayoutBorderMargin (unsigned int margin)
void | SetLayoutCellMargin (unsigned int margin)
virtual bool | Run ()
void | EndRun ()
void | SetBrowseModeTime (unsigned int time, std::size_t mode=0)
void | SetBrowseInfoWnd (const boost::shared_ptr< BrowseInfoWnd > &wnd, std::size_t mode=0)
void | ClearBrowseInfoWnd (std::size_t mode=0)
void | SetBrowseText (const std::string &text, std::size_t mode=0)
void | SetBrowseModes (const std::vector< BrowseInfoMode > &modes)
void | SetStyleFactory (const boost::shared_ptr< StyleFactory > &factory)
| GG_ABSTRACT_EXCEPTION (Exception)
| GG_CONCRETE_EXCEPTION (BadLayout, GG::Wnd, Exception)
Static Public Member Functions inherited from GG::Wnd
static unsigned int | DefaultBrowseTime ()
static void | SetDefaultBrowseTime (unsigned int time)
static const boost::shared_ptr < BrowseInfoWnd > & | DefaultBrowseInfoWnd ()
static void | SetDefaultBrowseInfoWnd (const boost::shared_ptr< BrowseInfoWnd > &browse_info_wnd)
Protected Types inherited from GG::Wnd
enum | DragDropRenderingState { NOT_DRAGGED, IN_PLACE_COPY, DRAGGED_OVER_UNACCEPTING_DROP_TARGET, DRAGGED_OVER_ACCEPTING_DROP_TARGET }
Protected Member Functions inherited from GG::Control
virtual void | MouseWheel (const Pt &pt, int move, Flags< ModKey > mod_keys)
virtual void | KeyPress (Key key, boost::uint32_t key_code_point, Flags< ModKey > mod_keys)
virtual void | KeyRelease (Key key, boost::uint32_t key_code_point, Flags< ModKey > mod_keys)
| Control ()
| Control (X x, Y y, X w, Y h, Flags< WndFlag > flags=INTERACTIVE)
Protected Attributes inherited from GG::Control
Clr | m_color
bool | m_disabled

## Detailed Description

Displays a piece of text.

TextControl's know how to center, left- or right-justify, etc. themselves within their window areas. The format flags used with TextControl are defined in the TextFormat flag type. TextControl has std::string-like operators and functions that allow the m_text member string to be manipulated directly. In addition, the << and >> operators allow virtually any type (int, float, char, etc.) to be read from a TextControl object as if it were an input or output stream, thanks to boost::lexical_cast. Note that the TextControl stream operators only read the first instance of the specified type from m_text, and overwrite the entire m_text string when writing to it; both operators may throw.

TextControl is based on pre-rendered font glyphs. The text is rendered character by character from a prerendered font. The font used is gotten from the GUI's font manager. Since a shared_ptr to the font is kept, the font is guaranteed to exist at least as long as the TextControl object that refers to it. This also means that if the font is explicitly released from the font manager but is still held by at least one TextControl object, it will not be destroyed, due to the shared_ptr. Note that if "" is supplied as the font_filename parameter, no text will be rendered, but a valid TextControl object will be constructed, which may later contain renderable text. TextControl objects support text with formatting tags. See GG::Font for details.

Definition at line 65 of file TextControl.h.

## Constructor & Destructor Documentation

GG::TextControl::TextControl | ( | X | x,
|  | Y | y,
|  | X | w,
|  | Y | h,
|  | const std::string & | str,
|  | const boost::shared_ptr< Font > & | font,
|  | Clr | color = `CLR_BLACK`,
|  | Flags< TextFormat > | format = `FORMAT_NONE`,
|  | Flags< WndFlag > | flags = `Flags< WndFlag >()`
| ) |  |

Ctor.

GG::TextControl::TextControl | ( | X | x,
|  | Y | y,
|  | const std::string & | str,
|  | const boost::shared_ptr< Font > & | font,
|  | Clr | color = `CLR_BLACK`,
|  | Flags< TextFormat > | format = `FORMAT_NONE`,
|  | Flags< WndFlag > | flags = `Flags< WndFlag >()`
| ) |  |

Ctor that does not require window size. Window size is determined from the string and font; the window will be large enough to fit the text as rendered, and no larger. The private member FitToText() will also return true.

See Also
  TextControl::SetText()

## Member Function Documentation

virtual Pt GG::TextControl::MinUsableSize | ( |  | ) | const
| virtual

Returns the size of the minimum bounding box that can enclose the Wnd and still show all of its elements, plus enough room for interaction with those elements (if applicable). For example, a TextControl's MinUsableSize() is just the area of its text, and a Scroll's MinUsableSize() is the combined sizes of its up-button, down-button, and tab (plus a bit of room in which to drag the tab).

Reimplemented from GG::Wnd.

Reimplemented in GG::StateButton, GG::Edit, and GG::MultiEdit.

const std::string& GG::TextControl::Text | ( |  | ) | const

Returns the text displayed in this control.

Flags<TextFormat> GG::TextControl::GetTextFormat | ( |  | ) | const

Returns the text format (vertical and horizontal justification, use of word breaks and line wrapping, etc.)

Clr GG::TextControl::TextColor | ( |  | ) | const

Returns the text color (this may differ from the Control::Color() in some subclasses)

bool GG::TextControl::ClipText | ( |  | ) | const

Returns true iff the text control clips its text to its client area; by default this is not done.

bool GG::TextControl::SetMinSize | ( |  | ) | const

Returns true iff the text control sets its MinSize() when the bounds of its text change because of a call to SetText() or SetTextFormat(); by default this is not done. The minimum size of the control in each dimension will be the larger of the text size and the current MinSize(), if any has been set. Note that this operates independently of fit-to-text behavior, which sets the window size, not its minimum size.

template<class T >

void GG::TextControl::operator>> | ( | T & | t | ) | const

Sets the value of t to the interpreted value of the control's text. If the control's text can be interpreted as an object of type T by boost::lexical_cast (and thus by a stringstream), then the >> operator will do so. Note that the return type is void, so multiple >> operations cannot be strung together. Also, because lexical_cast attempts to convert the entire contents of the string to a single value, a TextControl containing the string "4.15 3.8" will fill a float with 0.0 (the default construction of float), even though there is a perfectly valid 4.15 value that occurs first in the string.

Note
  boost::lexical_cast usually throws boost::bad_lexical_cast when it cannot perform a requested cast, though >> will return a default-constructed T if one cannot be deduced from the control's text.

Definition at line 265 of file TextControl.h.

template<class T >

T GG::TextControl::GetValue | ( |  | ) | const

Returns the value of the control's text, interpreted as an object of type T. If the control's text can be interpreted as an object of type T by boost::lexical_cast (and thus by a stringstream), then GetValue() will do so. Because lexical_cast attempts to convert the entire contents of the string to a single value, a TextControl containing the string "4.15 3.8" will throw, even though there is a perfectly valid 4.15 value that occurs first in the string.

Exceptions

  boost::bad_lexical_cast | boost::lexical_cast throws boost::bad_lexical_cast when it cannot perform a requested cast. This is handy for validating data in a dialog box; Otherwise, using operator>>(), you may get the default value, even though the text in the control may not be the default value at all, but garbage.

Definition at line 275 of file TextControl.h.

GG::TextControl::operator const std::string & | ( |  | ) | const

Returns the control's text; allows TextControl's to be used as std::string's.

Pt GG::TextControl::TextUpperLeft | ( |  | ) | const

Returns the upper-left corner of the text as it is would be rendered if it were not bound to the dimensions of this control.

Pt GG::TextControl::TextLowerRight | ( |  | ) | const

Returns the lower-right corner of the text as it is would be rendered if it were not bound to the dimensions of this control.

virtual void GG::TextControl::Render | ( |  | ) |
| virtual

Draws this Wnd. Note that Wnds being dragged for a drag-and-drop operation are rendered twice – once in-place as normal, once in the location of the drag operation, attached to the cursor. Such Wnds may wish to render themselves differently in those two cases. To determine which render is being performed, they can call GUI::GetGUI()->RenderingDragDropWnds().

Implements GG::Control.

Reimplemented in GG::StateButton, GG::Edit, GG::MultiEdit, and GG::Button.

virtual void GG::TextControl::SetText | ( | const std::string & | str | ) |
| virtual

Sets the text displayed in this control to str. May resize the window. If FitToText() returns true (i.e. if the second ctor was used), calls to this function cause the window to be resized to whatever space the newly rendered text occupies.

Reimplemented in GG::Edit, and GG::MultiEdit.

virtual void GG::TextControl::SizeMove | ( | const Pt & | ul,
|  | const Pt & | lr
| ) |  |
| virtual

Resizes and/or moves window to new upper-left and lower right boundaries.

Reimplemented from GG::Wnd.

Reimplemented in GG::StateButton, and GG::MultiEdit.

void GG::TextControl::SetTextFormat | ( | Flags< TextFormat > | format | ) |

Sets the text format; ensures that the flags are sane.

void GG::TextControl::SetTextColor | ( | Clr | color | ) |

Sets the text color.

virtual void GG::TextControl::SetColor | ( | Clr | c | ) |
| virtual

Just like Control::SetColor(), except that this one also adjusts the text color.

Reimplemented from GG::Control.

Reimplemented in GG::StateButton, GG::Edit, and GG::Button.

void GG::TextControl::ClipText | ( | bool | b | ) |

Enables/disables text clipping to the client area.

void GG::TextControl::SetMinSize | ( | bool | b | ) |

Enables/disables setting the minimum size of the window to be the text size.

template<class T >

void GG::TextControl::operator<< | ( | T | t | ) |

Sets the value of the control's text to the stringified version of t. If t can be converted to a string representation by a boost::lexical_cast (and thus by a stringstream), then the << operator will do so, e.g. double(4.15) to string("4.15"). Note that the return type is void, so multiple << operations cannot be strung together.

Exceptions

  boost::bad_lexical_cast | boost::lexical_cast throws boost::bad_lexical_cast when it is confused.

Definition at line 279 of file TextControl.h.

void GG::TextControl::Insert | ( | CPSize | pos,
|  | char | c
| ) |  |

Inserts c at position pos within the text.

Note
  Just as with most string parameters throughout GG, c must be a valid UTF-8 sequence.

void GG::TextControl::Insert | ( | CPSize | pos,
|  | const std::string & | s
| ) |  |

Inserts s at position pos within the text.

void GG::TextControl::Erase | ( | CPSize | pos,
|  | CPSize | num = `CP1`
| ) |  |

Erases num code points from the text starting at position pos.

void GG::TextControl::Insert | ( | std::size_t | line,
|  | CPSize | pos,
|  | char | c
| ) |  |

Inserts c at text position pos within line line.

Note
  Just as with most string parameters throughout GG, c must be a valid UTF-8 sequence.

void GG::TextControl::Insert | ( | std::size_t | line,
|  | CPSize | pos,
|  | const std::string & | s
| ) |  |

Inserts s at text position pos within line line.

void GG::TextControl::Erase | ( | std::size_t | line,
|  | CPSize | pos,
|  | CPSize | num = `CP1`
| ) |  |

Erases num code points from the text starting at position pos within line line.

const std::vector<Font::LineData>& GG::TextControl::GetLineData | ( |  | ) | const
| protected

Returns the line data for the text in this TextControl.

const boost::shared_ptr<Font>& GG::TextControl::GetFont | ( |  | ) | const
| protected

Returns the Font used by this TextControl to render its text.

bool GG::TextControl::FitToText | ( |  | ) | const
| protected

Returns true iff this TextControl was constructed using the ctor without width and height parameters.

See Also
  TextControl::SetText()

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

- TextControl.h