1
0
Fork 0

Merge pull request #3430 from bobrippling/fix/promenu-items

promenu: fix removal of final menu item
master
Rob Pilling 2024-05-23 21:01:18 +01:00 committed by GitHub
commit 574bf6e66d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 16 deletions

View File

@ -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

View File

@ -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)

View File

@ -1,6 +1,6 @@
type ActualMenuItem = Exclude<Menu["..."], MenuOptions | undefined>;
(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<Menu["..."], MenuOptions | undefined>;
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<Menu["..."], MenuOptions | undefined>;
}
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<Menu["..."], MenuOptions | undefined>;
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<Menu["..."], MenuOptions | undefined>;
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)

View File

@ -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",