working autoscroll

master
kkayam 2025-01-23 19:27:21 +00:00
parent 836c49e045
commit 4084754df3
2 changed files with 49 additions and 11 deletions

View File

@ -43,6 +43,31 @@
// Split content into words and remove empty strings // Split content into words and remove empty strings
const words = content.split(/\s+/).filter(word => word.length > 0); const words = content.split(/\s+/).filter(word => word.length > 0);
let currentWordIndex = 0; let currentWordIndex = 0;
let autoScrollInterval;
const SCROLL_SPEED = 200; // Time in ms between words during auto-scroll
let startAutoScroll = (direction) => {
if (autoScrollInterval) return; // Already scrolling
autoScrollInterval = setInterval(() => {
if (direction === 'prev' && currentWordIndex > 0) {
currentWordIndex--;
draw();
} else if (direction === 'next' && currentWordIndex < words.length - 1) {
currentWordIndex++;
draw();
} else {
clearInterval(autoScrollInterval);
autoScrollInterval = undefined;
}
}, SCROLL_SPEED);
};
let stopAutoScroll = () => {
if (autoScrollInterval) {
clearInterval(autoScrollInterval);
autoScrollInterval = undefined;
}
};
let draw = () => { let draw = () => {
// Set theme colors // Set theme colors
@ -67,22 +92,35 @@
mode: "custom", mode: "custom",
back: showFileBrowser, back: showFileBrowser,
touch: (button, xy) => { touch: (button, xy) => {
if (button == 1) { if (xy.type === 2) { // Long press
// Left side - previous word if (button === 1) {
if (currentWordIndex > 0) { startAutoScroll('prev');
currentWordIndex--; } else {
draw(); startAutoScroll('next');
} }
} else { } else if (xy.type === 0) { // Quick touch
// Right side - next word stopAutoScroll();
if (currentWordIndex < words.length - 1) { if (button === 1) {
currentWordIndex++; if (currentWordIndex > 0) {
draw(); currentWordIndex--;
draw();
}
} else {
if (currentWordIndex < words.length - 1) {
currentWordIndex++;
draw();
}
} }
} }
} }
}); });
// Make sure to stop auto-scroll when exiting
let cleanup = () => {
stopAutoScroll();
};
Bangle.on('lock', cleanup);
draw(); draw();
}; };

View File

@ -2,7 +2,7 @@
"id": "textreader", "id": "textreader",
"name": "Text Reader", "name": "Text Reader",
"shortName": "TextReader", "shortName": "TextReader",
"version": "0.02", "version": "0.03",
"description": "Read text files from your Bangle.js filesystem", "description": "Read text files from your Bangle.js filesystem",
"type": "app", "type": "app",
"tags": "tool,files,reader", "tags": "tool,files,reader",