popUpMenu: init highlight from pointer position on open, not selectedItemIndex
When the popup opens via ButtonPress on the main button, compute the highlighted item from the pointer position relative to the menu view, matching upstream WINGs semantics. Previously highlightedItem was set to selectedItemIndex, which might be -1 (no prior selection), causing the popup to open with no visible highlight until the first motion event. The fix uses event->u.button.y_root - menuView->pos.y divided by item height to determine which item the pointer is over when the menu appears. This item is painted as highlighted immediately on open.
This commit is contained in:
parent
3a2f5e96db
commit
d2c9a59344
|
|
@ -685,8 +685,20 @@ static void handleActionEvents(WMEvent * event, void *data)
|
|||
} else {
|
||||
popUpMenu(bPtr);
|
||||
if (!bPtr->flags.pullsDown) {
|
||||
bPtr->highlightedItem = bPtr->selectedItemIndex;
|
||||
/* Compute highlighted item from pointer position relative
|
||||
* to the menu view, matching upstream WINGs semantics:
|
||||
* the item under the pointer is highlighted on open. */
|
||||
int rel_y = event->u.button.y_root - bPtr->menuView->pos.y;
|
||||
int item = rel_y / bPtr->view->size.height;
|
||||
int count = WMGetArrayItemCount(bPtr->items);
|
||||
if (item >= count) item = count - 1;
|
||||
if (item < 0) item = 0;
|
||||
bPtr->highlightedItem = item;
|
||||
bPtr->flags.insideMenu = 1;
|
||||
if (bPtr->highlightedItem < count) {
|
||||
WMMenuItem *mi = WMGetPopUpButtonMenuItem(bPtr, item);
|
||||
paintMenuEntry(bPtr, item, WMGetMenuItemEnabled(mi));
|
||||
}
|
||||
} else {
|
||||
bPtr->highlightedItem = -1;
|
||||
bPtr->flags.insideMenu = 0;
|
||||
|
|
|
|||
Loading…
Reference in New Issue