Label routines
LabelBase.h contains functions and simple helper classes used to implement Ctrls with text, images and accelerator keys.
Generally, format of text used by LabelBase facilities is either simple multi-line or QTF:
If first character of text is '\1', text is QTF (starting with next character).
If first character is NOT '\1', text is simple multi-line text with '\n' used as line separator.
In both cases, '&' or '\b' are used as accelerator key flags. If '&' should be the part of text, it must be escaped as "&&".
This format is formally named "SmartText".
Note also that U++ normally distributes accelerator keys automatically. Providing accelerator keys is thus usually unnecessary.
String DeAmp(const char *s)
This routine escapes all occurrences of '&' character in source string with "&&" string to avoid using it as access-key flag.
|
Return value |
Escaped string. |
Size GetSmartTextSize(const char *text, Font font = StdFont(), int cx = INT_MAX)
Returns the minimal size of SmartText. If text is multi-paragraph QTF text, width of text is the width of widest paragraph without doing any line breaks (paragraphs are formatted for infinite width).
|
font |
Font for non-QTF text. |
|
Return value |
Size of SmartText. |
int GetSmartTextHeight(const char *s, int cx, Font font = StdFont())
Returns the height of given SmartText for given width. QTF paragraphs are formatted for this width.
|
font |
Font for non-QTF text. |
|
Return value |
Height of SmartText. |
void DrawSmartText(Draw& w, int x, int y, int cx, const char *text, Font font = StdFont(), Color ink = SBlack(), int accesskey = 0, Color qtf_ink = Null)
Paints SmartText to target Draw.
|
font |
Font for non-QTF SmartText. |
|
ink |
Text color for non-QTF SmartText. |
|
accesskey |
Access-key - first corresponding character will be painted with underline. |
|
qtf_ink |
If not Null overrides ink of qtf text and disables the qtf text background - useful to handle selected items. |
Scans input string for access-key.
|
label |
Output string - with access-key removed. |
bool CompareAccessKey(byte accesskey, dword key)
Compares access key to U++ event key value as received by Key virtual method.
|
Return value |
True if values match. |
byte ChooseAccessKey(const char *s, dword used)
Scans input string for suitable access-key.
|
used |
Bit-set of already used access-keys. Bit-mask of specific access-key is defined by Ctrl::AccessKeyBit class method. |
|
Return value |
Access-key or 0 if no suitable access-key found. |
struct DrawLabel
This structure in fact just encapsulates generic label painting routine that otherwise would have way too much parameters.
DrawLabel()
Default constructor. Default values are documented in attributes descriptions.
Size GetSize(int txtcx = INT_MAX) const
Returns the size of label based on current set of attributes. txtcx specifies the maximum width of text.
Size Paint(Draw& w, const Rect& r, bool visibleaccesskey = true) const
Paints the label in given rectangle.
|
visibleacckey |
Access-keys should be graphically highlighted (underlined). |
|
Return value |
Size of label. |
Size Paint(Draw& w, int x, int y, int cx, int cy, bool visibleaccesskey = true) const
Paints the label in given rectangle.
|
x, y, cx, cy |
Position and size of rectangle. |
|
visibleacckey |
Access-keys should be graphically highlighted (underlined). |
|
Return value |
Size of label. |
bool push
Label should be painted as "pushed" (means paint offset one pixel right and down). Default is false.
bool focus
Label should be painted as "with input focus" (light blue rectangle is drawn around label). Default is false.
bool disabled
Label should be painted as "disable" (affects the way how images and text are painted, disabled mean they are gray).
PaintRect paintrect
This paintrect is painted behind the label text. If label text is empty, size of text area is determined as paintrect.GetSize().
Image limg
Left image.
Color lcolor
Color of left monochromatic image. Null means that the image is color.
int lspc
Space between left image and text. If Null, image is placed at left edge of Label.
String text
Text of label.
Font font
Font used to paint non-QTF text.
Color ink
Color used to paint non-QTF text.
Image rimg
Right image.
Color rcolor
Color of monochromatic right image. Null means that the image is color.
int rspc
Space between the right image and text. If Null, image is placed at the right size of Label.
int align
Horizontal alignment. Can be ALIGN_LEFT, ALIGN_RIGHT or ALIGN_CENTER.
int valign
Vertical alignment. Can be ALIGN_TOP, ALIGN_BOTTOM or ALIGN_CENTER.
bool nowrap
When true (default false), no text wrapping is performed.
int accesskey
Access-key.
class LabelBase
This class encapsulates basic DrawLabel struct into form suitable to play a role of base class of GUI elements.
virtual void LabelUpdate()
This virtual method is called each time when any of attributes changes.
LabelBase& SetLeftImage(const Image& bmp1, int spc = 0)
Sets the left image.
|
spc |
Space between left image and text. If Null, image is placed at left size of Label. |
|
Return value |
*this for chaining. |
LabelBase& SetPaintRect(const PaintRect& pr)
Sets PaintRect to be drawn behind or instead of label text.
|
Return value |
*this for chaining. |
LabelBase& SetText(const char *text)
Sets text of the label.
|
Return value |
*this for chaining. |
LabelBase& SetFont(Font font)
Sets font of non-QTF text.
|
Return value |
*this for chaining. |
LabelBase& SetInk(Color color)
Sets the color of non-QTF text .
|
Return value |
*this for chaining. |
LabelBase& SetRightImage(const Image& bmp2, int spc = 0)
Sets the right image.
|
spc |
Space between left image and text. If Null, image is placed at left size of Label. |
|
Return value |
*this for chaining. |
LabelBase& SetAlign(int align)
Sets horizontal alignment.
|
align |
One of ALIGN_LEFT, ALIGN_RIGHT or ALIGN_CENTER. |
|
Return value |
*this for chaining. |
LabelBase& AlignLeft()
Same as SetAlign(ALIGN_LEFT).
LabelBase& AlignCenter()
Same as SetAlign(ALIGN_CENTER).
LabelBase& AlignRight()
Same as SetAlign(ALIGN_RIGHT).
LabelBase& SetVAlign(int align)
Sets vertical alignment.
|
align |
One of ALIGN_TOP, ALIGN_BOTTOM or ALIGN_CENTER. |
|
Return value |
*this for chaining. |
LabelBase& AlignTop()
Same as SetVAlign(ALIGN_TOP).
LabelBase& AlignVCenter()
Same as SetVAlign(ALIGN_CENTER).
LabelBase& AlignBottom()
Same as SetVAlign(ALIGN_BOTTOM).
LabelBase& NoWrap(bool b = true)
When active (default false), now text wrapping is performed.
LabelBase& SetImage(const Image& bmp, int spc = 0)
Same as SetLeftImage(bmp, spc).
int GetAlign() const
|
Return value |
Current horizontal alignment. |
int GetVAlign() const
|
Return value |
Current vertical alignment. |
PaintRect GetPaintRect() const
|
Return value |
Current PaintRect. |
String GetText() const
|
Return value |
Current label text. |
Font GetFont() const
|
Return value |
Current font. |
Color GetInk() const
|
Return value |
Current text color. |
Size PaintLabel(Draw& w, const Rect& r, bool disabled = false, bool push = false, bool focus = false, bool vak = true)
Paints label in the given rectangle.
|
vak |
If true, accelerator should be highlighted. |
|
Return value |
Size of label. |
Size PaintLabel(Draw& w, int x, int y, int cx, int cy, bool disabled = false, bool push = false, bool focus = false, bool vak = true)
Paints label in the given rectangle.
|
vak |
If true, accelerator should be highlighted. |
|
Return value |
Size of label. |
Size GetLabelSize() const
|
Return value |
Size of label. |
|