Skip to content

Commit

Permalink
Fix placement of calendar window
Browse files Browse the repository at this point in the history
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...
  • Loading branch information
humdingerb committed Jul 25, 2024
1 parent 726aefb commit c9cf0f4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/CalendarButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
3 changes: 3 additions & 0 deletions src/CalendarMenuWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit c9cf0f4

Please sign in to comment.