Support all alignment modes in label
This commit is contained in:
parent
619c4edbe2
commit
57473c545c
1 changed files with 28 additions and 2 deletions
|
|
@ -88,9 +88,35 @@ namespace psemek::ui
|
|||
for (auto const & g : cached_state_->glyphs)
|
||||
bbox |= g.position;
|
||||
|
||||
int lines = 1;
|
||||
|
||||
geom::vector<float, 2> offset;
|
||||
offset[0] = shape_.box[0].center() - bbox[0].length() / 2.f;
|
||||
offset[1] = shape_.box[1].center() - st->text_scale * st->font->size()[1] / 2.f;
|
||||
|
||||
switch (halign_)
|
||||
{
|
||||
case halignment::left:
|
||||
offset[0] = shape_.box[0].min;
|
||||
break;
|
||||
case halignment::center:
|
||||
offset[0] = shape_.box[0].center() - bbox[0].length() / 2.f;
|
||||
break;
|
||||
case halignment::right:
|
||||
offset[0] = shape_.box[0].max - bbox[0].length();
|
||||
break;
|
||||
}
|
||||
|
||||
switch (valign_)
|
||||
{
|
||||
case valignment::top:
|
||||
offset[1] = shape_.box[1].min;
|
||||
break;
|
||||
case valignment::center:
|
||||
offset[1] = shape_.box[1].center() - lines * st->text_scale * st->font->size()[1] / 2.f;
|
||||
break;
|
||||
case valignment::bottom:
|
||||
offset[1] = shape_.box[1].max - lines * st->text_scale * st->font->size()[1];
|
||||
break;
|
||||
}
|
||||
|
||||
for (auto & g : cached_state_->glyphs)
|
||||
g.position += offset;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue