64 lines
1 KiB
C++
64 lines
1 KiB
C++
#include <psemek/ui/positioner.hpp>
|
|
|
|
namespace psemek::ui
|
|
{
|
|
|
|
shape const & positioner::shape() const
|
|
{
|
|
return shape_;
|
|
}
|
|
|
|
void positioner::reshape(geom::box<float, 2> const & box)
|
|
{
|
|
shape_.box = box;
|
|
|
|
if (!child_)
|
|
return;
|
|
|
|
auto sc = child_->size_constraints();
|
|
|
|
geom::vector<float, 2> size;
|
|
size[0] = sc[0].min;
|
|
size[1] = sc[1].min;
|
|
|
|
geom::box<float, 2> cbox;
|
|
cbox[0].min = position_[0];
|
|
cbox[1].min = position_[1];
|
|
cbox[0].max = cbox[0].min + size[0];
|
|
cbox[1].max = cbox[1].min + size[1];
|
|
|
|
switch (x_)
|
|
{
|
|
case x_align::left:
|
|
break;
|
|
case x_align::center:
|
|
cbox[0] -= size[0] / 2.f;
|
|
break;
|
|
case x_align::right:
|
|
cbox[0] -= size[0];
|
|
break;
|
|
}
|
|
|
|
switch (y_)
|
|
{
|
|
case y_align::top:
|
|
break;
|
|
case y_align::center:
|
|
cbox[1] -= size[1] / 2.f;
|
|
break;
|
|
case y_align::bottom:
|
|
cbox[1] -= size[1];
|
|
break;
|
|
}
|
|
|
|
child_->reshape(cbox);
|
|
}
|
|
|
|
void positioner::set_position(geom::point<float, 2> const & p, x_align x, y_align y)
|
|
{
|
|
position_ = p;
|
|
x_ = x;
|
|
y_ = y;
|
|
}
|
|
|
|
}
|