55 lines
962 B
C++
55 lines
962 B
C++
#include <psemek/ui/element.hpp>
|
|
|
|
#include <psemek/log/log.hpp>
|
|
|
|
namespace psemek::ui
|
|
{
|
|
|
|
element * element::root()
|
|
{
|
|
element * r = this;
|
|
while (r->parent()) r = r->parent();
|
|
return r;
|
|
}
|
|
|
|
element const * element::root() const
|
|
{
|
|
element const * r = this;
|
|
while (r->parent()) r = r->parent();
|
|
return r;
|
|
}
|
|
|
|
void element::reshape()
|
|
{
|
|
reshape(shape().bbox());
|
|
}
|
|
|
|
geom::box<float, 2> element::size_constraints() const
|
|
{
|
|
static float const inf = std::numeric_limits<float>::infinity();
|
|
return {{{0.f, inf}, {0.f, inf}}};
|
|
}
|
|
|
|
std::shared_ptr<style const> element::set_style(std::shared_ptr<struct style const> st)
|
|
{
|
|
std::swap(st, style_);
|
|
return st;
|
|
}
|
|
|
|
void element::post(std::function<void()> f)
|
|
{
|
|
auto l = root()->loop();
|
|
if (l)
|
|
l->post(std::move(f));
|
|
}
|
|
|
|
void element::post_reshape()
|
|
{
|
|
auto weak_self = weak_from_this();
|
|
post([weak_self]{
|
|
if (auto self = weak_self.lock())
|
|
self->root()->reshape();
|
|
});
|
|
}
|
|
|
|
}
|