Skip to content

Commit

Permalink
Merge pull request #125 from Habbie/fonts-b612-mdi
Browse files Browse the repository at this point in the history
replace all fonts
  • Loading branch information
Habbie authored Oct 20, 2024
2 parents b97da03 + fc339c8 commit 0b7591c
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
[submodule "src/fonts/polarsys-b612"]
path = src/fonts/polarsys-b612
url = https://github.com/polarsys/b612/
[submodule "src/fonts/MaterialDesign-Webfont"]
path = src/fonts/MaterialDesign-Webfont
url = https://github.com/Templarian/MaterialDesign-Webfont
6 changes: 6 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ font_b612_c = xxd_generator.process(
extra_args: 'B612_Regular_ttf',
)

font_mdi_c = xxd_generator.process(
'src/fonts/MaterialDesign-Webfont/fonts/materialdesignicons-webfont.ttf',
extra_args: 'mdi_ttf',
)

brew_prefix = '/opt/homebrew/include'
brew = find_program('brew', required: false)
if brew.found()
Expand Down Expand Up @@ -233,6 +238,7 @@ if get_option('front-lvgl').enabled()
'src/front-lvgl.cpp',
'src/lv_conf.h',
font_b612_c,
font_mdi_c,
'src/generated/domains.hpp',
version_file,
],
Expand Down
1 change: 1 addition & 0 deletions src/fonts/MaterialDesign-Webfont
Submodule MaterialDesign-Webfont added at 57b567
35 changes: 28 additions & 7 deletions src/front-lvgl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@

extern unsigned char B612_Regular_ttf[];
extern unsigned int B612_Regular_ttf_len;
extern unsigned char mdi_ttf[];
extern unsigned int mdi_ttf_len;

namespace voorkant
{
namespace lvgl
{
lv_font_t* b612font;
lv_style_t b612style;
lv_font_t* mdifont;
lv_style_t mdistyle;
}
}

std::mutex g_lvgl_updatelock;
lv_obj_t* cont_row;
Expand Down Expand Up @@ -149,10 +162,15 @@ void uithread(int _argc, char* _argv[])
// lv_group_t* g = lv_group_create();
// lv_group_set_default(g);

static lv_font_t* B612font = lv_tiny_ttf_create_data_ex(B612_Regular_ttf, B612_Regular_ttf_len, 16, LV_FONT_KERNING_NORMAL, 1024);
static lv_style_t B612style;
lv_style_init(&B612style);
lv_style_set_text_font(&B612style, B612font);
voorkant::lvgl::b612font = lv_tiny_ttf_create_data_ex(B612_Regular_ttf, B612_Regular_ttf_len, 16, LV_FONT_KERNING_NORMAL, 1024);
lv_style_init(&voorkant::lvgl::b612style);
lv_style_set_text_font(&voorkant::lvgl::b612style, voorkant::lvgl::b612font);

voorkant::lvgl::mdifont = lv_tiny_ttf_create_data_ex(mdi_ttf, mdi_ttf_len, 16, LV_FONT_KERNING_NORMAL, 1024);
lv_style_init(&voorkant::lvgl::mdistyle);
lv_style_set_text_font(&voorkant::lvgl::mdistyle, voorkant::lvgl::mdifont);

lv_obj_add_style(lv_scr_act(), &voorkant::lvgl::b612style, 0);

/* container for object row (top 80% of screen) and logs (bottom 20%) */
lv_obj_t* row_and_logs = lv_obj_create(lv_scr_act());
Expand Down Expand Up @@ -188,14 +206,17 @@ void uithread(int _argc, char* _argv[])

lv_obj_t* left_btn = lv_button_create(bottom_row);
lv_obj_t* left_btn_txt = lv_label_create(left_btn);
lv_label_set_text(left_btn_txt, LV_SYMBOL_LEFT);
lv_label_set_text(left_btn_txt, MDI_ARROW_LEFT);
lv_obj_add_event_cb(left_btn, btnLeftPress, LV_EVENT_CLICKED, NULL);
lv_obj_add_style(left_btn, &voorkant::lvgl::mdistyle, 0);

UILogBox logbox(bottom_row, &B612style);
UILogBox logbox(bottom_row, &voorkant::lvgl::b612style);

