]> git.tdb.fi Git - libs/gltk.git/blob - source/label.cpp
Add method to get a Part by name
[libs/gltk.git] / source / label.cpp
1 /* $Id$
2
3 This file is part of libmspgltk
4 Copyright © 2007  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include "label.h"
9 #include "part.h"
10 #include "style.h"
11
12 using namespace std;
13
14 namespace Msp {
15 namespace GLtk {
16
17 Label::Label(const Resources &r, const string &t):
18         Widget(r),
19         text()
20 {
21         focusable = false;
22         update_style();
23         set_text(t);
24 }
25
26 void Label::autosize()
27 {
28         geom.h = text.get_height();
29         geom.w = text.get_width();
30         if(const Part *text_part = style->get_part("text"))
31         {
32                 const Sides &margin = text_part->get_margin();
33                 geom.w += margin.left+margin.right;
34                 geom.h += margin.top+margin.bottom;
35         }
36 }
37
38 void Label::set_text(const string &t)
39 {
40         text = t;
41 }
42
43 void Label::render_special(const Part &part) const
44 {
45         if(part.get_name()=="text")
46                 text.render(part, geom);
47 }
48
49 void Label::on_style_change()
50 {
51         text.set_style(style);
52 }
53
54
55 Label::Loader::Loader(Label &l):
56         Widget::Loader(l)
57 {
58         add("text", &Loader::text);
59 }
60
61 void Label::Loader::text(const string &t)
62 {
63         static_cast<Label &>(wdg).text = t;
64 }
65
66 } // namespace GLtk
67 } // namespace Msp