diff --git a/libs/ui/include/psemek/ui/element.hpp b/libs/ui/include/psemek/ui/element.hpp index f5ea9058..177d4d2a 100644 --- a/libs/ui/include/psemek/ui/element.hpp +++ b/libs/ui/include/psemek/ui/element.hpp @@ -88,4 +88,35 @@ namespace psemek::ui void post_delayed_callbacks() const; }; + template + Type * find_first_parent_of_type(element * e) + { + while (true) + { + if (!e) + return nullptr; + + if (auto p = dynamic_cast(e)) + return p; + + e = e->parent(); + } + } + + template + Type * find_last_parent_of_type(element * e) + { + Type * r = nullptr; + while (true) + { + if (auto p = find_first_parent_of_type(e)) + { + r = p; + e = p->parent(); + } + else + return r; + } + } + }