From: Mikko Rasa Date: Thu, 19 Sep 2019 08:25:00 +0000 (+0300) Subject: Add a helper class for single-child list items X-Git-Url: http://git.tdb.fi/?p=libs%2Fgltk.git;a=commitdiff_plain;h=6e58cefe8fd7aa736e528803ba483b9c8514bda1 Add a helper class for single-child list items --- diff --git a/source/list.cpp b/source/list.cpp index 005f6fa..9be88e5 100644 --- a/source/list.cpp +++ b/source/list.cpp @@ -538,6 +538,21 @@ void List::Item::render_special(const Part &part, GL::Renderer &renderer) const } +void List::SimpleItem::on_style_change() +{ + if(!style || children.empty()) + return; + + Widget *child = children.front()->widget; + child->autosize(); + if(const Part *part = style->get_part("children")) + { + const Sides &margin = part->get_margin(); + child->set_position(margin.left, margin.bottom); + } +} + + void List::MultiColumnItem::check_widths(vector &widths) const { if(widths.size()get_part("children")) - { - const Sides &margin = part->get_margin(); - label.set_position(margin.left, margin.bottom); - } -} - List::Loader::Loader(List &l): DataFile::DerivedObjectLoader(l) diff --git a/source/list.h b/source/list.h index 3701387..25001d1 100644 --- a/source/list.h +++ b/source/list.h @@ -68,6 +68,12 @@ public: virtual void render_special(const Part &, GL::Renderer &) const; }; + class SimpleItem: public Item + { + private: + virtual void on_style_change(); + }; + class MultiColumnItem: public Item { protected: @@ -79,16 +85,13 @@ public: }; private: - class BasicItem: public Item + class BasicItem: public SimpleItem { private: Label label; public: BasicItem(const std::string &); - - private: - virtual void on_style_change(); }; class ItemFactory