Support a separate text bbox in ui::edit
This commit is contained in:
parent
d1b3225112
commit
5066dd6494
2 changed files with 15 additions and 6 deletions
|
|
@ -79,6 +79,8 @@ namespace psemek::ui
|
||||||
|
|
||||||
state_t state() const { return state_; }
|
state_t state() const { return state_; }
|
||||||
|
|
||||||
|
void set_text_shape(geom::box<float, 2> const & box);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::u32string text_;
|
std::u32string text_;
|
||||||
font_type font_;
|
font_type font_;
|
||||||
|
|
@ -91,6 +93,7 @@ namespace psemek::ui
|
||||||
bool caret_visible_ = true;
|
bool caret_visible_ = true;
|
||||||
|
|
||||||
box_shape shape_;
|
box_shape shape_;
|
||||||
|
geom::box<float, 2> text_box_;
|
||||||
|
|
||||||
state_t state_ = state_t::normal;
|
state_t state_ = state_t::normal;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -226,6 +226,7 @@ namespace psemek::ui
|
||||||
void edit::reshape(geom::box<float, 2> const & bbox)
|
void edit::reshape(geom::box<float, 2> const & bbox)
|
||||||
{
|
{
|
||||||
shape_.box = bbox;
|
shape_.box = bbox;
|
||||||
|
text_box_ = bbox;
|
||||||
}
|
}
|
||||||
|
|
||||||
geom::box<float, 2> edit::size_constraints() const
|
geom::box<float, 2> edit::size_constraints() const
|
||||||
|
|
@ -285,26 +286,26 @@ namespace psemek::ui
|
||||||
switch (halign_)
|
switch (halign_)
|
||||||
{
|
{
|
||||||
case halignment::left:
|
case halignment::left:
|
||||||
offset[0] = shape_.box[0].min;
|
offset[0] = text_box_[0].min;
|
||||||
break;
|
break;
|
||||||
case halignment::center:
|
case halignment::center:
|
||||||
offset[0] = shape_.box[0].center() - cached_state_->size[0] * 0.5f;
|
offset[0] = text_box_[0].center() - cached_state_->size[0] * 0.5f;
|
||||||
break;
|
break;
|
||||||
case halignment::right:
|
case halignment::right:
|
||||||
offset[0] = shape_.box[0].max - cached_state_->size[0];
|
offset[0] = text_box_[0].max - cached_state_->size[0];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (valign_)
|
switch (valign_)
|
||||||
{
|
{
|
||||||
case valignment::top:
|
case valignment::top:
|
||||||
offset[1] = shape_.box[1].min;
|
offset[1] = text_box_[1].min;
|
||||||
break;
|
break;
|
||||||
case valignment::center:
|
case valignment::center:
|
||||||
offset[1] = shape_.box[1].center() - cached_state_->size[1] * 0.5f;
|
offset[1] = text_box_[1].center() - cached_state_->size[1] * 0.5f;
|
||||||
break;
|
break;
|
||||||
case valignment::bottom:
|
case valignment::bottom:
|
||||||
offset[1] = shape_.box[1].max - cached_state_->size[1];
|
offset[1] = text_box_[1].max - cached_state_->size[1];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -338,6 +339,11 @@ namespace psemek::ui
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void edit::set_text_shape(geom::box<float, 2> const & box)
|
||||||
|
{
|
||||||
|
text_box_ = box;
|
||||||
|
}
|
||||||
|
|
||||||
void edit::on_state_changed()
|
void edit::on_state_changed()
|
||||||
{
|
{
|
||||||
cached_state_ = std::nullopt;
|
cached_state_ = std::nullopt;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue