]> git.tdb.fi Git - libs/gltk.git/blob - source/label.cpp
Improve widget part caching
[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         rebuild();
31 }
32
33 void Label::set_text(const string &t)
34 {
35         text = t;
36         signal_autosize_changed.emit();
37         rebuild();
38 }
39
40 void Label::rebuild_special(const Part &part)
41 {
42         if(part.get_name()=="text")
43                 text.build(part, geom, part_cache);
44 }
45
46 void Label::on_style_change()
47 {
48         text.set_style(style);
49 }
50
51
52 Label::Loader::Loader(Label &l):
53         DataFile::DerivedObjectLoader<Label, Widget::Loader>(l)
54 {
55         add("text", &Loader::text);
56 }
57
58 void Label::Loader::text(const string &t)
59 {
60         obj.text = t;
61 }
62
63 } // namespace GLtk
64 } // namespace Msp