Skip to content

Commit bcc34e0

Browse files
committed
Make changing fonts easier.
Make some changes to centralize the default font sizes. These changes enable fonts to be changed by modifying.. fonts.json, lv_conf.h, CMakeLists.txt and InfiniTineTheme.h. No more having to search & replace to test new fonts. * Abstract the font names behind some sane variable names. * Add Fonts:: namespace to InfinitimeTheme.h, with references to fonts. * Update all screens, widgets, and settings to use the Fonts:: namespace.
1 parent e386fc7 commit bcc34e0

23 files changed

+59
-59
lines changed

src/displayapp/InfiniTimeTheme.cpp

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,10 @@ static void basic_init() {
218218
lv_theme_t* lv_pinetime_theme_init() {
219219
theme.color_primary = LV_COLOR_WHITE;
220220
theme.color_secondary = LV_COLOR_GRAY;
221-
theme.font_small = &jetbrains_mono_bold_20;
222-
theme.font_normal = &jetbrains_mono_bold_20;
223-
theme.font_subtitle = &jetbrains_mono_bold_20;
224-
theme.font_title = &jetbrains_mono_bold_20;
221+
theme.font_small = Fonts::small;
222+
theme.font_normal = Fonts::small;
223+
theme.font_subtitle = Fonts::small;
224+
theme.font_title = Fonts::small;
225225
theme.flags = 0;
226226

227227
basic_init();
@@ -251,22 +251,7 @@ static void theme_apply(lv_obj_t* obj, lv_theme_style_t name) {
251251
lv_obj_clean_style_list(obj, LV_OBJ_PART_MAIN);
252252
list = lv_obj_get_style_list(obj, LV_OBJ_PART_MAIN);
253253
_lv_style_list_add_style(list, &style_box);
254-
break;
255-
256-
case LV_THEME_CONT:
257-
lv_obj_clean_style_list(obj, LV_OBJ_PART_MAIN);
258-
list = lv_obj_get_style_list(obj, LV_CONT_PART_MAIN);
259-
_lv_style_list_add_style(list, &style_box);
260-
break;
261-
262-
case LV_THEME_BTN:
263-
lv_obj_clean_style_list(obj, LV_BTN_PART_MAIN);
264-
list = lv_obj_get_style_list(obj, LV_BTN_PART_MAIN);
265-
_lv_style_list_add_style(list, &style_btn);
266-
break;
267-
268-
case LV_THEME_BTNMATRIX:
269-
list = lv_obj_get_style_list(obj, LV_BTNMATRIX_PART_BG);
254+
break;src/displayapp/InfiniTimeTheme.cppobj, LV_BTNMATRIX_PART_BG);
270255
_lv_style_list_add_style(list, &style_bg);
271256
_lv_style_list_add_style(list, &style_pad_small);
272257

src/displayapp/InfiniTimeTheme.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ namespace Colors {
1515
static constexpr lv_color_t highlight = green;
1616
};
1717

18+
namespace Fonts {
19+
static lv_font_t * small = &jetbrains_mono_bold_20;
20+
static lv_font_t * normal = &jetbrains_mono_42;
21+
static lv_font_t * large = &jetbrains_mono_76;
22+
static lv_font_t * xlarge = &jetbrains_mono_extrabold_compressed;
23+
}
24+
1825
/**
1926
* Initialize the default
2027
* @param color_primary the primary color of the theme

src/displayapp/screens/Alarm.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Alarm::Alarm(Controllers::AlarmController& alarmController,
5656
hourCounter.EnableTwelveHourMode();
5757

5858
lblampm = lv_label_create(lv_scr_act(), nullptr);
59-
lv_obj_set_style_local_text_font(lblampm, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_bold_20);
59+
lv_obj_set_style_local_text_font(lblampm, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Fonts::normal);
6060
lv_label_set_text_static(lblampm, "AM");
6161
lv_label_set_align(lblampm, LV_LABEL_ALIGN_CENTER);
6262
lv_obj_align(lblampm, lv_scr_act(), LV_ALIGN_CENTER, 0, 30);
@@ -70,7 +70,7 @@ Alarm::Alarm(Controllers::AlarmController& alarmController,
7070
minuteCounter.SetValueChangedEventCallback(this, ValueChangedHandler);
7171

7272
lv_obj_t* colonLabel = lv_label_create(lv_scr_act(), nullptr);
73-
lv_obj_set_style_local_text_font(colonLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76);
73+
lv_obj_set_style_local_text_font(colonLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Fonts::large);
7474
lv_label_set_text_static(colonLabel, ":");
7575
lv_obj_align(colonLabel, lv_scr_act(), LV_ALIGN_CENTER, 0, -29);
7676

src/displayapp/screens/Alarm.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "displayapp/screens/Screen.h"
2323
#include "displayapp/widgets/Counter.h"
2424
#include "displayapp/Controllers.h"
25+
#include "displayapp/InfiniTimeTheme.h"
2526
#include "systemtask/WakeLock.h"
2627
#include "Symbols.h"
2728

@@ -62,8 +63,8 @@ namespace Pinetime {
6263
void HideInfo();
6364
void ToggleRecurrence();
6465
void UpdateAlarmTime();
65-
Widgets::Counter hourCounter = Widgets::Counter(0, 23, jetbrains_mono_76);
66-
Widgets::Counter minuteCounter = Widgets::Counter(0, 59, jetbrains_mono_76);
66+
Widgets::Counter hourCounter = Widgets::Counter(0, 23, *Fonts::large);
67+
Widgets::Counter minuteCounter = Widgets::Counter(0, 59, *Fonts::large);
6768
};
6869
}
6970

src/displayapp/screens/BatteryInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ BatteryInfo::BatteryInfo(const Pinetime::Controllers::Battery& batteryController
2929
lv_obj_align(status, nullptr, LV_ALIGN_IN_BOTTOM_MID, 0, -17);
3030

3131
percent = lv_label_create(lv_scr_act(), nullptr);
32-
lv_obj_set_style_local_text_font(percent, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42);
32+
lv_obj_set_style_local_text_font(percent, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Fonts::normal);
3333
lv_label_set_text_fmt(percent, "%02i%%", batteryPercent);
3434
lv_label_set_align(percent, LV_LABEL_ALIGN_LEFT);
3535
lv_obj_align(percent, chargingArc, LV_ALIGN_CENTER, 0, 0);

src/displayapp/screens/Dice.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Dice::Dice(Controllers::MotionController& motionController,
4949
static_cast<uint32_t>(motionController.Z())};
5050
gen.seed(sseq);
5151

52-
lv_obj_t* nCounterLabel = MakeLabel(&jetbrains_mono_bold_20,
52+
lv_obj_t* nCounterLabel = MakeLabel(Fonts::small,
5353
LV_COLOR_WHITE,
5454
LV_LABEL_LONG_EXPAND,
5555
0,
@@ -60,7 +60,7 @@ Dice::Dice(Controllers::MotionController& motionController,
6060
0,
6161
0);
6262

63-
lv_obj_t* dCounterLabel = MakeLabel(&jetbrains_mono_bold_20,
63+
lv_obj_t* dCounterLabel = MakeLabel(Fonts::small,
6464
LV_COLOR_WHITE,
6565
LV_LABEL_LONG_EXPAND,
6666
0,
@@ -82,7 +82,7 @@ Dice::Dice(Controllers::MotionController& motionController,
8282
std::uniform_int_distribution<> distrib(0, resultColors.size() - 1);
8383
currentColorIndex = distrib(gen);
8484

85-
resultTotalLabel = MakeLabel(&jetbrains_mono_42,
85+
resultTotalLabel = MakeLabel(Fonts::normal,
8686
resultColors[currentColorIndex],
8787
LV_LABEL_LONG_BREAK,
8888
120,
@@ -92,7 +92,7 @@ Dice::Dice(Controllers::MotionController& motionController,
9292
LV_ALIGN_IN_TOP_RIGHT,
9393
11,
9494
38);
95-
resultIndividualLabel = MakeLabel(&jetbrains_mono_bold_20,
95+
resultIndividualLabel = MakeLabel(Fonts::small,
9696
resultColors[currentColorIndex],
9797
LV_LABEL_LONG_BREAK,
9898
90,
@@ -112,7 +112,7 @@ Dice::Dice(Controllers::MotionController& motionController,
112112
lv_obj_set_size(btnRoll, 240, 50);
113113
lv_obj_align(btnRoll, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0);
114114

115-
btnRollLabel = MakeLabel(&jetbrains_mono_bold_20,
115+
btnRollLabel = MakeLabel(Fonts::small,
116116
LV_COLOR_WHITE,
117117
LV_LABEL_LONG_EXPAND,
118118
0,

src/displayapp/screens/Dice.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "displayapp/screens/Screen.h"
55
#include "displayapp/widgets/Counter.h"
66
#include "displayapp/Controllers.h"
7+
#include "displayapp/InfiniTimeTheme.h"
78
#include "Symbols.h"
89

910
#include <array>
@@ -35,8 +36,8 @@ namespace Pinetime {
3536
uint8_t currentColorIndex;
3637
void NextColor();
3738

38-
Widgets::Counter nCounter = Widgets::Counter(1, 9, jetbrains_mono_42);
39-
Widgets::Counter dCounter = Widgets::Counter(2, 99, jetbrains_mono_42);
39+
Widgets::Counter nCounter = Widgets::Counter(1, 9, *Fonts::normal);
40+
Widgets::Counter dCounter = Widgets::Counter(2, 99, *Fonts::normal);
4041

4142
bool openingRoll = true;
4243
uint8_t currentRollHysteresis = 0;

src/displayapp/screens/HeartRate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ HeartRate::HeartRate(Controllers::HeartRateController& heartRateController, Syst
3333
bool isHrRunning = heartRateController.State() != Controllers::HeartRateController::States::Stopped;
3434
label_hr = lv_label_create(lv_scr_act(), nullptr);
3535

36-
lv_obj_set_style_local_text_font(label_hr, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76);
36+
lv_obj_set_style_local_text_font(label_hr, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Fonts::large);
3737

3838
if (isHrRunning) {
3939
lv_obj_set_style_local_text_color(label_hr, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::highlight);

src/displayapp/screens/Metronome.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ Metronome::Metronome(Controllers::MotorController& motorController, System::Syst
3535
lv_arc_set_adjustable(bpmArc, true);
3636
lv_obj_align(bpmArc, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 0, 0);
3737

38-
bpmValue = createLabel("120", bpmArc, LV_ALIGN_IN_TOP_MID, &jetbrains_mono_76, 0, 55);
39-
createLabel("bpm", bpmValue, LV_ALIGN_OUT_BOTTOM_MID, &jetbrains_mono_bold_20, 0, 0);
38+
bpmValue = createLabel("120", bpmArc, LV_ALIGN_IN_TOP_MID, Fonts::large, 0, 55);
39+
createLabel("bpm", bpmValue, LV_ALIGN_OUT_BOTTOM_MID, Fonts::small, 0, 0);
4040

4141
bpmTap = lv_btn_create(lv_scr_act(), nullptr);
4242
bpmTap->user_data = this;

src/displayapp/screens/Navigation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ Navigation::Navigation(Pinetime::Controllers::NavigationService& nav) : navServi
213213
txtManDist = lv_label_create(lv_scr_act(), nullptr);
214214
lv_label_set_long_mode(txtManDist, LV_LABEL_LONG_BREAK);
215215
lv_obj_set_style_local_text_color(txtManDist, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN);
216-
lv_obj_set_style_local_text_font(txtManDist, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42);
216+
lv_obj_set_style_local_text_font(txtManDist, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Fonts::normal);
217217
lv_obj_set_width(txtManDist, LV_HOR_RES);
218218
lv_label_set_text_static(txtManDist, "--M");
219219
lv_label_set_align(txtManDist, LV_LABEL_ALIGN_CENTER);

0 commit comments

Comments
 (0)