Nana C++ Library
open-source C++ framework project The Programmer's Guide |
||||||||||||||||||||||||||||||||
nana::gui::label Description A label widget can dispaly a text string and images. Model of Widget Window Public base classes class widget_object<widget_tag>: public widget Typedefs C++ 03
C++11
Members
C++03
C++11
File nana/gui/widgets/label.hpp Notes 1. It is not good efficient that the background mode of the label is transparent. 2. If the caption of a lable contains a character '\n', the label will hide the character and display the text string after '\n' in a new line. 3. The format mode accepts the definition for displaying mutile-style text. For example. label.format(true); label.caption(STR("Hello, <bold=true>This is a bold text</>")); label.caption(STR("Hello, <bold=true color=0xff0000>This is a bold red text</>")); label.caption(STR("Hello <bold=true color=0xff0000 font=\"Consolas\">This is a bold red Consolas text</>")); label.caption(STR("Hello, <bold=true color=0xff0000 font=\"Consolas\" url=\"http://nanapro.sourceforge.net\">This is a bold red Consolas text</>")); Arrow cursor becomes a hand when the cursor moves over the red text. Meanwhile, it is open a web browser to open the URL by clicking the red text.[NOTE: the url only works under Windows] using namespace nana::gui; //void listener(label::command cmd, const nana::string& s) //C++11 void listener(label::command::t cmd, const nana::string& s) { if(label::command::click == cmd) { msgbox mb(STR("target clicked")); mb<<STR("the target \"")<<s<<"\" is clicked"; mb(); } } int main() { form fm; label lab(fm, nana::rectangle(0, 0, 100, 40)); lab.format(true); lab.add_format_listener(listener); lab.caption(STR("Click <color=0xFF target=\"target id\">here</>")); fm.show(); exec(); } 4, Some reserved words: red, green, blue, white, black. It can simplify the format text and increas it readable. lab.caption(STR("Click <color=0xFF target=\"target id\">here</>")); vs lab.caption(STR("Click <blue target=\"target id\">here</>")); 5, Image is supported for format mode. lab.caption(STR("<image=\"file.bmp\"><bold red size=20>Nana C++ Library</>")); As you see, the image tag has not a close-tag </> Defaultly, the image is displayed with its orignal size. With specifying a size, we can get a proper size by which the image is displayed. label.caption(STR("<image=\"file.bmp\" size=(150,150)><bold red size=20>Nana C++ Library</>")); size=(150,150) means that it stretchs the image to the specified size. In many situations, we want to display the image as it is if it is greater than/less than a specified size. There are two reserved words can achieve it. max_limited: stretchs the image to the specified size with preserving aspect ratio when its one of edge beyonds the specified size. min_limited: stretchs the image to the specified size with preserving aspect ratio when its one of edge is less than the specified size. label.caption(STR("<image=\"file.bmp\" size=(150,150) max_limited><bold red size=20>Nana C++ Library</>")); 6, Alignments for format mode. Defaulty, the alignment is baseline-aligned. The library provides 4 kinds of alignment which are: top, center, bottom and baseline. They are useful tools when display texts with different size in a line. label.caption(STR("<size=12 top>top</><size=14 center>center<size=16 bottom>bottom</><size=30>baseline</><size=10>small font by baseline</>")); See also None. Move to The Nana Programmer's Guide Main Page |
||||||||||||||||||||||||||||||||