From c9cf0f423911bc470cc23b860358d02aebb9b0af Mon Sep 17 00:00:00 2001 From: Humdinger Date: Thu, 25 Jul 2024 08:13:25 +0200 Subject: [PATCH] Fix placement of calendar window Before, the placement wasn't correct for smaller or bigger font sizes. For some reason, window->Bounds() always returns the coordinates of the CalenderMenuWindow's ctor, BRect(0.0, 0.0, 100.0, 130.0), not the actual size. Using GetLayout()->PreferredSize() instead works... --- src/CalendarButton.cpp | 9 ++++++--- src/CalendarMenuWindow.cpp | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/CalendarButton.cpp b/src/CalendarButton.cpp index be301db..51a56aa 100644 --- a/src/CalendarButton.cpp +++ b/src/CalendarButton.cpp @@ -130,7 +130,12 @@ CalendarButton::ShowPopUpCalendar() BDate date = fDateBox->GetDate(); BMessage* invocationMessage = new BMessage(M_SET_DATE); - BPoint where = Bounds().LeftTop(); + + // Get the center of the BButton + BRect buttonRect(Bounds()); + BPoint where = buttonRect.LeftTop(); + where.x += buttonRect.Width() / 2; + where.y += buttonRect.Height() / 2; ConvertToScreen(&where); CalendarMenuWindow* window = new CalendarMenuWindow(this, where); @@ -139,7 +144,5 @@ CalendarButton::ShowPopUpCalendar() window->SetDate(date); fCalendarWindow = BMessenger(window); window->Show(); - - window->MoveBy(Bounds().Width() / 2, window->Bounds().Height() * -1.5); window->MoveOnScreen(B_MOVE_IF_PARTIALLY_OFFSCREEN); } diff --git a/src/CalendarMenuWindow.cpp b/src/CalendarMenuWindow.cpp index aaf10c1..ed52e85 100644 --- a/src/CalendarMenuWindow.cpp +++ b/src/CalendarMenuWindow.cpp @@ -118,6 +118,9 @@ CalendarMenuWindow::CalendarMenuWindow(BHandler* handler, BPoint where) groupView->AddChild(view); AddChild(groupView); + // Moves the bottom left corner of the window to "where" + BSize size = GetLayout()->PreferredSize(); + where.y -= size.height; MoveTo(where); }