diff --git a/apps/promenu/ChangeLog b/apps/promenu/ChangeLog index 83140c994e..bbcab00f68 100644 --- a/apps/promenu/ChangeLog +++ b/apps/promenu/ChangeLog @@ -12,3 +12,4 @@ 0.08: Fix bug with modifying menu - allows hadash to save scroll positions 0.09: Don't show "..." if a string isn't truncated (i.e. scrolled) 0.10: Trigger `remove` callbacks when ending the menu +0.11: Add options for natural scroll and disabling wrap-around diff --git a/apps/promenu/bootb2.js b/apps/promenu/bootb2.js index 1090229d20..71692dd33f 100644 --- a/apps/promenu/bootb2.js +++ b/apps/promenu/bootb2.js @@ -1,3 +1,7 @@ +var _a, _b; +var settings = (require("Storage").readJSON("promenu.settings.json", true) || {}); +(_a = settings.naturalScroll) !== null && _a !== void 0 ? _a : (settings.naturalScroll = false); +(_b = settings.wrapAround) !== null && _b !== void 0 ? _b : (settings.wrapAround = true); E.showMenu = function (items) { var RectRnd = function (x1, y1, x2, y2, r) { var pp = []; @@ -164,7 +168,12 @@ E.showMenu = function (items) { } else { var lastSelected = selected; - selected = (selected + dir + menuItems.length) % menuItems.length; + if (settings.wrapAround) { + selected = (selected + dir + menuItems.length) % menuItems.length; + } + else { + selected = E.clip(selected + dir, 0, menuItems.length - 1); + } scroller.scroll = selected; l.draw(Math.min(lastSelected, selected), Math.max(lastSelected, selected)); } @@ -201,7 +210,7 @@ E.showMenu = function (items) { }, }, function (dir) { if (dir) - l.move(dir); + l.move(settings.naturalScroll ? -dir : dir); else l.select(); }); diff --git a/apps/promenu/bootb2.ts b/apps/promenu/bootb2.ts index c284ad88b9..c448397d30 100644 --- a/apps/promenu/bootb2.ts +++ b/apps/promenu/bootb2.ts @@ -1,9 +1,19 @@ type ActualMenuItem = Exclude; +type PromenuSettings = { + naturalScroll: boolean, + wrapAround: boolean, +}; + const enum Consts { NAME_SCROLL_PAD = 5, } +const settings = (require("Storage").readJSON("promenu.settings.json", true) || {}) as PromenuSettings; +settings.naturalScroll ??= false; +settings.wrapAround ??= true; + + E.showMenu = (items?: Menu): MenuInstance => { const RectRnd = (x1: number, y1: number, x2: number, y2: number, r: number) => { const pp = []; @@ -207,7 +217,11 @@ E.showMenu = (items?: Menu): MenuInstance => { } else { const lastSelected = selected; - selected = (selected + dir + /*keep +ve*/menuItems.length) % menuItems.length; + if (settings.wrapAround) { + selected = (selected + dir + /*keep +ve*/menuItems.length) % menuItems.length; + } else { + selected = E.clip(selected + dir, 0, menuItems.length - 1); + } scroller.scroll = selected; l.draw(Math.min(lastSelected, selected), Math.max(lastSelected, selected)); } @@ -244,7 +258,7 @@ E.showMenu = (items?: Menu): MenuInstance => { }, } as SetUIArg<"updown">, dir => { - if (dir) l.move(dir); + if (dir) l.move(settings.naturalScroll ? -dir : dir); else l.select(); }); diff --git a/apps/promenu/metadata.json b/apps/promenu/metadata.json index 87d9610456..efa33f0a23 100644 --- a/apps/promenu/metadata.json +++ b/apps/promenu/metadata.json @@ -1,7 +1,7 @@ { "id": "promenu", "name": "Pro Menu", - "version": "0.10", + "version": "0.11", "description": "Replace the built in menu function. Supports Bangle.js 1 and Bangle.js 2.", "icon": "icon.png", "type": "bootloader", @@ -12,6 +12,8 @@ "storage": [ {"name":"promenu.boot.js","url":"boot.js","supports": ["BANGLEJS"]}, {"name":"promenu.boot.js","url":"bootb2.js","supports": ["BANGLEJS2"]}, - {"name":"promenu.img","url":"promenuIcon.js","evaluate":true} - ] + {"name":"promenu.img","url":"promenuIcon.js","evaluate":true}, + {"name":"promenu.settings.js","url":"settings.js"} + ], + "data": [{"name":"promenu.settings.json"}] } diff --git a/apps/promenu/settings.js b/apps/promenu/settings.js new file mode 100644 index 0000000000..4d25e1335b --- /dev/null +++ b/apps/promenu/settings.js @@ -0,0 +1,30 @@ +(function (back) { + var _a, _b; + var SETTINGS_FILE = "promenu.settings.json"; + var storage = require("Storage"); + var settings = (storage.readJSON(SETTINGS_FILE, true) || {}); + (_a = settings.naturalScroll) !== null && _a !== void 0 ? _a : (settings.naturalScroll = false); + (_b = settings.wrapAround) !== null && _b !== void 0 ? _b : (settings.wrapAround = true); + var save = function () { + storage.writeJSON(SETTINGS_FILE, settings); + }; + var menu = { + "": { "title": "Promenu" }, + "< Back": back, + "Natural Scroll": { + value: !!settings.naturalScroll, + onchange: function (v) { + settings.naturalScroll = v; + save(); + } + }, + "Wrap Around": { + value: !!settings.wrapAround, + onchange: function (v) { + settings.wrapAround = v; + save(); + } + } + }; + E.showMenu(menu); +}) diff --git a/apps/promenu/settings.ts b/apps/promenu/settings.ts new file mode 100644 index 0000000000..b4a7df0a6d --- /dev/null +++ b/apps/promenu/settings.ts @@ -0,0 +1,33 @@ +(back => { + const SETTINGS_FILE = "promenu.settings.json"; + + const storage = require("Storage") + const settings = (storage.readJSON(SETTINGS_FILE, true) || {}) as PromenuSettings; + settings.naturalScroll ??= false; + settings.wrapAround ??= true; + + const save = () => { + storage.writeJSON(SETTINGS_FILE, settings); + }; + + const menu: Menu = { + "": { "title": "Promenu" }, + "< Back": back, + /*LANG*/"Natural Scroll": { + value: !!settings.naturalScroll, + onchange: (v: boolean) => { + settings.naturalScroll = v; + save(); + } + }, + /*LANG*/"Wrap Around": { + value: !!settings.wrapAround, + onchange: (v: boolean) => { + settings.wrapAround = v; + save(); + } + } + }; + + E.showMenu(menu); +}) satisfies SettingsFunc