Support ui::positioner clamping the positioned element within provided shape
This commit is contained in:
parent
440b7b6214
commit
2b027e09e5
2 changed files with 13 additions and 3 deletions
|
|
@ -26,7 +26,7 @@ namespace psemek::ui
|
|||
struct shape const & shape() const override;
|
||||
void reshape(geom::box<float, 2> const & box) override;
|
||||
|
||||
virtual void set_position(geom::point<float, 2> const & p, x_align x, y_align y);
|
||||
virtual void set_position(geom::point<float, 2> const & p, x_align x, y_align y, bool clamp = true);
|
||||
|
||||
void draw(ui::painter &) const override {}
|
||||
|
||||
|
|
@ -36,6 +36,7 @@ namespace psemek::ui
|
|||
geom::point<float, 2> position_{0.f, 0.f};
|
||||
x_align x_;
|
||||
y_align y_;
|
||||
bool clamp_;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,16 +51,25 @@ namespace psemek::ui
|
|||
break;
|
||||
}
|
||||
|
||||
if (clamp_)
|
||||
{
|
||||
cbox[0] += std::max(0.f, box[0].min - cbox[0].min);
|
||||
cbox[0] += std::min(0.f, box[0].max - cbox[0].max);
|
||||
cbox[1] += std::max(0.f, box[1].min - cbox[1].min);
|
||||
cbox[1] += std::min(0.f, box[1].max - cbox[1].max);
|
||||
}
|
||||
|
||||
child_->reshape(cbox);
|
||||
}
|
||||
|
||||
void positioner::set_position(geom::point<float, 2> const & p, x_align x, y_align y)
|
||||
void positioner::set_position(geom::point<float, 2> const & p, x_align x, y_align y, bool clamp)
|
||||
{
|
||||
if (p != position_ || x_ != x || y_ != y)
|
||||
if (p != position_ || x_ != x || y_ != y || clamp_ != clamp)
|
||||
{
|
||||
position_ = p;
|
||||
x_ = x;
|
||||
y_ = y;
|
||||
clamp_ = clamp;
|
||||
|
||||
post_reshape();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue