X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Flist.cpp;h=d81c48646016ab03e5704747b235be8be07df03b;hb=2b70e8801c43875ed3f4135bdd0141265cff0312;hp=65d2d6309d24cb612bb3b108fcd67533d20e8d25;hpb=73afd124ab87e8bace98db55517a56c797a9b8c7;p=libs%2Fgltk.git diff --git a/source/list.cpp b/source/list.cpp index 65d2d63..d81c486 100644 --- a/source/list.cpp +++ b/source/list.cpp @@ -1,10 +1,3 @@ -/* $Id$ - -This file is part of libmspgltk -Copyright © 2007-2011 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #include #include #include @@ -33,33 +26,65 @@ List::List(): } void List::autosize() +{ + autosize_rows(5); +} + +void List::autosize_rows(unsigned n) { if(!style) return; - float font_size = style->get_font()->get_default_size(); + Widget::autosize(); - geom.w = 0; - for(vector::iterator i=items.begin(); i!=items.end(); ++i) + if(items_part) { - unsigned w = static_cast(style->get_font()->get_string_width(*i)*font_size); - geom.w = max(geom.w, w); - } + const Sides &margin = items_part->get_margin(); + float font_size = style->get_font()->get_default_size(); + + unsigned max_w = 0; + for(vector::iterator i=items.begin(); i!=items.end(); ++i) + { + unsigned w = static_cast(style->get_font()->get_string_width(*i)*font_size); + max_w = max(max_w, w); + } - geom.h = items.size()*row_height; + geom.w = max(geom.w, max_w+margin.left+margin.right); + geom.h = max(geom.h, n*row_height+margin.top+margin.bottom); + } - if(items_part) + if(const Part *slider_part = style->get_part("slider")) { - const Sides &margin = items_part->get_margin(); - geom.w += margin.left+margin.right; - geom.h += margin.top+margin.bottom; + Geometry sgeom = slider_part->get_geometry(); + if(!sgeom.w || !sgeom.h) + { + slider.autosize(); + if(!sgeom.w) + sgeom.w = slider.get_geometry().w; + if(!sgeom.h) + sgeom.h = slider.get_geometry().h; + } + + const Sides &margin = slider_part->get_margin(); + geom.w = max(geom.w, sgeom.w+margin.left+margin.right); + geom.h = max(geom.h, sgeom.h+margin.top+margin.bottom); + + reposition_slider(); } + + check_view_range(); +} + +void List::autosize_all() +{ + autosize_rows(items.size()); } 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) @@ -69,6 +94,7 @@ void List::insert(unsigned i, const string &v) items.insert(items.begin()+i, v); check_view_range(); + signal_autosize_changed.emit(); } void List::remove(unsigned i) @@ -83,6 +109,7 @@ void List::remove(unsigned i) sel_index = -1; check_view_range(); + signal_autosize_changed.emit(); } void List::clear() @@ -91,6 +118,7 @@ void List::clear() sel_index = -1; check_view_range(); + signal_autosize_changed.emit(); } void List::set_selected_index(int i)