Menu bar items now depress when clicked.

This commit is contained in:
Scott Duensing 2026-03-18 00:56:00 -05:00
parent 0cede78932
commit 35f79eb834
3 changed files with 34 additions and 4 deletions

View file

@ -335,6 +335,13 @@ static void closeAllPopups(AppContextT *ctx) {
dirtyListAdd(&ctx->dirty, pl->popupX, pl->popupY, pl->popupW, pl->popupH);
}
// Clear the depressed menu bar item
WindowT *popupWin = findWindowById(ctx, ctx->popup.windowId);
if (popupWin && popupWin->menuBar && popupWin->menuBar->activeIdx >= 0) {
popupWin->menuBar->activeIdx = -1;
dirtyListAdd(&ctx->dirty, popupWin->x, popupWin->y, popupWin->w, CHROME_BORDER_WIDTH + CHROME_TITLE_HEIGHT + CHROME_MENU_HEIGHT);
}
ctx->popup.active = false;
ctx->popup.depth = 0;
}
@ -371,6 +378,13 @@ static void closePopupLevel(AppContextT *ctx) {
ctx->popup.popupH = pl->popupH;
ctx->popup.hoverItem = pl->hoverItem;
} else {
// Clear the depressed menu bar item
WindowT *popupWin = findWindowById(ctx, ctx->popup.windowId);
if (popupWin && popupWin->menuBar && popupWin->menuBar->activeIdx >= 0) {
popupWin->menuBar->activeIdx = -1;
dirtyListAdd(&ctx->dirty, popupWin->x, popupWin->y, popupWin->w, CHROME_BORDER_WIDTH + CHROME_TITLE_HEIGHT + CHROME_MENU_HEIGHT);
}
ctx->popup.active = false;
}
}
@ -2416,6 +2430,10 @@ static void openPopupAtMenu(AppContextT *ctx, WindowT *win, int32_t menuIdx) {
ctx->popup.menu = menu;
ctx->popup.popupX = win->x + menu->barX;
ctx->popup.popupY = win->y + CHROME_BORDER_WIDTH + CHROME_TITLE_HEIGHT + CHROME_MENU_HEIGHT;
// Mark the menu bar item as active (depressed look)
win->menuBar->activeIdx = menuIdx;
dirtyListAdd(&ctx->dirty, win->x, win->y, win->w, CHROME_BORDER_WIDTH + CHROME_TITLE_HEIGHT + CHROME_MENU_HEIGHT);
ctx->popup.hoverItem = -1;
ctx->popup.depth = 0;

View file

@ -304,6 +304,7 @@ struct MenuT {
typedef struct {
MenuT menus[MAX_MENUS];
int32_t menuCount;
int32_t activeIdx; // menu bar item with open popup (-1 = none)
bool positionsDirty; // true = barX/barW need recomputation
} MenuBarT;

View file

@ -301,12 +301,22 @@ static void drawMenuBar(DisplayT *d, const BlitOpsT *ops, const BitmapFontT *fon
win->w - CHROME_BORDER_WIDTH * 2, barH);
for (int32_t i = 0; i < win->menuBar->menuCount; i++) {
MenuT *menu = &win->menuBar->menus[i];
int32_t textX = win->x + menu->barX + CHROME_TITLE_PAD;
MenuT *menu = &win->menuBar->menus[i];
int32_t itemX = win->x + menu->barX;
int32_t itemW = menu->barW;
int32_t textX = itemX + CHROME_TITLE_PAD;
int32_t textY = barY + (barH - font->charHeight) / 2;
drawTextAccel(d, ops, font, textX, textY, menu->label,
colors->menuFg, colors->menuBg, true);
if (i == win->menuBar->activeIdx) {
// Depressed look for the open menu item
BevelStyleT sunken = BEVEL_SUNKEN(colors, colors->menuBg, 1);
drawBevel(d, ops, itemX, barY, itemW, barH - 1, &sunken);
drawTextAccel(d, ops, font, textX + 1, textY + 1, menu->label,
colors->menuFg, colors->menuBg, true);
} else {
drawTextAccel(d, ops, font, textX, textY, menu->label,
colors->menuFg, colors->menuBg, true);
}
}
setClipRect(d, savedClipX, savedClipY, savedClipW, savedClipH);
@ -852,6 +862,7 @@ MenuBarT *wmAddMenuBar(WindowT *win) {
}
memset(win->menuBar, 0, sizeof(MenuBarT));
win->menuBar->activeIdx = -1;
wmUpdateContentRect(win);
return win->menuBar;