]> git.tdb.fi Git - libs/gltk.git/commitdiff
Add a helper class for single-child list items
authorMikko Rasa <tdb@tdb.fi>
Thu, 19 Sep 2019 08:25:00 +0000 (11:25 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 19 Sep 2019 08:25:00 +0000 (11:25 +0300)
source/list.cpp
source/list.h

index 005f6fa8ea29cc2a57cd23152f46167dacf922a1..9be88e52c9ce65acecdf98b550d78a5db9a672ee 100644 (file)
@@ -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<unsigned> &widths) const
 {
        if(widths.size()<children.size())
@@ -610,19 +625,6 @@ List::BasicItem::BasicItem(const string &text):
        add(label);
 }
 
-void List::BasicItem::on_style_change()
-{
-       if(!style)
-               return;
-
-       label.autosize();
-       if(const Part *part = style->get_part("children"))
-       {
-               const Sides &margin = part->get_margin();
-               label.set_position(margin.left, margin.bottom);
-       }
-}
-
 
 List::Loader::Loader(List &l):
        DataFile::DerivedObjectLoader<List, Widget::Loader>(l)
index 3701387455c86f40c5f552a9e426fa2c38fd57c1..25001d18f7948dcab5af79e8671feddf538a61ae 100644 (file)
@@ -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