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)
45 signal_autosize_changed.emit();
48 void Toggle::set_exclusive(bool e)
51 if(exclusive && value)
55 void Toggle::exclude_siblings()
57 const list<Widget *> &siblings = parent->get_children();
58 for(list<Widget *>::const_iterator i=siblings.begin(); i!=siblings.end(); ++i)
59 if(Toggle *tgl = dynamic_cast<Toggle *>(*i))
60 if(tgl!=this && tgl->get_exclusive() && tgl->get_value())
61 tgl->set_value(false);
64 void Toggle::set_value(bool v)
70 if(exclusive && parent)
77 void Toggle::render_special(const Part &part) const
79 if(part.get_name()=="text")
80 text.render(part, geom);
83 void Toggle::button_press(int, int, unsigned btn)
89 void Toggle::button_release(int x, int y, unsigned btn)
93 if(geom.is_inside_relative(x, y) && (!value || !exclusive))
96 signal_toggled.emit(value);
103 void Toggle::on_style_change()
105 text.set_style(style);
109 Toggle::Loader::Loader(Toggle &t):
112 add("exclusive", &Toggle::exclusive);
113 add("text", &Loader::text);
114 add("value", &Toggle::value);
117 Toggle &Toggle::Loader::get_object() const
119 return static_cast<Toggle &>(obj);
122 void Toggle::Loader::finish()
124 Toggle &tgl = get_object();
128 tgl.state &= ~ACTIVE;
131 void Toggle::Loader::text(const string &t)
133 get_object().text = t;