]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/toggle.cpp
Fix a crash if the linear program contains an empty column
[libs/gltk.git] / source / toggle.cpp
index 7edbbb08823c5018aac2a6e4b217309b66fbf8d9..6d2a10b16644d6254163b53b26c6f92ead7754ce 100644 (file)
@@ -1,12 +1,6 @@
-/* $Id$
-
-This file is part of libmspgltk
-Copyright © 2007-2011  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #include "panel.h"
 #include "part.h"
+#include "style.h"
 #include "toggle.h"
 
 using namespace std;
@@ -23,9 +17,25 @@ Toggle::Toggle(const string &t):
        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)
@@ -99,12 +109,12 @@ Toggle::Loader::Loader(Toggle &t):
 
 Toggle &Toggle::Loader::get_object() const
 {
-       return static_cast<Toggle &>(wdg);
+       return static_cast<Toggle &>(obj);
 }
 
 void Toggle::Loader::finish()
 {
-       Toggle &tgl = static_cast<Toggle &>(wdg);
+       Toggle &tgl = get_object();
        if(tgl.value)
                tgl.state |= ACTIVE;
        else
@@ -113,7 +123,7 @@ void Toggle::Loader::finish()
 
 void Toggle::Loader::text(const string &t)
 {
-       static_cast<Toggle &>(wdg).text = t;
+       get_object().text = t;
 }
 
 } // namespace GLtk