Skip to content

Commit

Permalink
Merge pull request #3614 from bobrippling/feat/promenu-scroll-no-dots
Browse files Browse the repository at this point in the history
promenu: don't show "..." when a string is fully scrolled in
  • Loading branch information
thyttan authored Oct 21, 2024
2 parents 9c4cc9d + 7c2f191 commit 5c2760a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 19 deletions.
1 change: 1 addition & 0 deletions apps/promenu/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
0.06: Fix lower bounding of numeric values
0.07: Fix bug with alarms app (scroller) and correctly show images
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)
22 changes: 13 additions & 9 deletions apps/promenu/bootb2.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,21 @@ E.showMenu = function (items) {
.setColor(hl ? g.theme.fgH : g.theme.fg)
.setFontAlign(-1, -1);
var vplain = v.indexOf("\0") < 0;
var truncated = true;
if (vplain && name.length >= 17 - v.length && typeof item === "object") {
g.drawString(name.substring(nameScroll, nameScroll + 12 - v.length) + "...", x + 3.7, y + 2.7);
}
else if (vplain && name.length >= 15) {
g.drawString(name.substring(nameScroll, nameScroll + 15) + "...", x + 3.7, y + 2.7);
var truncated = false;
var drawn = false;
if (vplain) {
var isFunc = typeof item === "function";
var lim = isFunc ? 15 : 17 - v.length;
if (name.length >= lim) {
var len = isFunc ? 15 : 12 - v.length;
var dots = name.length - nameScroll > len ? "..." : "";
g.drawString(name.substring(nameScroll, nameScroll + len) + dots, x + 3.7, y + 2.7);
drawn = true;
truncated = true;
}
}
else {
if (!drawn)
g.drawString(name, x + 3.7, y + 2.7);
truncated = false;
}
var xo = x2;
if (selectEdit && idx === selected) {
xo -= 24 + 1;
Expand Down
34 changes: 25 additions & 9 deletions apps/promenu/bootb2.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
type ActualMenuItem = Exclude<Menu["..."], MenuOptions | undefined>;

const enum Consts {
NAME_SCROLL_PAD = 5,
}

E.showMenu = (items?: Menu): MenuInstance => {
const RectRnd = (x1: number, y1: number, x2: number, y2: number, r: number) => {
const pp = [];
Expand Down Expand Up @@ -60,15 +64,27 @@ E.showMenu = (items?: Menu): MenuInstance => {
.setFontAlign(-1, -1);

const vplain = v.indexOf("\0") < 0;
let truncated = true;
if(vplain && name.length >= 17 - v.length && typeof item === "object"){
g.drawString(name.substring(nameScroll, nameScroll + 12 - v.length) + "...", x + 3.7, y + 2.7);
}else if(vplain && name.length >= 15){
g.drawString(name.substring(nameScroll, nameScroll + 15) + "...", x + 3.7, y + 2.7);
}else{
g.drawString(name, x + 3.7, y + 2.7);
truncated = false;
let truncated = false;
let drawn = false;
if(vplain){
const isFunc = typeof item === "function";
const lim = isFunc ? 15 : 17 - v.length;

if(name.length >= lim){
const len = isFunc ? 15 : 12 - v.length;
const dots = name.length - nameScroll > len ? "..." : "";

g.drawString(
name.substring(nameScroll, nameScroll + len) + dots,
x + 3.7,
y + 2.7
);
drawn = true;
truncated = true;
}
}
if(!drawn)
g.drawString(name, x + 3.7, y + 2.7);

let xo = x2;
if (selectEdit && idx === selected) {
Expand Down Expand Up @@ -138,7 +154,7 @@ E.showMenu = (items?: Menu): MenuInstance => {
) => {
drawLine(name, v, item, idx, x, iy, nameScroll);
nameScroll += 1;
if (nameScroll >= name.length - 5) nameScroll = 0;
if (nameScroll >= name.length - Consts.NAME_SCROLL_PAD) nameScroll = 0;
}, 300, name, v, item, idx, x, iy);
}

Expand Down
2 changes: 1 addition & 1 deletion 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.08",
"version": "0.09",
"description": "Replace the built in menu function. Supports Bangle.js 1 and Bangle.js 2.",
"icon": "icon.png",
"type": "bootloader",
Expand Down

0 comments on commit 5c2760a

Please sign in to comment.