mirror of
https://github.com/InfiniTimeOrg/InfiniTime.git
synced 2024-10-22 23:21:53 +02:00
format
This commit is contained in:
parent
5af0a3410d
commit
cacf107c11
|
@ -2,10 +2,8 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <libraries/log/nrf_log.h>
|
#include <libraries/log/nrf_log.h>
|
||||||
|
|
||||||
|
|
||||||
using namespace Pinetime::Applications::Screens;
|
using namespace Pinetime::Applications::Screens;
|
||||||
|
|
||||||
|
|
||||||
static void eventHandler(lv_obj_t* obj, lv_event_t event) {
|
static void eventHandler(lv_obj_t* obj, lv_event_t event) {
|
||||||
auto app = static_cast<Calculator*>(obj->user_data);
|
auto app = static_cast<Calculator*>(obj->user_data);
|
||||||
app->OnButtonEvent(obj, event);
|
app->OnButtonEvent(obj, event);
|
||||||
|
@ -15,12 +13,7 @@ Calculator::~Calculator() {
|
||||||
lv_obj_clean(lv_scr_act());
|
lv_obj_clean(lv_scr_act());
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* buttonMap[] = {
|
static const char* buttonMap[] = {"7", "8", "9", "<", "\n", "4", "5", "6", "+-", "\n", "1", "2", "3", "*/", "\n", ".", "0", "=", "^", ""};
|
||||||
"7", "8", "9", "<", "\n",
|
|
||||||
"4", "5", "6", "+-", "\n",
|
|
||||||
"1", "2", "3", "*/", "\n",
|
|
||||||
".", "0", "=", "^", ""
|
|
||||||
};
|
|
||||||
|
|
||||||
Calculator::Calculator(DisplayApp* app) : Screen(app) {
|
Calculator::Calculator(DisplayApp* app) : Screen(app) {
|
||||||
resultLabel = lv_label_create(lv_scr_act(), nullptr);
|
resultLabel = lv_label_create(lv_scr_act(), nullptr);
|
||||||
|
@ -186,13 +179,7 @@ void Calculator::UpdateResultLabel() {
|
||||||
padding++;
|
padding++;
|
||||||
}
|
}
|
||||||
|
|
||||||
lv_label_set_text_fmt(
|
lv_label_set_text_fmt(resultLabel, "%ld.%0*u", integer, padding, printRemainder);
|
||||||
resultLabel,
|
|
||||||
"%ld.%0*u",
|
|
||||||
integer,
|
|
||||||
padding,
|
|
||||||
printRemainder
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Calculator::UpdateValueLabel() {
|
void Calculator::UpdateValueLabel() {
|
||||||
|
@ -206,14 +193,14 @@ void Calculator::UpdateValueLabel() {
|
||||||
printRemainder = remainder;
|
printRemainder = remainder;
|
||||||
padding = 3;
|
padding = 3;
|
||||||
} else {
|
} else {
|
||||||
printRemainder = remainder / (10*offset);
|
printRemainder = remainder / (10 * offset);
|
||||||
padding = 0;
|
padding = 0;
|
||||||
|
|
||||||
// calculate the padding length as the length difference
|
// calculate the padding length as the length difference
|
||||||
// between FIXED_POINT_OFFSET and offset
|
// between FIXED_POINT_OFFSET and offset
|
||||||
long int tmp = FIXED_POINT_OFFSET / (10*offset);
|
long int tmp = FIXED_POINT_OFFSET / (10 * offset);
|
||||||
while (tmp > 1) {
|
while (tmp > 1) {
|
||||||
padding ++;
|
padding++;
|
||||||
tmp /= 10;
|
tmp /= 10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -223,13 +210,7 @@ void Calculator::UpdateValueLabel() {
|
||||||
} else if ((offset == FIXED_POINT_OFFSET / 10) && (remainder == 0)) {
|
} else if ((offset == FIXED_POINT_OFFSET / 10) && (remainder == 0)) {
|
||||||
lv_label_set_text_fmt(valueLabel, "%ld.", integer);
|
lv_label_set_text_fmt(valueLabel, "%ld.", integer);
|
||||||
} else {
|
} else {
|
||||||
lv_label_set_text_fmt(
|
lv_label_set_text_fmt(valueLabel, "%ld.%0*u", integer, padding, printRemainder);
|
||||||
valueLabel,
|
|
||||||
"%ld.%0*u",
|
|
||||||
integer,
|
|
||||||
padding,
|
|
||||||
printRemainder
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
#include "Screen.h"
|
#include "Screen.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Pinetime {
|
namespace Pinetime {
|
||||||
namespace Applications {
|
namespace Applications {
|
||||||
namespace Screens {
|
namespace Screens {
|
||||||
|
|
Loading…
Reference in a new issue