From 103ceeace366c6d80fce323438b31b9bbc167915 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 21 Aug 2023 11:23:42 +0300 Subject: [PATCH] Minor refactoring --- source/container.cpp | 3 +-- source/image.cpp | 26 +++++++++++--------------- source/layout.h | 1 - source/panel.h | 2 -- source/part.cpp | 2 +- source/part.h | 3 ++- source/partcache.cpp | 9 +++------ source/widget.cpp | 7 ++----- 8 files changed, 20 insertions(+), 33 deletions(-) diff --git a/source/container.cpp b/source/container.cpp index 64e3a9a..a8c3133 100644 --- a/source/container.cpp +++ b/source/container.cpp @@ -103,8 +103,7 @@ Widget *Container::find_descendant_at(int x, int y) const if(Container *cont = dynamic_cast(wdg)) { const Geometry &cgeom = wdg->get_geometry(); - Widget *wdg2 = cont->find_descendant_at(x-cgeom.x, y-cgeom.y); - if(wdg2) + if(Widget *wdg2 = cont->find_descendant_at(x-cgeom.x, y-cgeom.y)) return wdg2; } return wdg; diff --git a/source/image.cpp b/source/image.cpp index 655ecc2..448da7b 100644 --- a/source/image.cpp +++ b/source/image.cpp @@ -55,22 +55,18 @@ void Image::set_keep_aspect(bool ka) void Image::update_icon() { - if(style) - { - Root *root = find_ancestor(); - if(root) - { - if(icon_name.empty()) - image = nullptr; - else - image = &root->get_resources().get(icon_name); - signal_autosize_changed.emit(); - mark_rebuild(); - return; - } - } - image = nullptr; + if(!style) + return; + + Root *root = find_ancestor(); + if(!root) + return; + + if(!icon_name.empty()) + image = &root->get_resources().get(icon_name); + signal_autosize_changed.emit(); + mark_rebuild(); } void Image::rebuild_special(const Part &part) diff --git a/source/layout.h b/source/layout.h index 2e58505..2d34b7a 100644 --- a/source/layout.h +++ b/source/layout.h @@ -1,7 +1,6 @@ #ifndef MSP_GLTK_LAYOUT_H_ #define MSP_GLTK_LAYOUT_H_ -#include #include #include #include diff --git a/source/panel.h b/source/panel.h index e9744fd..ab83de0 100644 --- a/source/panel.h +++ b/source/panel.h @@ -72,8 +72,6 @@ protected: static TypeRegistry widget_registry; static bool widget_registry_init_done; - Panel(const Panel &); - Panel &operator=(const Panel &); public: Panel(); virtual ~Panel(); diff --git a/source/part.cpp b/source/part.cpp index dbccc06..aacc52a 100644 --- a/source/part.cpp +++ b/source/part.cpp @@ -44,7 +44,7 @@ Part::Loader::Loader(Part &p, Resources &r): add("size", &Loader::size); } -Part::Loader::~Loader() +void Part::Loader::finish() { for(unsigned i=0; ipart==&part) - { - parts.erase(next, current); - break; - } + current = find_if(next, parts.end(), [&part](const CachedPart &p){ return p.part==∂ }); + if(current!=parts.end()) + parts.erase(next, current); if(current==parts.end()) current = parts.insert(next, CachedPart()); diff --git a/source/widget.cpp b/source/widget.cpp index 4d99000..b7dcfc5 100644 --- a/source/widget.cpp +++ b/source/widget.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "container.h" #include "resources.h" #include "root.h" @@ -131,11 +132,7 @@ void Widget::update_style() else { string sname = get_class(); - if(!style_name.empty()) - { - sname += '-'; - sname += style_name; - } + append(sname, "-", style_name); style = &root->get_resources().get