]> git.tdb.fi Git - libs/gltk.git/commitdiff
Rename some get functions as find because they can return null
authorMikko Rasa <tdb@tdb.fi>
Sun, 20 Aug 2023 20:07:04 +0000 (23:07 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 20 Aug 2023 21:52:42 +0000 (00:52 +0300)
source/container.cpp
source/container.h
source/entry.cpp
source/list.cpp
source/root.cpp
source/slider.cpp
source/style.cpp
source/style.h

index 4f4d2a370152fe6fda3b05c2e65de7d92d59ef35..393973cc2ab7293adcd32c3e939442780e0ff23e 100644 (file)
@@ -86,7 +86,7 @@ list<Widget *> Container::get_children() const
        return result;
 }
 
-Widget *Container::get_child_at(int x, int y) const
+Widget *Container::find_child_at(int x, int y) const
 {
        for(auto i=children.end(); i!=children.begin();)
                if((*--i)->widget->is_visible() && (*i)->widget->get_geometry().is_inside(x, y))
@@ -95,13 +95,13 @@ Widget *Container::get_child_at(int x, int y) const
        return nullptr;
 }
 
-Widget *Container::get_descendant_at(int x, int y) const
+Widget *Container::find_descendant_at(int x, int y) const
 {
-       Widget *wdg = get_child_at(x, y);
+       Widget *wdg = find_child_at(x, y);
        if(Container *cont = dynamic_cast<Container *>(wdg))
        {
                const Geometry &cgeom = wdg->get_geometry();
-               Widget *wdg2 = cont->get_descendant_at(x-cgeom.x, y-cgeom.y);
+               Widget *wdg2 = cont->find_descendant_at(x-cgeom.x, y-cgeom.y);
                if(wdg2)
                        return wdg2;
        }
@@ -211,7 +211,7 @@ void Container::button_release(int x, int y, unsigned btn)
                {
                        click_focus = nullptr;
                        if(!pointer_focus)
-                               set_pointer_focus(get_child_at(x, y));
+                               set_pointer_focus(find_child_at(x, y));
                }
 
                const Geometry &cgeom = child->get_geometry();
@@ -242,7 +242,7 @@ Widget *Container::get_pointer_target(int x, int y, bool touch) const
                return touch_focus;
        else
        {
-               Widget *child = get_child_at(x, y);
+               Widget *child = find_child_at(x, y);
                if(child && child->is_enabled())
                        return child;
                else
index 26100b72d315234329b9814ffdd80d14fc50c8f8..b2f69d3bb2eae41cf35183d04f8cc5f1b47531ef 100644 (file)
@@ -60,8 +60,8 @@ protected:
        void reposition_child(Widget &, const Part &) const;
 public:
        std::list<Widget *> get_children() const;
-       Widget *get_child_at(int, int) const;
-       Widget *get_descendant_at(int, int) const;
+       Widget *find_child_at(int, int) const;
+       Widget *find_descendant_at(int, int) const;
        void raise(Widget &);
 
 protected:
index 5aadbc262d355805e3b4fe338714a2a0bb8d4311..b113b2040de556001b5a3e28e631761860eb0909 100644 (file)
@@ -347,7 +347,7 @@ void Entry::on_style_change()
                return;
        }
 
-       text_part = style->get_part("text");
+       text_part = style->find_part("text");
 
        if(multiline)
                check_view_range();
@@ -446,7 +446,7 @@ void Entry::erase_selection(bool emit_change)
 
 void Entry::check_cursor_blink()
 {
-       const Part *cursor_part = style->get_part("cursor");
+       const Part *cursor_part = style->find_part("cursor");
        bool has_blink = (cursor_part && cursor_part->get_graphic(ACTIVE|FOCUS)!=cursor_part->get_graphic(NORMAL|FOCUS));
 
        cursor_blink = (state&FOCUS);
index e0d2bd81c150d62918bedd77b7eebe3b1537baac..963b442775f982840f27b6d796437f02227e9fac 100644 (file)
@@ -330,7 +330,7 @@ bool List::navigate(Navigation nav)
 
 void List::on_style_change()
 {
-       items_part = (style ? style->get_part("items") : nullptr);
+       items_part = (style ? style->find_part("items") : nullptr);
 }
 
 void List::move_focus(Navigation nav, bool select)
@@ -615,7 +615,7 @@ void List::SimpleItem::on_style_change()
 
        Widget *child = children.front()->widget;
        child->autosize();
-       if(const Part *part = style->get_part("children"))
+       if(const Part *part = style->find_part("children"))
        {
                const Sides &margin = part->get_margin();
                child->set_position(margin.left, margin.bottom);
@@ -644,7 +644,7 @@ void List::MultiColumnItem::set_widths(const vector<unsigned> &widths)
        if(!style)
                return;
 
-       const Part *part = style->get_part("children");
+       const Part *part = style->find_part("children");
        if(!part)
                return;
 
index 376b9d53c819beec1b2f4548d771571535073b8e..167b3f798c8963768b11c320cb9d82bf9dc5d916 100644 (file)
@@ -78,7 +78,7 @@ void Root::tick()
        if(tooltip_timeout && Time::now()>tooltip_timeout)
        {
                std::string tip;
-               if(Widget *wdg = get_descendant_at(pointer_x, pointer_y))
+               if(Widget *wdg = find_descendant_at(pointer_x, pointer_y))
                {
                        tip = wdg->get_tooltip();
                        tooltip_target = wdg;
@@ -185,7 +185,7 @@ bool Root::axis_motion_event(unsigned, float, float)
                        pointer_y = y;
                        tooltip_timeout = Time::now()+700*Time::msec;
                }
-               else if(get_descendant_at(x, y)!=tooltip_target)
+               else if(find_descendant_at(x, y)!=tooltip_target)
                {
                        if(lbl_tooltip)
                                lbl_tooltip->set_visible(false);
index cca717f6309c7b1f8b2f39040a3b0b6915432f9a..29f906766ea52c087bb25a707ebc248677aa456a 100644 (file)
@@ -153,7 +153,7 @@ void Slider::on_style_change()
        if(!style)
                return;
 
-       if(const Part *slider_part = style->get_part("slider"))
+       if(const Part *slider_part = style->find_part("slider"))
        {
                const Geometry &pgeom = slider_part->get_geometry();
                const Sides &margin = slider_part->get_margin();
index a339c0cb2bd913f2e336228cd0fb3fd2c63afb36..ddca1c454060ae9ba3f3d5dadae568996981dda6 100644 (file)
@@ -29,7 +29,7 @@ const GL::Sampler &Style::get_sampler() const
        return *sampler;
 }
 
-const Part *Style::get_part(const string &name) const
+const Part *Style::find_part(const string &name) const
 {
        auto i = find_if(parts, [&name](const Part &p){ return p.get_name()==name; });
        return (i!=parts.end() ? &*i : nullptr);
index 56870da615b8e1a9efb7062d0fea9869c7512a4c..2c4863ac4a340e627ecd1984c9ba79f6f5cde956 100644 (file)
@@ -48,7 +48,7 @@ public:
        const GL::Color &get_font_color(State) const;
        const GL::Sampler &get_sampler() const;
        const PartSeq &get_parts() const { return parts; }
-       const Part *get_part(const std::string &) const;
+       const Part *find_part(const std::string &) const;
        bool compare_states(State, State) const;
 };