Define a label widget (can dispaly a formated text string and images). Provides the interfaces to be operational.
More...
|
| label () |
|
| label (window, bool visible) |
|
| label (window, const std::string &text, bool visible=true) |
|
| label (window parent, const char *text, bool visible=true) |
|
| label (window, const rectangle &={}, bool visible=true) |
|
label & | transparent (bool) |
| Switchs the label widget to the transparent background mode. More...
|
|
bool | transparent () const noexcept |
|
label & | format (bool) |
| Switches the format mode of the widget. More...
|
|
label & | add_format_listener (std::function< void(command, const std::string &)>) |
|
label & | click_for (window associated_window) noexcept |
| as same as the HTML "for" attribute of a label More...
|
|
nana::size | measure (unsigned allowed_width_in_pixel) const |
|
label & | text_align (align horizontal_align, align_v vertical_align=align_v::top) |
|
| widget_object () |
|
| ~widget_object () |
|
event_type & | events () const |
|
bool | create (window parent_wd, bool visible) |
|
bool | create (window parent_wd, const rectangle &r={}, bool visible=true) |
|
widget_object & | borderless (bool enable) |
|
bool | borderless () const |
|
scheme_type & | scheme () const |
|
void | filter_event (const event_code evt_code, const bool bDisabled) |
|
void | filter_event (const std::vector< event_code > evt_codes, const bool bDisabled) |
|
void | filter_event (const event_filter_status &evt_all_states) |
|
bool | filter_event (const event_code evt_code) |
|
event_filter_status | filter_event () |
|
void | clear_filter () |
|
window | handle () const override |
| Returns the handle of window, returns 0 if window is not created. More...
|
|
| widget ()=default |
|
virtual | ~widget ()=default |
|
bool | empty () const |
| Determines whether the manipulator is handling a window. More...
|
|
void | close () |
|
window | parent () const |
|
::std::string | caption () const noexcept |
|
::std::wstring | caption_wstring () const noexcept |
|
native_string_type | caption_native () const noexcept |
|
widget & | caption (std::string utf8) |
|
widget & | caption (std::wstring) |
|
template<typename... Args> |
void | i18n (std::string msgid, Args &&...args) |
|
void | i18n (i18n_eval) |
|
void | cursor (nana::cursor) |
|
nana::cursor | cursor () const |
| Retrieves the shape of cursor. More...
|
|
void | typeface (const paint::font &font) |
|
paint::font | typeface () const |
|
bool | enabled () const |
| Determines whether the window is enabled for mouse and keyboard input. More...
|
|
void | enabled (bool) |
|
void | enable_dropfiles (bool) |
| Enables/Disables a window to accept dropped files. More...
|
|
void | focus () |
|
bool | focused () const |
|
std::shared_ptr
< scroll_operation_interface > | scroll_operation () |
|
void | show () |
| Sets the window visible. More...
|
|
void | hide () |
| Sets the window invisible. More...
|
|
bool | visible () const |
|
nana::size | size () const |
|
void | size (const nana::size &) |
|
void | set_capture (bool ignore_children) |
| Enables the widget to grab the mouse input. More...
|
|
void | release_capture () |
| Disables the widget to grab the mouse input. More...
|
|
point | pos () const |
|
void | move (int x, int y) |
|
void | move (const point &) |
|
void | move (const rectangle &) |
|
void | fgcolor (const nana::color &) |
|
nana::color | fgcolor () const |
|
void | bgcolor (const nana::color &) |
|
nana::color | bgcolor () const |
|
general_events & | events () const |
|
void | umake_event (event_handle eh) const |
| Deletes an event callback by a handle. More...
|
|
widget & | register_shortkey (wchar_t) |
| Registers a shortkey. To remove a registered key, pass 0. More...
|
|
widget & | take_active (bool activated, window take_if_not_activated) |
|
widget & | tooltip (const ::std::string &) |
|
| operator dummy_bool_type () const |
|
| operator window () const |
|
Define a label widget (can dispaly a formated text string and images). Provides the interfaces to be operational.
A New Label
Notes
- It is not efficient when the background mode of the label is transparent.
- If the caption of a label contains a character '\n', the label will hide the character and display the text string after '\n' in a new line.
- 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_bold.png)
label.caption(STR("Hello, <bold=true, color=0xff0000>This is a bold red text</>"));
![](label_bold_red.png)
label.caption(STR("Hello, <bold=true, color=0xff0000, font=\"Consolas\">This is a bold red Consolas text</>"));
![](label_bold_red_consolas.png)
label.caption(STR("Hello, <bold=true, color=0xff0000, font=\"Consolas\", url=\"http://stdex.sourceforge.net\">This is a bold red Consolas text</>"));
The arrow mouse 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();
}
- 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</>"));
- 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</>"));
![Specifying a proper size](label_image.png)
`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 preserving the aspect ratio when one of its edge is beyonds the specified size.
`min_limited`: stretchs the image to the specified size preserving the aspect ratio when one of its 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</>"));
![A Proper Size](label_image_maxlimited.png) Specifying a proper size
- 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</>"));
![Label Alignment](label_alignment.png)
- Examples:
- a_group_impl.cpp, background-effects.cpp, calculator.cpp, group.cpp, helloword.cpp, helloworld_demo.cpp, label_listener.cpp, MontiHall.cpp, widget_show.cpp, and widget_show2.cpp.