forked from FOSS/BangleApps
Merge pull request #3430 from bobrippling/fix/promenu-items
promenu: fix removal of final menu itemmaster
commit
574bf6e66d
|
@ -5,3 +5,5 @@
|
||||||
functionality, both via `.back` and `"< Back"` items, displaying an
|
functionality, both via `.back` and `"< Back"` items, displaying an
|
||||||
entry and the `setUI` back widget. Fix `setUI`'s back overwrite. Add
|
entry and the `setUI` back widget. Fix `setUI`'s back overwrite. Add
|
||||||
support for scroll.
|
support for scroll.
|
||||||
|
0.05: Fix display of final menu item when no options are given and
|
||||||
|
handling of E.showMenu() with no arguments
|
||||||
|
|
|
@ -12,12 +12,10 @@ E.showMenu = function (items) {
|
||||||
g.fillPoly(RectRnd(x1, y1, x2, y2, r));
|
g.fillPoly(RectRnd(x1, y1, x2, y2, r));
|
||||||
g.setColor(255, 255, 255);
|
g.setColor(255, 255, 255);
|
||||||
};
|
};
|
||||||
|
var options = items && items[""] || {};
|
||||||
|
if (items)
|
||||||
|
delete items[""];
|
||||||
var menuItems = Object.keys(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 fontHeight = options.fontHeight || 25;
|
||||||
var selected = options.scroll || options.selected || 0;
|
var selected = options.scroll || options.selected || 0;
|
||||||
var ar = Bangle.appRect;
|
var ar = Bangle.appRect;
|
||||||
|
@ -144,7 +142,7 @@ E.showMenu = function (items) {
|
||||||
l.draw();
|
l.draw();
|
||||||
var back = options.back;
|
var back = options.back;
|
||||||
if (!back) {
|
if (!back) {
|
||||||
var backItem = items["< Back"];
|
var backItem = items && items["< Back"];
|
||||||
if (typeof backItem === "function")
|
if (typeof backItem === "function")
|
||||||
back = backItem;
|
back = backItem;
|
||||||
else if (backItem && "back" in backItem)
|
else if (backItem && "back" in backItem)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
type ActualMenuItem = Exclude<Menu["..."], MenuOptions | undefined>;
|
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 RectRnd = (x1: number, y1: number, x2: number, y2: number, r: number) => {
|
||||||
const pp = [];
|
const pp = [];
|
||||||
pp.push(...g.quadraticBezier([x2 - r, y1, x2, y1, x2, y1 + r]));
|
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.fillPoly(RectRnd(x1, y1, x2, y2, r));
|
||||||
g.setColor(255, 255, 255);
|
g.setColor(255, 255, 255);
|
||||||
};
|
};
|
||||||
|
let options = items && items[""] || {};
|
||||||
|
if (items) delete items[""];
|
||||||
const menuItems = Object.keys(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;
|
const fontHeight = options.fontHeight||25;
|
||||||
|
|
||||||
|
@ -63,7 +60,7 @@ type ActualMenuItem = Exclude<Menu["..."], MenuOptions | undefined>;
|
||||||
}
|
}
|
||||||
while (rows--) {
|
while (rows--) {
|
||||||
const name = menuItems[idx];
|
const name = menuItems[idx];
|
||||||
const item = items[name]! as ActualMenuItem;
|
const item = items![name]! as ActualMenuItem;
|
||||||
|
|
||||||
const hl = (idx === selected && !selectEdit);
|
const hl = (idx === selected && !selectEdit);
|
||||||
if(g.theme.dark){
|
if(g.theme.dark){
|
||||||
|
@ -118,7 +115,7 @@ type ActualMenuItem = Exclude<Menu["..."], MenuOptions | undefined>;
|
||||||
g.flip();
|
g.flip();
|
||||||
},
|
},
|
||||||
select: () => {
|
select: () => {
|
||||||
const item = items[menuItems[selected]] as ActualMenuItem;
|
const item = items![menuItems[selected]] as ActualMenuItem;
|
||||||
|
|
||||||
if (typeof item === "function") {
|
if (typeof item === "function") {
|
||||||
item();
|
item();
|
||||||
|
@ -164,7 +161,7 @@ type ActualMenuItem = Exclude<Menu["..."], MenuOptions | undefined>;
|
||||||
|
|
||||||
let back = options.back;
|
let back = options.back;
|
||||||
if (!back) {
|
if (!back) {
|
||||||
const backItem = items["< Back"];
|
const backItem = items && items["< Back"];
|
||||||
if (typeof backItem === "function")
|
if (typeof backItem === "function")
|
||||||
back = backItem;
|
back = backItem;
|
||||||
else if (backItem && "back" in backItem)
|
else if (backItem && "back" in backItem)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"id": "promenu",
|
"id": "promenu",
|
||||||
"name": "Pro Menu",
|
"name": "Pro Menu",
|
||||||
"version": "0.04",
|
"version": "0.05",
|
||||||
"description": "Replace the built in menu function. Supports Bangle.js 1 and Bangle.js 2.",
|
"description": "Replace the built in menu function. Supports Bangle.js 1 and Bangle.js 2.",
|
||||||
"icon": "icon.png",
|
"icon": "icon.png",
|
||||||
"type": "bootloader",
|
"type": "bootloader",
|
||||||
|
|
Loading…
Reference in New Issue