lv_obj_t* right_btn = lv_button_create(bottom_row);
lv_obj_t* right_btn_txt = lv_label_create(right_btn);
lv_label_set_text(right_btn_txt, LV_SYMBOL_RIGHT);
lv_label_set_text(right_btn_txt, MDI_ARROW_RIGHT);
lv_obj_add_style(right_btn_txt, &voorkant::lvgl::mdistyle, 0);

lv_obj_add_event_cb(right_btn, btnRightPress, LV_EVENT_CLICKED, NULL);

lv_log_register_print_cb(lvLogCallback);
Expand Down
17 changes: 17 additions & 0 deletions src/uicomponents/UIComponents.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@

extern std::mutex g_lvgl_updatelock;

// FIXME: this is to make objects from front-lvgl.cpp visible. This is not actually the right header file. We want some singleton core state object anyway.
namespace voorkant
{
namespace lvgl
{
extern lv_font_t* b612font;
extern lv_style_t b612style;
extern lv_font_t* mdifont;
extern lv_style_t mdistyle;
}
}

#define MDI_ARROW_LEFT "\xf3\xb0\x81\x8d"
#define MDI_ARROW_RIGHT "\xf3\xb0\x81\x94"
#define MDI_POWER_STANDBY "\xf3\xb0\xa4\x86"
#define MDI_WAZE "\xf3\xb0\xaf\x9e"

// FIXME: we never free() the lv_obj_t*'s in code
class UIComponent : public IObserver
{
Expand Down
9 changes: 6 additions & 3 deletions src/uicomponents/uirgblight.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "uirgblight.hpp"
#include "logger.hpp"
#include "uicomponents/UIComponents.hpp"
#include <src/core/lv_obj_pos.h>
#include <src/misc/lv_area.h>
#include <src/misc/lv_color.h>
Expand All @@ -18,6 +19,8 @@ lv_obj_t* UIRGBLight::createImageButton(const void* _imgOrSymbol, lv_event_cb_t
lv_obj_t* btn = lv_button_create(btns);
lv_obj_set_size(btn, 50, 40);
lv_obj_set_style_pad_all(btn, 5, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_add_style(btn, &voorkant::lvgl::mdistyle, 0);

if (_toggle) {
lv_obj_add_flag(btn, LV_OBJ_FLAG_CHECKABLE);
}
Expand Down Expand Up @@ -180,9 +183,9 @@ UIRGBLight::UIRGBLight(std::shared_ptr<HAEntity> _entity, lv_obj_t* _parent) :

tilecontainer = lv_tileview_create(flowpanel);
lv_obj_add_event_cb(tilecontainer, UIRGBLight::changeTileCB, LV_EVENT_VALUE_CHANGED, reinterpret_cast<void*>(this));
lv_obj_set_height(tilecontainer, uiEntityWidth - 10);
lv_obj_set_height(tilecontainer, uiEntityWidth - 15);

lv_coord_t sliderheight = widthheight - (lv_coord_t)25;
lv_coord_t sliderheight = widthheight - (lv_coord_t)30;

if (showBrightness) {
lv_obj_t* brightness_tile = lv_tileview_add_tile(tilecontainer, 0, 0, LV_DIR_HOR);
Expand Down Expand Up @@ -259,7 +262,7 @@ UIRGBLight::UIRGBLight(std::shared_ptr<HAEntity> _entity, lv_obj_t* _parent) :
lv_obj_set_flex_align(btns, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
lv_obj_remove_flag(btns, LV_OBJ_FLAG_SCROLLABLE);

btnOnOff = createImageButton(LV_SYMBOL_POWER, UIRGBLight::btnOnOffCB, LV_EVENT_VALUE_CHANGED, true);
btnOnOff = createImageButton(MDI_POWER_STANDBY, UIRGBLight::btnOnOffCB, LV_EVENT_VALUE_CHANGED, true);

if (showBrightness) {
btnBrightness = createImageButton(&G_BRIGHTNESS24, UIRGBLight::btnBrightnessCB, LV_EVENT_CLICKED);
Expand Down

0 comments on commit 0b7591c

Please sign in to comment.