]> git.tdb.fi Git - libs/gltk.git/commitdiff
Minor refactoring
authorMikko Rasa <tdb@tdb.fi>
Mon, 21 Aug 2023 08:23:42 +0000 (11:23 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 21 Aug 2023 12:51:08 +0000 (15:51 +0300)
source/container.cpp
source/image.cpp
source/layout.h
source/panel.h
source/part.cpp
source/part.h
source/partcache.cpp
source/widget.cpp

index 64e3a9a7e296ce374819abddc035112a18948e53..a8c3133d0632238831c5b1692f29c2e9c32c3876 100644 (file)
@@ -103,8 +103,7 @@ Widget *Container::find_descendant_at(int x, int y) const
        if(Container *cont = dynamic_cast<Container *>(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;
index 655ecc252d2b81aa3187195e6d662611835e283a..448da7b985e14664730a1dc33b9994df98bcecbb 100644 (file)
@@ -55,22 +55,18 @@ void Image::set_keep_aspect(bool ka)
 
 void Image::update_icon()
 {
-       if(style)
-       {
-               Root *root = find_ancestor<Root>();
-               if(root)
-               {
-                       if(icon_name.empty())
-                               image = nullptr;
-                       else
-                               image = &root->get_resources().get<GL::Texture2D>(icon_name);
-                       signal_autosize_changed.emit();
-                       mark_rebuild();
-                       return;
-               }
-       }
-
        image = nullptr;
+       if(!style)
+               return;
+
+       Root *root = find_ancestor<Root>();
+       if(!root)
+               return;
+
+       if(!icon_name.empty())
+               image = &root->get_resources().get<GL::Texture2D>(icon_name);
+       signal_autosize_changed.emit();
+       mark_rebuild();
 }
 
 void Image::rebuild_special(const Part &part)
index 2e58505881c351856c0bc0aedc015da5a984f439..2d34b7ad43b3e7be75c973540606ba0337a2cbbb 100644 (file)
@@ -1,7 +1,6 @@
 #ifndef MSP_GLTK_LAYOUT_H_
 #define MSP_GLTK_LAYOUT_H_
 
-#include <set>
 #include <vector>
 #include <sigc++/trackable.h>
 #include <msp/strings/lexicalcast.h>
index e9744fd107a273c12365a86d11cec545228109d6..ab83de078bc17f595f8089112610c3f72fd8cb41 100644 (file)
@@ -72,8 +72,6 @@ protected:
        static TypeRegistry<Loader::AddChildType, Loader &> widget_registry;
        static bool widget_registry_init_done;
 
-       Panel(const Panel &);
-       Panel &operator=(const Panel &);
 public:
        Panel();
        virtual ~Panel();
index dbccc060e828c8b4b5f1f07a5f650dfc94d638fa..aacc52adc28048372c6353dfe8b9a78c2acb72d5 100644 (file)
@@ -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; i<N_STATES_; ++i)
                if(obj.graphic[i])
index 35b8f7d52d820333f74d9f44a0aa23e26dfd313c..10eef5ff2ac329e4214ab33c48092d97fb8690ee 100644 (file)
@@ -24,8 +24,9 @@ public:
        {
        public:
                Loader(Part &, Resources &);
-               ~Loader();
        private:
+               void finish() override;
+
                void graphic_normal(const std::string &);
                void graphic(State, const std::string &);
                void align(float, float);
index 77b51d2cbc2096a101eb941b20e45f6b23568c6a..8b425c2b0a5f255c553d91e67fcca67497c6dd0a 100644 (file)
@@ -47,12 +47,9 @@ void PartCache::insert_special(const Part &part)
        if(!rebuilding)
                throw logic_error("!rebuilding");
 
-       for(current=next; current!=parts.end(); ++current)
-               if(current->part==&part)
-               {
-                       parts.erase(next, current);
-                       break;
-               }
+       current = find_if(next, parts.end(), [&part](const CachedPart &p){ return p.part==&part; });
+       if(current!=parts.end())
+               parts.erase(next, current);
 
        if(current==parts.end())
                current = parts.insert(next, CachedPart());
index 4d990009d81002ece8cc5a8caeb2ac73606e0b3c..b7dcfc5e0d1ed6d104dde077195fe5f7c79b4870 100644 (file)
@@ -1,5 +1,6 @@
 #include <msp/gl/matrix.h>
 #include <msp/strings/format.h>
+#include <msp/strings/utils.h>
 #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<Style>(sname);
        }