calculator: truncate long numbers

master
Flaparoo 2024-09-10 21:18:25 +08:00
parent 4d8c46ba51
commit 563829bf82
3 changed files with 6 additions and 1 deletions

View File

@ -5,3 +5,4 @@
0.05: Grid positioning and swipe controls to switch between numbers, operators and special (for Bangle.js 2) 0.05: Grid positioning and swipe controls to switch between numbers, operators and special (for Bangle.js 2)
0.06: Bangle.js 2: Exit with a short press of the physical button 0.06: Bangle.js 2: Exit with a short press of the physical button
0.07: Bangle.js 2: Exit by pressing upper left corner of the screen 0.07: Bangle.js 2: Exit by pressing upper left corner of the screen
0.08: truncate long numbers (and append '-' to displayed value)

View File

@ -13,6 +13,7 @@ require("Font7x11Numeric7Seg").add(Graphics);
var DEFAULT_SELECTION_NUMBERS = '5', DEFAULT_SELECTION_OPERATORS = '=', DEFAULT_SELECTION_SPECIALS = 'R'; var DEFAULT_SELECTION_NUMBERS = '5', DEFAULT_SELECTION_OPERATORS = '=', DEFAULT_SELECTION_SPECIALS = 'R';
var RIGHT_MARGIN = 20; var RIGHT_MARGIN = 20;
var RESULT_HEIGHT = 40; var RESULT_HEIGHT = 40;
var RESULT_MAX_LEN = Math.floor((g.getWidth() - 20) / 14);
var COLORS = { var COLORS = {
// [normal, selected] // [normal, selected]
DEFAULT: ['#7F8183', '#A6A6A7'], DEFAULT: ['#7F8183', '#A6A6A7'],
@ -261,6 +262,9 @@ function displayOutput(num) {
num = num.toString(); num = num.toString();
num = num.replace("-","- "); // fix padding for '-' num = num.replace("-","- "); // fix padding for '-'
g.setFont('7x11Numeric7Seg', 2); g.setFont('7x11Numeric7Seg', 2);
if (num.length > RESULT_MAX_LEN) {
num = num.substr(0, RESULT_MAX_LEN - 1)+'-';
}
} }
g.setFontAlign(1,0); g.setFontAlign(1,0);
g.drawString(num, g.getWidth()-20, RESULT_HEIGHT/2); g.drawString(num, g.getWidth()-20, RESULT_HEIGHT/2);

View File

@ -2,7 +2,7 @@
"id": "calculator", "id": "calculator",
"name": "Calculator", "name": "Calculator",
"shortName": "Calculator", "shortName": "Calculator",
"version": "0.07", "version": "0.08",
"description": "Basic calculator reminiscent of MacOs's one. Handy for small calculus.", "description": "Basic calculator reminiscent of MacOs's one. Handy for small calculus.",
"icon": "calculator.png", "icon": "calculator.png",
"screenshots": [{"url":"screenshot_calculator.png"}], "screenshots": [{"url":"screenshot_calculator.png"}],