]> git.tdb.fi Git - libs/gltk.git/blob - source/label.cpp
Strip copyright messages and id tags from individual files
[libs/gltk.git] / source / label.cpp
1 #include "label.h"
2 #include "part.h"
3 #include "style.h"
4
5 using namespace std;
6
7 namespace Msp {
8 namespace GLtk {
9
10 Label::Label(const string &t)
11 {
12         focusable = false;
13         set_text(t);
14 }
15
16 void Label::autosize()
17 {
18         if(!style)
19                 return;
20
21         Widget::autosize();
22
23         if(const Part *text_part = style->get_part("text"))
24         {
25                 const Sides &margin = text_part->get_margin();
26                 geom.w = max(geom.w, text.get_width()+margin.left+margin.right);
27                 geom.h = max(geom.h, text.get_height()+margin.top+margin.bottom);
28         }
29 }
30
31 void Label::set_text(const string &t)
32 {
33         text = t;
34         signal_autosize_changed.emit();
35 }
36
37 void Label::render_special(const Part &part) const
38 {
39         if(part.get_name()=="text")
40                 text.render(part, geom);
41 }
42
43 void Label::on_style_change()
44 {
45         text.set_style(style);
46 }
47
48
49 Label::Loader::Loader(Label &l):
50         Widget::Loader(l)
51 {
52         add("text", &Loader::text);
53 }
54
55 void Label::Loader::text(const string &t)
56 {
57         static_cast<Label &>(obj).text = t;
58 }
59
60 } // namespace GLtk
61 } // namespace Msp