3 This file is part of libmspgltk
4 Copyright © 2007-2011 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
18 Toggle::Toggle(const string &t):
27 void Toggle::autosize()
34 if(const Part *text_part = style->get_part("text"))
36 const Sides &margin = text_part->get_margin();
37 geom.w = max(geom.w, text.get_width()+margin.left+margin.right);
38 geom.h = max(geom.h, text.get_height()+margin.top+margin.bottom);
42 void Toggle::set_text(const string &t)
47 void Toggle::set_exclusive(bool e)
50 if(exclusive && value)
54 void Toggle::exclude_siblings()
56 const list<Widget *> &siblings = parent->get_children();
57 for(list<Widget *>::const_iterator i=siblings.begin(); i!=siblings.end(); ++i)
58 if(Toggle *tgl = dynamic_cast<Toggle *>(*i))
59 if(tgl!=this && tgl->get_exclusive() && tgl->get_value())
60 tgl->set_value(false);
63 void Toggle::set_value(bool v)
69 if(exclusive && parent)
76 void Toggle::render_special(const Part &part) const
78 if(part.get_name()=="text")
79 text.render(part, geom);
82 void Toggle::button_press(int, int, unsigned btn)
88 void Toggle::button_release(int x, int y, unsigned btn)
92 if(geom.is_inside_relative(x, y) && (!value || !exclusive))
95 signal_toggled.emit(value);
102 void Toggle::on_style_change()
104 text.set_style(style);
108 Toggle::Loader::Loader(Toggle &t):
111 add("exclusive", &Toggle::exclusive);
112 add("text", &Loader::text);
113 add("value", &Toggle::value);
116 Toggle &Toggle::Loader::get_object() const
118 return static_cast<Toggle &>(obj);
121 void Toggle::Loader::finish()
123 Toggle &tgl = get_object();
127 tgl.state &= ~ACTIVE;
130 void Toggle::Loader::text(const string &t)
132 get_object().text = t;