X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftoggle.cpp;h=6d2a10b16644d6254163b53b26c6f92ead7754ce;hb=39cf4c8d917dc60c087fb4af6885bfa78f6fba34;hp=3b896bedb7290451a202f3dcab2efbe2f40cb965;hpb=0af3c2393bd00f39db3bfaf5b78a7a44f0fd5ff1;p=libs%2Fgltk.git diff --git a/source/toggle.cpp b/source/toggle.cpp index 3b896be..6d2a10b 100644 --- a/source/toggle.cpp +++ b/source/toggle.cpp @@ -1,12 +1,6 @@ -/* $Id$ - -This file is part of libmspgltk -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #include "panel.h" #include "part.h" +#include "style.h" #include "toggle.h" using namespace std; @@ -14,20 +8,34 @@ using namespace std; namespace Msp { namespace GLtk { -Toggle::Toggle(const Resources &r, const string &t): - Widget(r), +Toggle::Toggle(const string &t): text(), pressed(false), value(false), exclusive(false) { - update_style(); set_text(t); } +void Toggle::autosize() +{ + if(!style) + return; + + Widget::autosize(); + + if(const Part *text_part = style->get_part("text")) + { + const Sides &margin = text_part->get_margin(); + geom.w = max(geom.w, text.get_width()+margin.left+margin.right); + geom.h = max(geom.h, text.get_height()+margin.top+margin.bottom); + } +} + void Toggle::set_text(const string &t) { text = t; + signal_autosize_changed.emit(); } void Toggle::set_exclusive(bool e) @@ -37,6 +45,15 @@ void Toggle::set_exclusive(bool e) exclude_siblings(); } +void Toggle::exclude_siblings() +{ + const list &siblings = parent->get_children(); + for(list::const_iterator i=siblings.begin(); i!=siblings.end(); ++i) + if(Toggle *tgl = dynamic_cast(*i)) + if(tgl!=this && tgl->get_exclusive() && tgl->get_value()) + tgl->set_value(false); +} + void Toggle::set_value(bool v) { value = v; @@ -50,6 +67,12 @@ void Toggle::set_value(bool v) state &= ~ACTIVE; } +void Toggle::render_special(const Part &part) const +{ + if(part.get_name()=="text") + text.render(part, geom); +} + void Toggle::button_press(int, int, unsigned btn) { if(btn==1) @@ -70,21 +93,6 @@ void Toggle::button_release(int x, int y, unsigned btn) } } -void Toggle::render_special(const Part &part) const -{ - if(part.get_name()=="text") - text.render(part, geom); -} - -void Toggle::exclude_siblings() -{ - const list &siblings = parent->get_children(); - for(list::const_iterator i=siblings.begin(); i!=siblings.end(); ++i) - if(Toggle *tgl = dynamic_cast(*i)) - if(tgl!=this && tgl->get_exclusive() && tgl->get_value()) - tgl->set_value(false); -} - void Toggle::on_style_change() { text.set_style(style); @@ -101,12 +109,12 @@ Toggle::Loader::Loader(Toggle &t): Toggle &Toggle::Loader::get_object() const { - return static_cast(wdg); + return static_cast(obj); } void Toggle::Loader::finish() { - Toggle &tgl = static_cast(wdg); + Toggle &tgl = get_object(); if(tgl.value) tgl.state |= ACTIVE; else @@ -115,7 +123,7 @@ void Toggle::Loader::finish() void Toggle::Loader::text(const string &t) { - static_cast(wdg).text = t; + get_object().text = t; } } // namespace GLtk