Skip to content

Commit

Permalink
Set default font in a better way
Browse files Browse the repository at this point in the history
  • Loading branch information
suchmememanyskill committed Feb 10, 2024
1 parent 1c10d46 commit 2fb83df
Show file tree
Hide file tree
Showing 17 changed files with 67 additions and 91 deletions.
2 changes: 1 addition & 1 deletion CYD-Klipper/src/conf/lv_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@
#define LV_FONT_CUSTOM_DECLARE

/*Always set a default font*/
#define LV_FONT_DEFAULT &lv_font_montserrat_14
#define LV_FONT_DEFAULT &CYD_SCREEN_FONT

/*Enable handling large font and/or fonts with a lot of characters.
*The limit depends on the font size, font face and bpp.
Expand Down
12 changes: 3 additions & 9 deletions CYD-Klipper/src/core/lv_setup.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "lv_setup.h"
#include "screen_driver.h"
#include "../conf/global_config.h"
#include "lvgl.h"
#include <Esp.h>

#ifndef CPU_FREQ_HIGH
Expand All @@ -10,9 +11,10 @@
#define CPU_FREQ_LOW 80
#endif

typedef void (*lv_indev_drv_read_cb_t)(struct _lv_indev_drv_t * indev_drv, lv_indev_data_t * data);

bool isScreenInSleep = false;
lv_timer_t *screenSleepTimer;
static lv_style_t default_label_style;

void set_screen_brightness()
{
Expand Down Expand Up @@ -120,9 +122,6 @@ void lv_touch_intercept(lv_indev_drv_t *indev_driver, lv_indev_data_t *data)

void lv_setup()
{
lv_style_init(&default_label_style);
lv_style_set_text_font(&default_label_style, &CYD_SCREEN_FONT);

screen_timer_setup();
screen_timer_start();
set_color_scheme();
Expand All @@ -138,9 +137,4 @@ void lv_setup()
bool is_screen_asleep()
{
return isScreenInSleep;
}

lv_style_t * get_default_label_style()
{
return &default_label_style;
}
8 changes: 1 addition & 7 deletions CYD-Klipper/src/core/lv_setup.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
#pragma once

#include "lvgl.h"

typedef void (*lv_indev_drv_read_cb_t)(struct _lv_indev_drv_t * indev_drv, lv_indev_data_t * data);

void set_screen_brightness();
void set_screen_timer_period();
void screen_timer_wake();
void screen_timer_start();
void screen_timer_stop();
void set_color_scheme();
void lv_setup();
bool is_screen_asleep();

lv_style_t * get_default_label_style();
bool is_screen_asleep();
10 changes: 5 additions & 5 deletions CYD-Klipper/src/ui/ip_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static void power_devices_button(lv_event_t * e) {
lv_obj_set_size(button, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_obj_add_event_cb(button, destroy_event_user_data, LV_EVENT_CLICKED, panel);

lv_obj_t * label = lv_label_create_ex(button);
lv_obj_t * label = lv_label_create(button);
lv_label_set_text(label, LV_SYMBOL_CLOSE " Close");
lv_obj_center(label);

Expand All @@ -120,7 +120,7 @@ static void power_devices_button(lv_event_t * e) {
void redraw_connect_screen(){
lv_obj_clean(lv_scr_act());

label = lv_label_create_ex(lv_scr_act());
label = lv_label_create(lv_scr_act());
lv_label_set_text(label, "Connecting to Klipper");
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);

Expand All @@ -133,7 +133,7 @@ void redraw_connect_screen(){
lv_obj_add_event_cb(reset_btn, reset_btn_event_handler, LV_EVENT_CLICKED, NULL);
lv_obj_set_height(reset_btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);

lv_obj_t * btn_label = lv_label_create_ex(reset_btn);
lv_obj_t * btn_label = lv_label_create(reset_btn);
lv_label_set_text(btn_label, "Reset");
lv_obj_center(btn_label);

Expand All @@ -142,7 +142,7 @@ void redraw_connect_screen(){
lv_obj_add_event_cb(power_devices_btn, power_devices_button, LV_EVENT_CLICKED, NULL);
lv_obj_set_height(power_devices_btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);

btn_label = lv_label_create_ex(power_devices_btn);
btn_label = lv_label_create(power_devices_btn);
lv_label_set_text(btn_label, "Power Devices");
lv_obj_center(btn_label);
}
Expand All @@ -166,7 +166,7 @@ void ip_init_inner(){
lv_obj_set_flex_grow(top_root, 1);
lv_obj_set_style_pad_all(top_root, CYD_SCREEN_GAP_PX, 0);

label = lv_label_create_ex(top_root);
label = lv_label_create(top_root);
lv_label_set_text(label, "Enter Klipper IP/Hostname and Port");
lv_obj_set_width(label, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 2);

Expand Down
12 changes: 6 additions & 6 deletions CYD-Klipper/src/ui/main_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void error_ui_macros_open(lv_event_t * e){
lv_obj_set_size(button, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_obj_add_event_cb(button, destroy_event_user_data, LV_EVENT_CLICKED, panel);

lv_obj_t * label = lv_label_create_ex(button);
lv_obj_t * label = lv_label_create(button);
lv_label_set_text(label, LV_SYMBOL_CLOSE " Close");
lv_obj_center(label);

Expand All @@ -49,10 +49,10 @@ void error_ui(){
lv_obj_set_flex_align(panel, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START);

lv_obj_t * label;
label = lv_label_create_ex(panel);
label = lv_label_create(panel);
lv_label_set_text(label, LV_SYMBOL_WARNING " Printer is not ready");

label = lv_label_create_ex(panel);
label = lv_label_create(panel);
lv_label_set_text(label, printer.state_message);
lv_obj_set_width(label, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 2);
lv_obj_clear_flag(label, LV_OBJ_FLAG_SCROLLABLE);
Expand All @@ -67,7 +67,7 @@ void error_ui(){
lv_obj_add_event_cb(btn, btn_click_restart, LV_EVENT_CLICKED, NULL);
lv_obj_set_flex_grow(btn, 1);

label = lv_label_create_ex(btn);
label = lv_label_create(btn);
lv_label_set_text(label, "Restart");
lv_obj_center(label);

Expand All @@ -76,7 +76,7 @@ void error_ui(){
lv_obj_add_event_cb(btn, btn_click_firmware_restart, LV_EVENT_CLICKED, NULL);
lv_obj_set_flex_grow(btn, 1);

label = lv_label_create_ex(btn);
label = lv_label_create(btn);
lv_label_set_text(label, "FW Restart");
lv_obj_center(label);

Expand All @@ -86,7 +86,7 @@ void error_ui(){
lv_obj_add_event_cb(btn, error_ui_macros_open, LV_EVENT_CLICKED, NULL);
lv_obj_set_flex_grow(btn, 1);

label = lv_label_create_ex(btn);
label = lv_label_create(btn);
lv_label_set_text(label, "Devices");
lv_obj_center(label);
}
Expand Down
2 changes: 1 addition & 1 deletion CYD-Klipper/src/ui/nav_buttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void create_button(const char* icon, const char* name, lv_event_cb_t button_clic
if (button_click != NULL)
lv_obj_add_event_cb(btn, button_click, LV_EVENT_CLICKED, NULL);

lv_obj_t* label = lv_label_create_ex(btn);
lv_obj_t* label = lv_label_create(btn);
lv_label_set_text(label, icon);
lv_obj_align(label, LV_ALIGN_CENTER, 0, -1 * CYD_SCREEN_GAP_PX);

Expand Down
4 changes: 2 additions & 2 deletions CYD-Klipper/src/ui/ota_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ void ota_do_update(bool variant_automatic)
lv_obj_align(panel, LV_ALIGN_TOP_LEFT, 0, 0);
lv_layout_flex_column(panel, LV_FLEX_ALIGN_CENTER);

lv_obj_t *label = lv_label_create_ex(panel);
lv_obj_t *label = lv_label_create(panel);
lv_label_set_text(label, "Updating OTA...");

percentage_bar = lv_bar_create(panel);
lv_obj_set_size(percentage_bar, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX * 0.75f);

update_label = lv_label_create_ex(panel);
update_label = lv_label_create(panel);
lv_label_set_text(update_label, "0/0");

if (!variant_automatic) {
Expand Down
10 changes: 5 additions & 5 deletions CYD-Klipper/src/ui/panels/macros_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void macros_panel_add_macros_to_panel(lv_obj_t * root_panel, MACROSQUERY query){
lv_layout_flex_row(panel, LV_FLEX_ALIGN_END);
lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);

lv_obj_t * label = lv_label_create_ex(panel);
lv_obj_t * label = lv_label_create(panel);
lv_label_set_text(label, macro);
lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR);
lv_obj_set_flex_grow(label, 1);
Expand All @@ -37,7 +37,7 @@ void macros_panel_add_macros_to_panel(lv_obj_t * root_panel, MACROSQUERY query){
lv_obj_add_event_cb(btn, btn_press, LV_EVENT_CLICKED, (void*)macro);
lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);

label = lv_label_create_ex(btn);
label = lv_label_create(btn);
lv_label_set_text(label, "Run");
lv_obj_center(label);

Expand Down Expand Up @@ -66,7 +66,7 @@ void macros_panel_add_power_devices_to_panel(lv_obj_t * root_panel, POWERQUERY q
lv_layout_flex_row(panel, LV_FLEX_ALIGN_END);
lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);

lv_obj_t * label = lv_label_create_ex(panel);
lv_obj_t * label = lv_label_create(panel);
lv_label_set_text(label, power_device_name);
lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR);
lv_obj_set_flex_grow(label, 1);
Expand All @@ -90,14 +90,14 @@ void macros_panel_init(lv_obj_t* panel) {
lv_obj_set_size(btn, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_obj_align(btn, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_GAP_PX);

lv_obj_t * label = lv_label_create_ex(btn);
lv_obj_t * label = lv_label_create(btn);
lv_label_set_text(label, LV_SYMBOL_SETTINGS " Screen Settings");
lv_obj_center(label);

MACROSQUERY query = macros_query();
POWERQUERY power = power_devices_query();
if (query.count == 0 && power.count == 0){
label = lv_label_create_ex(panel);
label = lv_label_create(panel);
lv_label_set_text(label, "No macros found.\nMacros with the description\n\"CYD_SCREEN_MACRO\"\nwill show up here.");
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
return;
Expand Down
12 changes: 6 additions & 6 deletions CYD-Klipper/src/ui/panels/move_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ inline void root_panel_steppers_locked(lv_obj_t * root_panel){
lv_obj_add_event_cb(btn, home_button_click, LV_EVENT_CLICKED, NULL);
lv_obj_set_flex_grow(btn, 1);

lv_obj_t * label = lv_label_create_ex(btn);
lv_obj_t * label = lv_label_create(btn);
lv_label_set_text(label, LV_SYMBOL_HOME "Home Axis");
lv_obj_center(label);

Expand All @@ -129,12 +129,12 @@ inline void root_panel_steppers_locked(lv_obj_t * root_panel){
lv_obj_add_event_cb(btn, disable_steppers_click, LV_EVENT_CLICKED, NULL);
lv_obj_set_flex_grow(btn, 1);

label = lv_label_create_ex(btn);
label = lv_label_create(btn);
lv_label_set_text(label, LV_SYMBOL_EYE_CLOSE " Disable Step");
lv_obj_center(label);

for (int row = 0; row < 3; row++) {
label = lv_label_create_ex(panel);
label = lv_label_create(panel);
lv_label_set_text(label, "???");
lv_obj_set_width(label, width);
lv_obj_add_event_cb(label, position_callbacks[row], LV_EVENT_MSG_RECEIVED, NULL);
Expand All @@ -151,7 +151,7 @@ inline void root_panel_steppers_locked(lv_obj_t * root_panel){
lv_obj_add_event_cb(btn, button_callbacks[row], LV_EVENT_CLICKED, (void*)(offsets[row] + col));
lv_obj_set_flex_grow(btn, 1);

label = lv_label_create_ex(btn);
label = lv_label_create(btn);
lv_label_set_text(label, offset_labels[row][col]);
lv_obj_center(label);
}
Expand All @@ -165,14 +165,14 @@ inline void root_panel_steppers_unlocked(lv_obj_t * root_panel){
lv_obj_set_style_pad_all(panel, CYD_SCREEN_GAP_PX, 0);
lv_layout_flex_column(panel, LV_FLEX_ALIGN_CENTER);

lv_obj_t * label = lv_label_create_ex(panel);
lv_obj_t * label = lv_label_create(panel);
lv_label_set_text(label, LV_SYMBOL_EYE_CLOSE " Steppers unlocked");

lv_obj_t * btn = lv_btn_create(panel);
lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_obj_add_event_cb(btn, home_button_click, LV_EVENT_CLICKED, NULL);

label = lv_label_create_ex(btn);
label = lv_label_create(btn);
lv_label_set_text(label, LV_SYMBOL_HOME "Home Axis");
lv_obj_center(label);
}
Expand Down
11 changes: 5 additions & 6 deletions CYD-Klipper/src/ui/panels/print_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ static void btn_print_file_verify(lv_event_t * e){
lv_obj_set_size(panel, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 4, CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_GAP_PX * 3);
lv_obj_align(panel, LV_ALIGN_CENTER, 0, 0);

lv_obj_t * label = lv_label_create_ex(panel);
lv_obj_t * label = lv_label_create(panel);
lv_label_set_text(label, "Print File");
lv_obj_align(label, LV_ALIGN_TOP_LEFT, 0, 0);

label = lv_label_create_ex(panel);
label = lv_label_create(panel);
lv_label_set_text(label, selected_file->name);
lv_obj_align(label, LV_ALIGN_CENTER, 0, -20);
lv_obj_set_width(label, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 10);
Expand All @@ -67,7 +67,7 @@ static void btn_print_file_verify(lv_event_t * e){
lv_obj_set_size(btn, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * button_size_mult, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX * button_size_mult);
lv_obj_add_event_cb(btn, destroy_event_user_data, LV_EVENT_CLICKED, panel);

label = lv_label_create_ex(btn);
label = lv_label_create(btn);
lv_label_set_text(label, LV_SYMBOL_CLOSE);
lv_obj_center(label);

Expand All @@ -76,7 +76,7 @@ static void btn_print_file_verify(lv_event_t * e){
lv_obj_set_size(btn, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * button_size_mult, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX * button_size_mult);
lv_obj_add_event_cb(btn, btn_print_file, LV_EVENT_CLICKED, panel);

label = lv_label_create_ex(btn);
label = lv_label_create(btn);
lv_label_set_text(label, LV_SYMBOL_OK);
lv_obj_center(label);
}
Expand All @@ -98,7 +98,6 @@ void print_panel_init(lv_obj_t* panel){
int count = 0;
while (files != NULL && files->name != NULL && count <= 20){
lv_obj_t * btn = lv_list_add_btn(list, LV_SYMBOL_FILE, files->name);
lv_obj_add_style(btn, get_default_label_style(), 0);
lv_obj_set_style_bg_opa(btn, LV_OPA_TRANSP, 0);
lv_obj_add_event_cb(btn, btn_print_file_verify, LV_EVENT_CLICKED, (void*)files);

Expand All @@ -108,7 +107,7 @@ void print_panel_init(lv_obj_t* panel){

if (count <= 0){
lv_obj_del(list);
lv_obj_t * label = lv_label_create_ex(panel);
lv_obj_t * label = lv_label_create(panel);
lv_label_set_text(label, "Failed to read files.");
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
}
Expand Down
14 changes: 7 additions & 7 deletions CYD-Klipper/src/ui/panels/progress_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void progress_panel_init(lv_obj_t* panel){
lv_layout_flex_column(center_panel);

// Filename
lv_obj_t * label = lv_label_create_ex(center_panel);
lv_obj_t * label = lv_label_create(center_panel);
lv_label_set_text(label, printer.print_filename);
lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR);
lv_obj_set_width(label, panel_width);
Expand All @@ -73,21 +73,21 @@ void progress_panel_init(lv_obj_t* panel){
lv_obj_set_size(time_est_panel, panel_width, LV_SIZE_CONTENT);

// Elapsed Time
label = lv_label_create_ex(time_est_panel);
label = lv_label_create(time_est_panel);
lv_label_set_text(label, "???");
lv_obj_align(label, LV_ALIGN_LEFT_MID, 0, 0);
lv_obj_add_event_cb(label, update_printer_data_elapsed_time, LV_EVENT_MSG_RECEIVED, NULL);
lv_msg_subsribe_obj(DATA_PRINTER_DATA, label, NULL);

// Remaining Time
label = lv_label_create_ex(time_est_panel);
label = lv_label_create(time_est_panel);
lv_label_set_text(label, "???");
lv_obj_align(label, LV_ALIGN_RIGHT_MID, 0, 0);
lv_obj_add_event_cb(label, update_printer_data_remaining_time, LV_EVENT_MSG_RECEIVED, NULL);
lv_msg_subsribe_obj(DATA_PRINTER_DATA, label, NULL);

// Percentage
label = lv_label_create_ex(time_est_panel);
label = lv_label_create(time_est_panel);
lv_label_set_text(label, "???");
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
lv_obj_add_event_cb(label, update_printer_data_percentage, LV_EVENT_MSG_RECEIVED, NULL);
Expand All @@ -99,7 +99,7 @@ void progress_panel_init(lv_obj_t* panel){
lv_obj_set_size(btn, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * button_size_mult, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX * button_size_mult);
lv_obj_add_event_cb(btn, btn_click_stop, LV_EVENT_CLICKED, NULL);

label = lv_label_create_ex(btn);
label = lv_label_create(btn);
lv_label_set_text(label, LV_SYMBOL_STOP);
lv_obj_center(label);

Expand All @@ -108,7 +108,7 @@ void progress_panel_init(lv_obj_t* panel){
btn = lv_btn_create(panel);
lv_obj_add_event_cb(btn, btn_click_resume, LV_EVENT_CLICKED, NULL);

label = lv_label_create_ex(btn);
label = lv_label_create(btn);
lv_label_set_text(label, LV_SYMBOL_PLAY);
lv_obj_center(label);
}
Expand All @@ -117,7 +117,7 @@ void progress_panel_init(lv_obj_t* panel){
btn = lv_btn_create(panel);
lv_obj_add_event_cb(btn, btn_click_pause, LV_EVENT_CLICKED, NULL);

label = lv_label_create_ex(btn);
label = lv_label_create(btn);
lv_label_set_text(label, LV_SYMBOL_PAUSE);
lv_obj_center(label);
}
Expand Down
Loading

0 comments on commit 2fb83df

Please sign in to comment.