Skip to content

Commit 893a67a

Browse files
authored
Merge pull request espruino#3834 from bobrippling/fix/promenu-y-offset
promenu: always render at a fixed y
2 parents 711c46c + 4c7556d commit 893a67a

File tree

4 files changed

+19
-18
lines changed

4 files changed

+19
-18
lines changed

apps/promenu/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
0.11: Add options for natural scroll and disabling wrap-around
1616
0.12: Fix bug where settings would behave as if all were set to false
1717
0.13: Update to new touch-event handling
18+
0.14: Fix bug in handling changes to `Bangle.appRect`

apps/promenu/bootb2.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,7 @@ E.showMenu = function (items) {
2020
var menuItems = Object.keys(items).filter(function (x) { return x.length; });
2121
var fontHeight = options.fontHeight || 25;
2222
var selected = options.scroll || options.selected || 0;
23-
var ar = Bangle.appRect;
24-
g.reset().clearRect(ar);
25-
var x = ar.x;
26-
var x2 = ar.x2;
27-
var y = ar.y;
28-
var y2 = ar.y2 - 12;
29-
if (options.title)
30-
y += 22;
23+
g.reset().clearRect(Bangle.appRect);
3124
var lastIdx = 0;
3225
var selectEdit = undefined;
3326
var scroller = {
@@ -36,6 +29,7 @@ E.showMenu = function (items) {
3629
var nameScroller = null;
3730
var drawLine = function (name, v, item, idx, x, y, nameScroll) {
3831
if (nameScroll === void 0) { nameScroll = 0; }
32+
var x2 = Bangle.appRect.x2;
3933
var hl = (idx === selected && !selectEdit);
4034
if (g.theme.dark) {
4135
fillRectRnd(x, y, x2, y + fontHeight - 3, 7, hl ? g.theme.bgH : g.theme.bg + 40);
@@ -74,6 +68,12 @@ E.showMenu = function (items) {
7468
};
7569
var l = {
7670
draw: function (rowmin, rowmax) {
71+
var _a = Bangle.appRect, x = _a.x, x2 = _a.x2, y = _a.y, y2 = _a.y2;
72+
if (y === 0)
73+
y = 24;
74+
if (options.title)
75+
y += 22;
76+
y2 -= 12;
7777
if (nameScroller)
7878
clearInterval(nameScroller), nameScroller = null;
7979
var rows = 0 | Math.min((y2 - y) / fontHeight, menuItems.length);

apps/promenu/bootb2.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,7 @@ E.showMenu = (items?: Menu): MenuInstance => {
3434

3535
let selected = options.scroll || options.selected || 0;
3636

37-
const ar = Bangle.appRect;
38-
g.reset().clearRect(ar);
39-
40-
const x = ar.x;
41-
const x2 = ar.x2;
42-
let y = ar.y;
43-
const y2 = ar.y2 - 12; // padding at end for arrow
44-
if (options.title)
45-
y += 22;
37+
g.reset().clearRect(Bangle.appRect);
4638

4739
let lastIdx = 0;
4840
let selectEdit: undefined | ActualMenuItem = undefined;
@@ -61,6 +53,7 @@ E.showMenu = (items?: Menu): MenuInstance => {
6153
y: number,
6254
nameScroll: number = 0,
6355
) => {
56+
const { x2 } = Bangle.appRect;
6457
const hl = (idx === selected && !selectEdit);
6558
if(g.theme.dark){
6659
fillRectRnd(x, y, x2, y + fontHeight - 3, 7, hl ? g.theme.bgH : g.theme.bg + 40);
@@ -114,6 +107,13 @@ E.showMenu = (items?: Menu): MenuInstance => {
114107

115108
const l = {
116109
draw: (rowmin?: number, rowmax?: number) => {
110+
// always refresh appRect, a back button may have appeared
111+
let { x, x2, y, y2 } = Bangle.appRect;
112+
if(y === 0) y = 24; // always bump down for widgets/back button
113+
114+
if (options.title) y += 22;
115+
y2 -= 12; // padding at end for arrow
116+
117117
if (nameScroller) clearInterval(nameScroller), nameScroller = null;
118118
let rows = 0|Math.min((y2 - y) / fontHeight, menuItems.length);
119119
let idx = E.clip(selected - (rows>>1), 0, menuItems.length - rows);

apps/promenu/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "promenu",
33
"name": "Pro Menu",
4-
"version": "0.13",
4+
"version": "0.14",
55
"description": "Replace the built in menu function. Supports Bangle.js 1 and Bangle.js 2.",
66
"icon": "icon.png",
77
"type": "bootloader",

0 commit comments

Comments
 (0)