From 6bd3d2e599652c145f1927cdcfe67d359c939144 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Tue, 21 May 2024 21:36:37 +0100 Subject: [PATCH] promenu: fix removal of final menu item & `E.showMenu()` --- apps/promenu/ChangeLog | 2 ++ apps/promenu/bootb2.js | 10 ++++------ apps/promenu/bootb2.ts | 15 ++++++--------- apps/promenu/metadata.json | 2 +- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/apps/promenu/ChangeLog b/apps/promenu/ChangeLog index e06007c98..0cbb4fdba 100644 --- a/apps/promenu/ChangeLog +++ b/apps/promenu/ChangeLog @@ -5,3 +5,5 @@ functionality, both via `.back` and `"< Back"` items, displaying an entry and the `setUI` back widget. Fix `setUI`'s back overwrite. Add support for scroll. +0.05: Fix display of final menu item when no options are given and + handling of E.showMenu() with no arguments diff --git a/apps/promenu/bootb2.js b/apps/promenu/bootb2.js index 87d6e4a54..a41b8cb06 100644 --- a/apps/promenu/bootb2.js +++ b/apps/promenu/bootb2.js @@ -12,12 +12,10 @@ E.showMenu = function (items) { g.fillPoly(RectRnd(x1, y1, x2, y2, r)); g.setColor(255, 255, 255); }; + var options = items && items[""] || {}; + if (items) + delete items[""]; var menuItems = Object.keys(items); - var options = items[""] || {}; - if (!(options instanceof Object)) - options = {}; - if (options) - menuItems.splice(menuItems.indexOf(""), 1); var fontHeight = options.fontHeight || 25; var selected = options.scroll || options.selected || 0; var ar = Bangle.appRect; @@ -144,7 +142,7 @@ E.showMenu = function (items) { l.draw(); var back = options.back; if (!back) { - var backItem = items["< Back"]; + var backItem = items && items["< Back"]; if (typeof backItem === "function") back = backItem; else if (backItem && "back" in backItem) diff --git a/apps/promenu/bootb2.ts b/apps/promenu/bootb2.ts index c3ec89bea..abc243c45 100644 --- a/apps/promenu/bootb2.ts +++ b/apps/promenu/bootb2.ts @@ -1,6 +1,6 @@ type ActualMenuItem = Exclude; -(E.showMenu as any) = (items: Menu): MenuInstance => { +E.showMenu = (items?: Menu): MenuInstance => { const RectRnd = (x1: number, y1: number, x2: number, y2: number, r: number) => { const pp = []; pp.push(...g.quadraticBezier([x2 - r, y1, x2, y1, x2, y1 + r])); @@ -14,12 +14,9 @@ type ActualMenuItem = Exclude; g.fillPoly(RectRnd(x1, y1, x2, y2, r)); g.setColor(255, 255, 255); }; + let options = items && items[""] || {}; + if (items) delete items[""]; const menuItems = Object.keys(items); - let options = items[""] || {}; - if (!(options instanceof Object)) options = {}; - - if (options) - menuItems.splice(menuItems.indexOf(""), 1); const fontHeight = options.fontHeight||25; @@ -63,7 +60,7 @@ type ActualMenuItem = Exclude; } while (rows--) { const name = menuItems[idx]; - const item = items[name]! as ActualMenuItem; + const item = items![name]! as ActualMenuItem; const hl = (idx === selected && !selectEdit); if(g.theme.dark){ @@ -118,7 +115,7 @@ type ActualMenuItem = Exclude; g.flip(); }, select: () => { - const item = items[menuItems[selected]] as ActualMenuItem; + const item = items![menuItems[selected]] as ActualMenuItem; if (typeof item === "function") { item(); @@ -164,7 +161,7 @@ type ActualMenuItem = Exclude; let back = options.back; if (!back) { - const backItem = items["< Back"]; + const backItem = items && items["< Back"]; if (typeof backItem === "function") back = backItem; else if (backItem && "back" in backItem) diff --git a/apps/promenu/metadata.json b/apps/promenu/metadata.json index 7da6e32df..31be93940 100644 --- a/apps/promenu/metadata.json +++ b/apps/promenu/metadata.json @@ -1,7 +1,7 @@ { "id": "promenu", "name": "Pro Menu", - "version": "0.04", + "version": "0.05", "description": "Replace the built in menu function. Supports Bangle.js 1 and Bangle.js 2.", "icon": "icon.png", "type": "bootloader",