Skip to content

Commit

Permalink
use std::array to reduce unnecessary variables
Browse files Browse the repository at this point in the history
  • Loading branch information
yusufmte committed Sep 13, 2022
1 parent 6c7d8c2 commit 3bd3d81
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/displayapp/screens/Dice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Dice::Dice(DisplayApp* app, Controllers::DateTime& dateTime) : Screen(app) {
lv_obj_align(sidesCounter.GetObject(), nullptr, LV_ALIGN_IN_TOP_LEFT, 49, 24);
sidesCounter.SetValue(2);

currentColorIndex = rand() % resultColorsLength;
currentColorIndex = rand() % resultColors.size();

resultLabel = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_font(resultLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76);
Expand Down Expand Up @@ -59,6 +59,6 @@ void Dice::Roll() {
}

void Dice::NextColor() {
currentColorIndex = (currentColorIndex + 1) % resultColorsLength;
currentColorIndex = (currentColorIndex + 1) % resultColors.size();
lv_obj_set_style_local_text_color(resultLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, resultColors[currentColorIndex]);
}
4 changes: 2 additions & 2 deletions src/displayapp/screens/Dice.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "displayapp/widgets/Counter.h"
#include "components/datetime/DateTimeController.h"
#include <lvgl/lvgl.h>
#include <array>

namespace Pinetime::Applications::Screens {
class Dice : public Screen {
Expand All @@ -18,8 +19,7 @@ namespace Pinetime::Applications::Screens {
lv_obj_t* btnRollLabel;
lv_obj_t* resultLabel;

lv_color_t resultColors[3] = {LV_COLOR_YELLOW, LV_COLOR_MAGENTA, LV_COLOR_AQUA};
uint8_t resultColorsLength = sizeof(resultColors) / sizeof(resultColors[0]);
std::array<lv_color_t, 3> resultColors = {LV_COLOR_YELLOW, LV_COLOR_MAGENTA, LV_COLOR_AQUA};
uint8_t currentColorIndex;

uint8_t rollResult;
Expand Down

0 comments on commit 3bd3d81

Please sign in to comment.