feat: desktop - use MTK menu for desktop right-click menu
This commit is contained in:
@@ -274,55 +274,16 @@ void gui::desktop_compose(DesktopState* ds) {
|
||||
}
|
||||
|
||||
// Draw right-click context menu if open
|
||||
if (ds->ctx_menu_open) {
|
||||
static constexpr int CTX_MENU_W = 180;
|
||||
static constexpr int CTX_ITEM_H = 36;
|
||||
static constexpr int CTX_ITEM_COUNT = 6;
|
||||
int cmx = ds->ctx_menu_x;
|
||||
int cmy = ds->ctx_menu_y;
|
||||
int cmh = CTX_ITEM_H * CTX_ITEM_COUNT + 8;
|
||||
if (ds->ctx_menu.open) {
|
||||
gui::mtk::ContextMenuItem ctx_items[DESKTOP_CTX_COUNT];
|
||||
desktop_ctx_menu_items(ctx_items);
|
||||
|
||||
// Clamp to screen
|
||||
if (cmx + CTX_MENU_W > sw) cmx = sw - CTX_MENU_W;
|
||||
if (cmy + cmh > sh) cmy = sh - cmh;
|
||||
|
||||
ensure_filemanager_icons_loaded(ds);
|
||||
|
||||
draw_shadow(fb, cmx, cmy, CTX_MENU_W, cmh, 4, colors::SHADOW);
|
||||
fill_rounded_rect(fb, cmx, cmy, CTX_MENU_W, cmh, 8, colors::MENU_BG);
|
||||
draw_rect(fb, cmx, cmy, CTX_MENU_W, cmh, colors::BORDER);
|
||||
|
||||
struct CtxItem { const char* label; SvgIcon* icon; };
|
||||
CtxItem ctx_items[CTX_ITEM_COUNT] = {
|
||||
{ "Terminal", &ds->icon_terminal },
|
||||
{ "Files", &ds->icon_filemanager },
|
||||
{ "Settings", &ds->icon_system_configuration_menu },
|
||||
{ "Sleep", &ds->icon_sleep },
|
||||
{ "Reboot", &ds->icon_reboot },
|
||||
{ "Shutdown", &ds->icon_shutdown },
|
||||
};
|
||||
|
||||
int mmx = ds->mouse.x;
|
||||
int mmy = ds->mouse.y;
|
||||
|
||||
for (int i = 0; i < CTX_ITEM_COUNT; i++) {
|
||||
int iy = cmy + 4 + i * CTX_ITEM_H;
|
||||
Rect item_r = {cmx + 4, iy, CTX_MENU_W - 8, CTX_ITEM_H};
|
||||
|
||||
if (item_r.contains(mmx, mmy)) {
|
||||
fill_rounded_rect(fb, item_r.x, item_r.y, item_r.w, item_r.h, 4, gui::mtk::accent_hover_tint(ds->settings.accent_color));
|
||||
}
|
||||
|
||||
int icon_x = item_r.x + 8;
|
||||
int icon_y = item_r.y + (CTX_ITEM_H - 20) / 2;
|
||||
if (ctx_items[i].icon && ctx_items[i].icon->pixels) {
|
||||
fb.blit_alpha(icon_x, icon_y, ctx_items[i].icon->width, ctx_items[i].icon->height, ctx_items[i].icon->pixels);
|
||||
}
|
||||
|
||||
int tx = icon_x + 28;
|
||||
int ty = item_r.y + (CTX_ITEM_H - system_font_height()) / 2;
|
||||
draw_text(fb, tx, ty, ctx_items[i].label, colors::TEXT_COLOR);
|
||||
}
|
||||
// The compositor draws straight into the back buffer; wrap it in a
|
||||
// Canvas so the shared MTK widget can render it.
|
||||
Canvas c(fb.buffer(), fb.pitch() / 4, sh);
|
||||
gui::mtk::Theme theme = gui::mtk::make_theme(ds->settings.accent_color);
|
||||
gui::mtk::draw_context_menu(c, ds->ctx_menu, ctx_items, DESKTOP_CTX_COUNT,
|
||||
theme, DESKTOP_CTX_MENU_W, DESKTOP_CTX_ITEM_H);
|
||||
}
|
||||
|
||||
if (ds->launcher_open) {
|
||||
|
||||
Reference in New Issue
Block a user