Center the OpenWindow. The problem is that we cannot get the real size of the window before it's actually shown on screen.. the trick I did was to show it offscreen, get the real size and move the window.
Fixes ticket #4236 git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32410 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -57,12 +57,22 @@ OpenWindow::OpenWindow()
|
|||||||
.Add(probeDeviceButton, 2, 1)
|
.Add(probeDeviceButton, 2, 1)
|
||||||
.SetInsets(8, 8, 8, 8)
|
.SetInsets(8, 8, 8, 8)
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO: This does not center the window, since with layout management,
|
|
||||||
// the window will still have an invalid size at this point.
|
|
||||||
BScreen screen(this);
|
BScreen screen(this);
|
||||||
MoveTo(screen.Frame().left + (screen.Frame().Width() - Frame().Width()) / 2,
|
// move the window offscreen..
|
||||||
screen.Frame().top + (screen.Frame().Height() - Frame().Height()) / 2);
|
MoveTo(screen.Frame().right+20, screen.Frame().top);
|
||||||
|
fCentered = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
OpenWindow::FrameResized(float width, float height)
|
||||||
|
{
|
||||||
|
if (fCentered) {
|
||||||
|
BScreen screen(this);
|
||||||
|
MoveTo(screen.Frame().left + (screen.Frame().Width() - width) / 2,
|
||||||
|
screen.Frame().top + (screen.Frame().Height() - height) / 2);
|
||||||
|
}
|
||||||
|
fCentered = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -20,11 +20,14 @@ public:
|
|||||||
virtual void MessageReceived(BMessage* message);
|
virtual void MessageReceived(BMessage* message);
|
||||||
virtual bool QuitRequested();
|
virtual bool QuitRequested();
|
||||||
|
|
||||||
|
virtual void FrameResized(float width, float height);
|
||||||
|
|
||||||
static void CollectDevices(BMenu* menu,
|
static void CollectDevices(BMenu* menu,
|
||||||
BEntry* startEntry = NULL);
|
BEntry* startEntry = NULL);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BMenu* fDevicesMenu;
|
BMenu* fDevicesMenu;
|
||||||
|
bool fCentered;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* OPEN_WINDOW_H */
|
#endif /* OPEN_WINDOW_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user