Adding utility to center windows in their parent container.

This commit is contained in:
Ben Vanik
2015-07-19 13:26:07 -07:00
parent 187fb988e0
commit f24f535f31
2 changed files with 10 additions and 0 deletions

View File

@@ -180,6 +180,14 @@ void Window::set_settings(WindowSettings settings) {
Invalidate();
}
void Window::CenterInParent() {
if (!parent()) {
return;
}
Rect bounds(0, 0, parent()->rect().w, parent()->rect().h);
set_rect(rect().CenterIn(bounds).MoveIn(bounds).Clip(bounds));
}
int Window::title_bar_height() {
if (any(window_settings_ & WindowSettings::kTitleBar)) {
return title_mover_.GetPreferredSize().pref_h;

View File

@@ -77,6 +77,8 @@ class Window : public Element {
// Sets settings for how this window should look and behave.
void set_settings(WindowSettings settings);
void CenterInParent();
// ResizeFit specifies how ResizeToFitContent should resize the window.
enum class ResizeFit {
kPreferred, // Fit the preferred size of all content.