add backspace button

This commit is contained in:
minacode 2022-12-20 20:03:49 +01:00
parent 8c10adc890
commit e46a1ca712
3 changed files with 32 additions and 7 deletions

View file

@ -7,7 +7,7 @@
},
{
"file": "FontAwesome5-Solid+Brands+Regular.woff",
"range": "0xf294, 0xf242, 0xf54b, 0xf21e, 0xf1e6, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf201, 0xf06e, 0xf015, 0xf00c, 0xf1ec, 0xf743"
"range": "0xf294, 0xf242, 0xf54b, 0xf21e, 0xf1e6, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf201, 0xf06e, 0xf015, 0xf00c, 0xf1ec, 0xf743, 0xf55a"
}
],
"bpp": 1,

View file

@ -1,7 +1,8 @@
#include "Calculator.h"
#include <cmath>
#include <cinttypes>
#include <libraries/log/nrf_log.h>
#include "Calculator.h"
#include "Symbols.h"
using namespace Pinetime::Applications::Screens;
@ -14,7 +15,7 @@ Calculator::~Calculator() {
lv_obj_clean(lv_scr_act());
}
static const char* buttonMap[] = {"7", "8", "9", "<", "\n", "4", "5", "6", "+-", "\n", "1", "2", "3", "*/", "\n", ".", "0", "=", "^", ""};
static const char* buttonMap[] = {"7", "8", "9", Symbols::backspace, "\n", "4", "5", "6", "+-", "\n", "1", "2", "3", "*/", "\n", ".", "0", "=", "^", ""};
Calculator::Calculator(DisplayApp* app) : Screen(app) {
resultLabel = lv_label_create(lv_scr_act(), nullptr);
@ -132,15 +133,38 @@ void Calculator::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
lv_label_refr_text(operationLabel);
break;
case '<':
offset = FIXED_POINT_OFFSET;
// this is a little hacky because it matches only the first char
case Symbols::backspace[0]:
if (value != 0) {
value = 0;
// delete one value digit
if (offset < FIXED_POINT_OFFSET) {
if (offset == 0) {
offset = 1;
} else {
offset *= 10;
}
} else {
value /= 10;
}
if (offset < FIXED_POINT_OFFSET) {
value -= value % (10 * offset);
} else {
value -= value % offset;
}
UpdateValueLabel();
} else {
// reset the result
result = 0;
UpdateResultLabel();
}
UpdateValueLabel();
NRF_LOG_INFO(". offset: %" PRId64, offset);
NRF_LOG_INFO(". value: %" PRId64, value);
NRF_LOG_INFO(". result: %" PRId64, result);
*operation = ' ';
lv_label_refr_text(operationLabel);

View file

@ -40,6 +40,7 @@ namespace Pinetime {
static constexpr const char* home = "\xEF\x80\x95";
static constexpr const char* sleep = "\xEE\xBD\x84";
static constexpr const char* calculator = "\xEF\x87\xAC";
static constexpr const char* backspace = "\xEF\x95\x9A";
// fontawesome_weathericons.c
// static constexpr const char* sun = "\xEF\x86\x85";