Add ui helpers for finding a specific element type in element tree
This commit is contained in:
parent
b215d52289
commit
73d05a5ec4
1 changed files with 31 additions and 0 deletions
|
|
@ -88,4 +88,35 @@ namespace psemek::ui
|
||||||
void post_delayed_callbacks() const;
|
void post_delayed_callbacks() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename Type>
|
||||||
|
Type * find_first_parent_of_type(element * e)
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
if (!e)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
if (auto p = dynamic_cast<Type *>(e))
|
||||||
|
return p;
|
||||||
|
|
||||||
|
e = e->parent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Type>
|
||||||
|
Type * find_last_parent_of_type(element * e)
|
||||||
|
{
|
||||||
|
Type * r = nullptr;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
if (auto p = find_first_parent_of_type<Type>(e))
|
||||||
|
{
|
||||||
|
r = p;
|
||||||
|
e = p->parent();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue