Add ui::find_element_by_id

This commit is contained in:
Nikita Lisitsa 2022-05-25 22:55:25 +03:00
parent 924533fc7f
commit 21ae912271
2 changed files with 21 additions and 0 deletions

View file

@ -156,6 +156,8 @@ namespace psemek::ui
}
}
element * find_element_by_id(element * root, std::string_view id);
void send_fake_mouse_move_event(element * e, bool mouseover);
}

View file

@ -237,6 +237,25 @@ namespace psemek::ui
c->post_delayed_callbacks();
}
element * find_element_by_id(element * root, std::string_view id)
{
auto visitor = util::recursive([&](auto && self, element * e) -> element *
{
if (!e) return nullptr;
if (e->id() && e->id() == id)
return e;
for (auto c : e->children())
if (auto r = self(c))
return r;
return nullptr;
});
return visitor(root);
}
void send_fake_mouse_move_event(element * e, bool mouseover)
{
auto const box = e->shape().bbox();