]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/list.cpp
Make font size a property of Style
[libs/gltk.git] / source / list.cpp
index ea3969ce16dbb466591a642bdcff01c1e1150ed5..e1f39b7dc8ecaa67db27c9212ada54ef24199593 100644 (file)
@@ -1,10 +1,3 @@
-/* $Id$
-
-This file is part of libmspgltk
-Copyright © 2007-2011  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #include <msp/gl/immediate.h>
 #include <msp/gl/matrix.h>
 #include <msp/gl/transform.h>
@@ -47,7 +40,7 @@ void List::autosize_rows(unsigned n)
        if(items_part)
        {
                const Sides &margin = items_part->get_margin();
-               float font_size = style->get_font()->get_default_size();
+               float font_size = style->get_font_size();
 
                unsigned max_w = 0;
                for(vector<string>::iterator i=items.begin(); i!=items.end(); ++i)
@@ -91,21 +84,23 @@ void List::append(const string &v)
 {
        items.push_back(v);
        check_view_range();
+       signal_autosize_changed.emit();
 }
 
 void List::insert(unsigned i, const string &v)
 {
        if(i>items.size())
-               throw InvalidParameterValue("Index out of range");
+               throw out_of_range("List::insert");
 
        items.insert(items.begin()+i, v);
        check_view_range();
+       signal_autosize_changed.emit();
 }
 
 void List::remove(unsigned i)
 {
        if(i>items.size())
-               throw InvalidParameterValue("Index out of range");
+               throw out_of_range("List::remove");
 
        items.erase(items.begin()+i);
        if(sel_index>static_cast<int>(i))
@@ -114,6 +109,7 @@ void List::remove(unsigned i)
                sel_index = -1;
 
        check_view_range();
+       signal_autosize_changed.emit();
 }
 
 void List::clear()
@@ -122,6 +118,7 @@ void List::clear()
        sel_index = -1;
 
        check_view_range();
+       signal_autosize_changed.emit();
 }
 
 void List::set_selected_index(int i)
@@ -134,13 +131,13 @@ void List::set_selected_index(int i)
                signal_item_selected.emit(sel_index, items[sel_index]);
        }
        else
-               throw InvalidParameterValue("Index out of range");
+               throw out_of_range("List::set_selected_index");
 }
 
 const string &List::get_selected() const
 {
        if(sel_index<0)
-               throw InvalidState("No selection");
+               throw logic_error("sel_index<0");
 
        return items[sel_index];
 }
@@ -226,7 +223,7 @@ void List::on_style_change()
        items_part = style->get_part("items");
 
        const GL::Font &font = *style->get_font();
-       row_height = static_cast<unsigned>((font.get_ascent()-font.get_descent())*font.get_default_size());
+       row_height = static_cast<unsigned>((font.get_ascent()-font.get_descent())*style->get_font_size());
 
        check_view_range();
 }