From 6e58cefe8fd7aa736e528803ba483b9c8514bda1 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 19 Sep 2019 11:25:00 +0300 Subject: [PATCH] Add a helper class for single-child list items --- source/list.cpp | 28 +++++++++++++++------------- source/list.h | 11 +++++++---- 2 files changed, 22 insertions(+), 17 deletions(-) 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 -- 2.45.2