Skip to content

Commit 03938a1

Browse files
committed
Refine menu alignment flags for Windows placement
Updated the alignment flag logic in menu_windows.cpp to more accurately set TPM_* flags for each Placement option, ensuring correct horizontal and vertical alignment of context menus relative to their anchor.
1 parent 679761a commit 03938a1

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/platform/windows/menu_windows.cpp

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -725,29 +725,46 @@ bool Menu::Open(const PositioningStrategy& strategy, Placement placement) {
725725
// Set the host window as foreground to ensure menu can be displayed
726726
SetForegroundWindow(host_window);
727727

728-
// Determine alignment flags based on placement
729-
// Note: TPM_* flags are mutually exclusive and control vertical alignment only
730-
UINT uFlags = TPM_BOTTOMALIGN | TPM_LEFTALIGN; // Default
728+
// Determine alignment flags based on placement (both axes)
729+
// Horizontal: TPM_LEFTALIGN | TPM_CENTERALIGN | TPM_RIGHTALIGN
730+
// Vertical: TPM_TOPALIGN | TPM_VCENTERALIGN | TPM_BOTTOMALIGN
731+
UINT uFlags = 0;
731732
switch (placement) {
732733
case Placement::Top:
734+
uFlags = TPM_BOTTOMALIGN | TPM_CENTERALIGN; // above anchor, horizontally centered
735+
break;
733736
case Placement::TopStart:
737+
uFlags = TPM_BOTTOMALIGN | TPM_LEFTALIGN; // above anchor, align left
738+
break;
734739
case Placement::TopEnd:
735-
uFlags = TPM_TOPALIGN | TPM_LEFTALIGN;
740+
uFlags = TPM_BOTTOMALIGN | TPM_RIGHTALIGN; // above anchor, align right
736741
break;
737742
case Placement::Right:
743+
uFlags = TPM_LEFTALIGN | TPM_VCENTERALIGN; // right of anchor, vertically centered
744+
break;
738745
case Placement::RightStart:
746+
uFlags = TPM_LEFTALIGN | TPM_TOPALIGN; // right of anchor, align top
747+
break;
739748
case Placement::RightEnd:
740-
uFlags = TPM_BOTTOMALIGN | TPM_RIGHTALIGN;
749+
uFlags = TPM_LEFTALIGN | TPM_BOTTOMALIGN; // right of anchor, align bottom
741750
break;
742751
case Placement::Bottom:
752+
uFlags = TPM_TOPALIGN | TPM_CENTERALIGN; // below anchor, horizontally centered
753+
break;
743754
case Placement::BottomStart:
755+
uFlags = TPM_TOPALIGN | TPM_LEFTALIGN; // below anchor, align left
756+
break;
744757
case Placement::BottomEnd:
745-
uFlags = TPM_BOTTOMALIGN | TPM_LEFTALIGN;
758+
uFlags = TPM_TOPALIGN | TPM_RIGHTALIGN; // below anchor, align right
746759
break;
747760
case Placement::Left:
761+
uFlags = TPM_RIGHTALIGN | TPM_VCENTERALIGN; // left of anchor, vertically centered
762+
break;
748763
case Placement::LeftStart:
764+
uFlags = TPM_RIGHTALIGN | TPM_TOPALIGN; // left of anchor, align top
765+
break;
749766
case Placement::LeftEnd:
750-
uFlags = TPM_BOTTOMALIGN | TPM_LEFTALIGN;
767+
uFlags = TPM_RIGHTALIGN | TPM_BOTTOMALIGN; // left of anchor, align bottom
751768
break;
752769
}
753770

0 commit comments

Comments
 (0)