forked from espruino/BangleApps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
tonykakuuu
committed
Feb 4, 2025
1 parent
9b22417
commit f5e6842
Showing
8 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.01: New App! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# txtreader | ||
|
||
Very basic text reader with an integrated file selector. | ||
|
||
## Features | ||
|
||
- select files from storage (.txt) | ||
- display their contents | ||
- browse pages | ||
|
||
## Controls | ||
|
||
Bangle.js 2 | ||
- tap the right side of the screen to flip to the next page | ||
- tap the left side of the screen to flip to the previous page | ||
- exit by pressing the physical button | ||
|
||
## Creator | ||
|
||
<https://topkekker.rip/> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
function showFileSelector() { | ||
let files = require("Storage").list().filter(f => f.endsWith('.txt')); | ||
|
||
let menuItems = {}; | ||
files.forEach(file => { | ||
menuItems[file] = () => { | ||
E.showPrompt(`Select ${file}?`).then(confirm => { | ||
if (confirm) { | ||
onFileSelected(file); | ||
} else { | ||
showFileSelector(); | ||
} | ||
}); | ||
}; | ||
}); | ||
|
||
menuItems['< Back'] = () => { load(); }; // Go back to the launcher or previous screen | ||
E.showMenu(menuItems); | ||
} | ||
|
||
function onFileSelected(file) { | ||
|
||
var text = require("Storage").read(file); | ||
|
||
function displayText(text, startLine, pageNumber) { | ||
g.clear(); | ||
g.setFont("6x8", 1); | ||
g.setColor(1); | ||
g.drawString("Page " + pageNumber, 10, 2); | ||
g.drawString(file, g.getWidth()-file.length*6, 2); | ||
|
||
var lines = text.split("\n"); | ||
var y = 15; // Text start, top row reserved for page number | ||
var currentLine = startLine || 0; | ||
var linesDisplayed = 0; //Per page | ||
|
||
for (var i = currentLine; i < lines.length; i++) { | ||
var wrappedLines = g.wrapString(lines[i], g.getWidth() - 20); | ||
for (var j = 0; j < wrappedLines.length; j++) { | ||
g.drawString(wrappedLines[j], 10, y); | ||
y += 10; // Move down for the next line | ||
linesDisplayed++; | ||
if (y >= g.getHeight() - 10) { | ||
// If we run out of space, stop drawing | ||
return { nextStartLine: i , linesDisplayed: linesDisplayed }; | ||
} | ||
} | ||
} | ||
return null; // No more lines to display | ||
} | ||
|
||
var currentStartLine = 0; | ||
var currentPage = 1; | ||
var history = []; // Track the start line and lines displayed for each page | ||
|
||
// Initial display | ||
var result = displayText(text, currentStartLine, currentPage); | ||
history.push({ startLine: currentStartLine, linesDisplayed: result.linesDisplayed }); | ||
|
||
// Handle touch events | ||
Bangle.on('touch', function(button) { | ||
if (button === 2) { // Right side of the screen (next page) | ||
var nextStartLine = displayText(text, currentStartLine, currentPage + 1); | ||
if (nextStartLine !== null) { | ||
currentStartLine = nextStartLine.nextStartLine; | ||
currentPage++; | ||
history.push({ startLine: currentStartLine, linesDisplayed: nextStartLine.linesDisplayed }); | ||
displayText(text, currentStartLine, currentPage); | ||
} else { | ||
currentStartLine = 0; | ||
currentPage = 1; | ||
history = [{ startLine: currentStartLine, linesDisplayed: result.linesDisplayed }]; | ||
displayText(text, currentStartLine, currentPage); | ||
} | ||
} else if (button === 1) { // Left side of the screen (previous page) | ||
if (currentPage > 1) { | ||
// Go back to the previous page | ||
history.pop(); // Remove the current page from history | ||
var previousPage = history[history.length - 1]; | ||
currentStartLine = previousPage.startLine; | ||
currentPage--; | ||
displayText(text, currentStartLine, currentPage); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
showFileSelector(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"id": "txtreader", | ||
"name": "txtreader", | ||
"shortName": "txtreader", | ||
"version": "0.01", | ||
"description": "Basic text reader with pages and a file selector.", | ||
"icon": "txtreader.png", | ||
"screenshots": [{"url":"screenshot_txtreader.png"}], | ||
"tags": "app,tool", | ||
"supports": ["BANGLEJS2"], | ||
"readme": "README.md", | ||
"storage": [ | ||
{"name":"txtreader.app.js","url":"app.js"}, | ||
{"name":"txtreader.img","url":"app-icon.js","evaluate":true} | ||
] | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.