mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:48:12 +00:00
GButton: Align the button text according to text_alignment().
Added a Rect::align_within(other_rect, alignment) helper that seemed useful.
This commit is contained in:
parent
75b0e5cce5
commit
cca510162e
3 changed files with 27 additions and 4 deletions
|
@ -76,3 +76,23 @@ Vector<Rect> Rect::shatter(const Rect& hammer) const
|
|||
|
||||
return pieces;
|
||||
}
|
||||
|
||||
void Rect::align_within(const Rect& other, TextAlignment alignment)
|
||||
{
|
||||
switch (alignment) {
|
||||
case TextAlignment::Center:
|
||||
center_within(other);
|
||||
return;
|
||||
case TextAlignment::TopLeft:
|
||||
set_location(other.location());
|
||||
return;
|
||||
case TextAlignment::CenterLeft:
|
||||
set_x(other.x());
|
||||
center_vertically_within(other);
|
||||
return;
|
||||
case TextAlignment::CenterRight:
|
||||
set_x(other.x() + other.width() - width());
|
||||
center_vertically_within(other);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue