TextBlock Class Reference

#include <Pt/Forms/TextBlock.h>

Represents wrapped text as positioned lines. More...

Public Types

typedef TextLineIterator
 Iterator over the laid-out lines.
 
typedef const TextLineConstIterator
 Const iterator over the laid-out lines.
 

Public Member Functions

 TextBlock ()
 Creates an empty text block. More...
 
 ~TextBlock ()
 Destructor.
 
const Gfx::PointFposition () const
 Returns the origin of the block.
 
void setPosition (const Gfx::PointF &p)
 Sets the origin of the block.
 
const Gfx::SizeFsize () const
 Returns the laid-out width and height.
 
double width () const
 Returns the laid-out width.
 
double height () const
 Returns the laid-out height.
 
double maxWidth () const
 Returns the maximum width used to wrap lines.
 
void setMaxWidth (double w)
 Sets the maximum width used to wrap lines.
 
void setAdjustment (Adjustment a)
 Sets the horizontal alignment of each line.
 
Adjustment adjustment () const
 Returns the horizontal alignment of each line.
 
void setLineSpacing (double v)
 Sets extra space between consecutive lines.
 
double lineSpacing () const
 Returns extra space between consecutive lines.
 
Iterator begin ()
 Returns a pointer to the first line, or 0 when empty.
 
Iterator end ()
 Returns a pointer past the last line, or 0 when empty.
 
ConstIterator begin () const
 Returns a pointer to the first line, or 0 when empty.
 
ConstIterator end () const
 Returns a pointer past the last line, or 0 when empty.
 
void layout (const Painter &painter, const Pt::String &text)
 Wraps text into lines using painter's font metrics. More...
 

Detailed Description

A TextBlock is not a Widget and does not own a painter or control. Label and LineEditor use it. A custom control sets the maximum width, adjustment, and line spacing, calls layout(), then iterates the lines to measure or paint the text.

layout() uses the painter's font metrics to wrap a string into TextLine objects. It replaces the previous lines and updates the block size. Wrapping is word-based: whitespace separates words, and explicit newlines are not hard breaks. Adjustment::Left, Adjustment::Right, and Adjustment::Center align each line within the maximum width. Adjustment::Justify is treated as left. The default adjustment is Center.

position() is the block origin and each line position is relative to it. size() returns the laid-out width and height. Line spacing adds extra space between consecutive lines.

Constructor & Destructor Documentation

◆ TextBlock()

TextBlock ( )

The default maximum width is large. The default adjustment is Center.

Member Function Documentation

◆ layout()

void layout ( const Painter painter,
const Pt::String text 
)

Replaces the previous lines and updates size().