From 9678abb23abe450109e2feda081f5bba5f20cc94 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 20 Aug 2023 23:07:04 +0300 Subject: [PATCH] Rename some get functions as find because they can return null --- source/container.cpp | 12 ++++++------ source/container.h | 4 ++-- source/entry.cpp | 4 ++-- source/list.cpp | 6 +++--- source/root.cpp | 4 ++-- source/slider.cpp | 2 +- source/style.cpp | 2 +- source/style.h | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/source/container.cpp b/source/container.cpp index 4f4d2a3..393973c 100644 --- a/source/container.cpp +++ b/source/container.cpp @@ -86,7 +86,7 @@ list 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(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 diff --git a/source/container.h b/source/container.h index 26100b7..b2f69d3 100644 --- a/source/container.h +++ b/source/container.h @@ -60,8 +60,8 @@ protected: void reposition_child(Widget &, const Part &) const; public: std::list 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: diff --git a/source/entry.cpp b/source/entry.cpp index 5aadbc2..b113b20 100644 --- a/source/entry.cpp +++ b/source/entry.cpp @@ -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); diff --git a/source/list.cpp b/source/list.cpp index e0d2bd8..963b442 100644 --- a/source/list.cpp +++ b/source/list.cpp @@ -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 &widths) if(!style) return; - const Part *part = style->get_part("children"); + const Part *part = style->find_part("children"); if(!part) return; diff --git a/source/root.cpp b/source/root.cpp index 376b9d5..167b3f7 100644 --- a/source/root.cpp +++ b/source/root.cpp @@ -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); diff --git a/source/slider.cpp b/source/slider.cpp index cca717f..29f9067 100644 --- a/source/slider.cpp +++ b/source/slider.cpp @@ -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(); diff --git a/source/style.cpp b/source/style.cpp index a339c0c..ddca1c4 100644 --- a/source/style.cpp +++ b/source/style.cpp @@ -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); diff --git a/source/style.h b/source/style.h index 56870da..2c4863a 100644 --- a/source/style.h +++ b/source/style.h @@ -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; }; -- 2.43.0