Skip to content

Commit

Permalink
Merge pull request #3703 from devsnd/promenu-0.11
Browse files Browse the repository at this point in the history
promenu 0.11: Add options for natural scroll and disabling wrap-around
  • Loading branch information
bobrippling authored Jan 2, 2025
2 parents 1cef4fe + c9c9003 commit 1ccde9c
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 7 deletions.
1 change: 1 addition & 0 deletions apps/promenu/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 11 additions & 2 deletions apps/promenu/bootb2.js
Original file line number Diff line number Diff line change
@@ -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 = [];
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -201,7 +210,7 @@ E.showMenu = function (items) {
},
}, function (dir) {
if (dir)
l.move(dir);
l.move(settings.naturalScroll ? -dir : dir);
else
l.select();
});
Expand Down
18 changes: 16 additions & 2 deletions apps/promenu/bootb2.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
type ActualMenuItem = Exclude<Menu["..."], MenuOptions | undefined>;

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 = [];
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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();
});

Expand Down
8 changes: 5 additions & 3 deletions apps/promenu/metadata.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"}]
}
30 changes: 30 additions & 0 deletions apps/promenu/settings.js
Original file line number Diff line number Diff line change
@@ -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);
})
33 changes: 33 additions & 0 deletions apps/promenu/settings.ts
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1ccde9c

Please sign in to comment.