11 Toggle::Toggle(const string &t):
20 void Toggle::autosize()
27 if(const Part *text_part = style->get_part("text"))
29 const Sides &margin = text_part->get_margin();
30 geom.w = max(geom.w, text.get_width()+margin.left+margin.right);
31 geom.h = max(geom.h, text.get_height()+margin.top+margin.bottom);
37 void Toggle::set_text(const string &t)
40 signal_autosize_changed.emit();
44 void Toggle::set_exclusive(bool e)
47 if(exclusive && value)
51 void Toggle::exclude_siblings()
53 const list<Widget *> &siblings = parent->get_children();
54 for(list<Widget *>::const_iterator i=siblings.begin(); i!=siblings.end(); ++i)
55 if(Toggle *tgl = dynamic_cast<Toggle *>(*i))
56 if(tgl!=this && tgl->get_exclusive() && tgl->get_value())
57 tgl->set_value(false);
60 void Toggle::set_value(bool v)
66 if(exclusive && parent)
73 void Toggle::rebuild_special(const Part &part, CachedPart &cache)
75 if(part.get_name()=="text")
76 text.build(part, geom, cache);
79 void Toggle::button_press(int, int, unsigned btn)
85 void Toggle::button_release(int x, int y, unsigned btn)
89 if(geom.is_inside_relative(x, y) && (!value || !exclusive))
92 signal_toggled.emit(value);
99 void Toggle::on_style_change()
101 text.set_style(style);
105 Toggle::Loader::Loader(Toggle &t):
108 add("exclusive", &Toggle::exclusive);
109 add("text", &Loader::text);
110 add("value", &Toggle::value);
113 Toggle &Toggle::Loader::get_object() const
115 return static_cast<Toggle &>(obj);
118 void Toggle::Loader::finish()
120 Toggle &tgl = get_object();
121 tgl.set_state(ACTIVE, (tgl.value ? ACTIVE : NORMAL));
124 void Toggle::Loader::text(const string &t)
126 get_object().text = t;