Skip to content

Commit

Permalink
POC refactoring on style and screen code for Splash screen on Marlin …
Browse files Browse the repository at this point in the history
…target
  • Loading branch information
luc-github committed Apr 28, 2024
1 parent 4f0ef28 commit 3ecfd41
Show file tree
Hide file tree
Showing 75 changed files with 513 additions and 396 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ OPTION(HARDWARE_MOD_EXT_PSRAM "Hardware Mod: External PSRAM" OFF)
# #######################################
# Select one targeted firmware
# #######################################
OPTION(TARGET_FW_MARLIN "Marlin firmware" OFF)
OPTION(TARGET_FW_MARLIN "Marlin firmware" ON)
OPTION(TARGET_FW_REPETIER "Repetier firmware" OFF)
OPTION(TARGET_FW_SMOOTHIEWARE "Smoothieware firmware" OFF)
OPTION(TARGET_FW_GRBL "GRBL firmware" ON)
OPTION(TARGET_FW_GRBL "GRBL firmware" OFF)


# #######################################
Expand Down
2 changes: 1 addition & 1 deletion cmake/dev_tools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ add_compile_options(-DESP3D_TFT_LOG=0)
add_compile_options(-DDISABLE_COLOR_LOG=0)

#Use the Snapshot API of LVGL to dump screens to the SD card
add_compile_options(-DLV_USE_SNAPSHOT=0)
add_compile_options(-DLV_USE_SNAPSHOT=1)

# ESP3D-TFT specific bechmark
# Enabled = 1
Expand Down
63 changes: 22 additions & 41 deletions main/display/3dprinter/marlin/esp3d_styles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,7 @@
#include "esp3d_styles.h"

#include "esp3d_log.h"

#define CURRENT_MAIN_BG_COLOR lv_color_hex(0x000000)

#define CURRENT_BG_LABEL_TEXT_COLOR lv_color_hex(0xFFFFFF)

#define CURRENT_STATUS_BAR_TEXT_COLOR lv_color_hex(0x000000)
#define CURRENT_STATUS_BAR_BG_COLOR lv_color_hex(0xFFFFFF)

#define CURRENT_STATUS_BAR_BORDER_COLOR lv_palette_main(LV_PALETTE_GREY)

#define CURRENT_BUTTON_COLOR_PALETTE LV_PALETTE_GREY
#define CURRENT_BUTTON_COLOR_PALETTE_DARKEN 2

#define CURRENT_BUTTON_BORDER_COLOR \
lv_color_hex(0xFFFFFF) // lv_palette_main(LV_PALETTE_GREY)
#define CURRENT_BUTTON_TEXT_COLOR lv_color_hex(0xFFFFFF)
#define CURRENT_BUTTON_OUTLINE_COLOR_PALETTE LV_PALETTE_GREEN
#define CURRENT_BUTTON_PRESSED_COLOR_PALETTE LV_PALETTE_GREY
#define CURRENT_BUTTON_PRESSED_TEXT_COLOR lv_color_hex(0x00FF00)
#define CURRENT_BUTTON_PRESSED_BORDER_COLOR lv_color_hex(0x00FF00)

namespace ESP3DStyle {
// Create styles for main background
lv_style_t style_main_bg;
lv_style_t style_bg_label;
Expand Down Expand Up @@ -82,45 +62,45 @@ lv_style_t style_text_container;
lv_style_t style_spinner_screen;
lv_style_t style_spinner_text;

bool init_styles() {
bool init() {
/*
Spinner screen
*/
lv_style_init(&style_spinner_screen);
lv_style_set_text_opa(&style_spinner_screen, LV_OPA_COVER);
lv_style_set_text_color(&style_spinner_screen, CURRENT_BG_LABEL_TEXT_COLOR);
lv_style_set_bg_color(&style_spinner_screen, CURRENT_MAIN_BG_COLOR);
lv_style_set_text_color(&style_spinner_screen, ESP3D_SCREEN_BACKGROUND_TEXT_COLOR);
lv_style_set_bg_color(&style_spinner_screen, ESP3D_SCREEN_BACKGROUND_COLOR);
lv_style_set_bg_opa(&style_spinner_screen, LV_OPA_50);
/*
Spinner text
*/
lv_style_init(&style_spinner_text);
lv_style_set_text_opa(&style_spinner_text, LV_OPA_COVER);
lv_style_set_text_color(&style_spinner_text, CURRENT_BG_LABEL_TEXT_COLOR);
lv_style_set_text_color(&style_spinner_text, ESP3D_SCREEN_BACKGROUND_TEXT_COLOR);

/*
Main background
*/
lv_style_init(&style_main_bg);
lv_style_set_text_opa(&style_main_bg, LV_OPA_COVER);
lv_style_set_text_color(&style_main_bg, CURRENT_BG_LABEL_TEXT_COLOR);
lv_style_set_bg_color(&style_main_bg, CURRENT_MAIN_BG_COLOR);
lv_style_set_text_color(&style_main_bg, ESP3D_SCREEN_BACKGROUND_TEXT_COLOR);
lv_style_set_bg_color(&style_main_bg, ESP3D_SCREEN_BACKGROUND_COLOR);

/*
Label on main background
*/
lv_style_init(&style_bg_label);
lv_style_set_text_opa(&style_bg_label, LV_OPA_COVER);
lv_style_set_text_color(&style_bg_label, CURRENT_BG_LABEL_TEXT_COLOR);
lv_style_set_bg_color(&style_bg_label, CURRENT_MAIN_BG_COLOR);
lv_style_set_text_color(&style_bg_label, ESP3D_SCREEN_BACKGROUND_TEXT_COLOR);
lv_style_set_bg_color(&style_bg_label, ESP3D_SCREEN_BACKGROUND_COLOR);

/*
read only value on main background
*/
lv_style_init(&style_read_only_value);
lv_style_set_text_opa(&style_read_only_value, LV_OPA_COVER);
lv_style_set_text_color(&style_read_only_value, CURRENT_BG_LABEL_TEXT_COLOR);
lv_style_set_bg_color(&style_read_only_value, CURRENT_MAIN_BG_COLOR);
lv_style_set_text_color(&style_read_only_value, ESP3D_SCREEN_BACKGROUND_TEXT_COLOR);
lv_style_set_bg_color(&style_read_only_value, ESP3D_SCREEN_BACKGROUND_COLOR);
lv_style_set_radius(&style_read_only_value, CURRENT_STATUS_BAR_RADIUS);
lv_style_set_border_width(&style_read_only_value,
CURRENT_STATUS_BAR_BORDER_VALUE);
Expand All @@ -137,7 +117,7 @@ bool init_styles() {
lv_style_set_text_opa(&style_read_only_setting, LV_OPA_COVER);
lv_style_set_text_color(&style_read_only_setting,
CURRENT_BUTTON_PRESSED_TEXT_COLOR);
lv_style_set_bg_color(&style_read_only_setting, CURRENT_MAIN_BG_COLOR);
lv_style_set_bg_color(&style_read_only_setting, ESP3D_SCREEN_BACKGROUND_COLOR);
lv_style_set_radius(&style_read_only_setting, CURRENT_STATUS_BAR_RADIUS);
lv_style_set_border_width(&style_read_only_setting,
CURRENT_STATUS_BAR_BORDER_VALUE);
Expand Down Expand Up @@ -541,17 +521,17 @@ bool init_styles() {
*/
lv_style_init(&style_simple_container_default);
lv_style_set_bg_opa(&style_simple_container_default, LV_OPA_COVER);
lv_style_set_bg_color(&style_simple_container_default, CURRENT_MAIN_BG_COLOR);
lv_style_set_bg_color(&style_simple_container_default, ESP3D_SCREEN_BACKGROUND_COLOR);

// Text Container
lv_style_init(&style_text_container);
lv_style_set_bg_opa(&style_text_container, LV_OPA_COVER);
lv_style_set_bg_color(&style_text_container, CURRENT_MAIN_BG_COLOR);
lv_style_set_bg_color(&style_text_container, ESP3D_SCREEN_BACKGROUND_COLOR);

return true;
}

bool apply_style(lv_obj_t* obj, ESP3DStyleType type) {
bool apply(lv_obj_t* obj, ESP3DStyleType type) {
if (type != ESP3DStyleType::main_bg && type != ESP3DStyleType::status_list &&
type != ESP3DStyleType::buttons_msgbox &&
type != ESP3DStyleType::message_box &&
Expand Down Expand Up @@ -625,8 +605,8 @@ bool apply_style(lv_obj_t* obj, ESP3DStyleType type) {
break;
case ESP3DStyleType::message_box:
lv_obj_set_width(obj, LV_PCT(80));
apply_style(lv_msgbox_get_close_btn(obj), ESP3DStyleType::button);
apply_style(lv_msgbox_get_btns(obj), ESP3DStyleType::buttons_msgbox);
ESP3DStyle::apply(lv_msgbox_get_close_btn(obj), ESP3DStyleType::button);
ESP3DStyle::apply(lv_msgbox_get_btns(obj), ESP3DStyleType::buttons_msgbox);
lv_obj_set_height(lv_msgbox_get_btns(obj), SYMBOL_BUTTON_HEIGHT);
lv_obj_set_width(lv_msgbox_get_btns(obj), MSGBOX_BUTTON_WIDTH);
break;
Expand All @@ -651,7 +631,7 @@ bool apply_style(lv_obj_t* obj, ESP3DStyleType type) {
LV_PART_MAIN);
break;
case ESP3DStyleType::list_container:
apply_style(obj, ESP3DStyleType::col_container);
ESP3DStyle::apply(obj, ESP3DStyleType::col_container);
lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLL_ELASTIC);
lv_obj_add_flag(obj, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_set_scrollbar_mode(obj, LV_SCROLLBAR_MODE_AUTO);
Expand All @@ -675,7 +655,7 @@ bool apply_style(lv_obj_t* obj, ESP3DStyleType type) {
case ESP3DStyleType::simple_container:
lv_obj_add_style(obj, &style_simple_container_default, LV_STATE_DEFAULT);
lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLLABLE);
apply_outline_pad(obj);
ESP3DStyle::add_pad(obj);
break;
case ESP3DStyleType::status_list:
lv_obj_add_style(obj, &style_status_list_default, LV_STATE_DEFAULT);
Expand All @@ -688,11 +668,12 @@ bool apply_style(lv_obj_t* obj, ESP3DStyleType type) {
return true;
}

bool apply_outline_pad(lv_obj_t* obj) {
bool add_pad(lv_obj_t* obj) {
lv_obj_set_style_pad_left(obj, CURRENT_BUTTON_PRESSED_OUTLINE, LV_PART_MAIN);
lv_obj_set_style_pad_right(obj, CURRENT_BUTTON_PRESSED_OUTLINE, LV_PART_MAIN);
lv_obj_set_style_pad_top(obj, CURRENT_BUTTON_PRESSED_OUTLINE, LV_PART_MAIN);
lv_obj_set_style_pad_bottom(obj, CURRENT_BUTTON_PRESSED_OUTLINE,
LV_PART_MAIN);
return true;
}
}
} // namespace ESP3DStyle
32 changes: 29 additions & 3 deletions main/display/3dprinter/marlin/esp3d_styles.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "esp3d_styles_res.h"
#include "lvgl.h"

//Styles for common controls
enum class ESP3DStyleType : uint8_t {
default_style = 0,
main_bg,
Expand All @@ -48,6 +49,31 @@ enum class ESP3DStyleType : uint8_t {
text_container,
};

extern bool init_styles();
extern bool apply_style(lv_obj_t* obj, ESP3DStyleType type);
extern bool apply_outline_pad(lv_obj_t* obj);
//Name space for styles
namespace ESP3DStyle {
bool init();
bool apply(lv_obj_t* obj, ESP3DStyleType type);
bool add_pad(lv_obj_t* obj);
}; // namespace ESP3DStyle

//Colors definition
//Screen colors
#define ESP3D_SCREEN_BACKGROUND_COLOR lv_color_hex(0x000000)
#define ESP3D_SCREEN_BACKGROUND_TEXT_COLOR lv_color_hex(0xFFFFFF)


#define CURRENT_STATUS_BAR_TEXT_COLOR lv_color_hex(0x000000)
#define CURRENT_STATUS_BAR_BG_COLOR lv_color_hex(0xFFFFFF)
#define CURRENT_STATUS_BAR_BORDER_COLOR lv_palette_main(LV_PALETTE_GREY)

#define CURRENT_BUTTON_COLOR_PALETTE LV_PALETTE_GREY
#define CURRENT_BUTTON_COLOR_PALETTE_DARKEN 2

#define CURRENT_BUTTON_BORDER_COLOR \
lv_color_hex(0xFFFFFF) // lv_palette_main(LV_PALETTE_GREY)
#define CURRENT_BUTTON_TEXT_COLOR lv_color_hex(0xFFFFFF)
#define CURRENT_BUTTON_OUTLINE_COLOR_PALETTE LV_PALETTE_GREEN
#define CURRENT_BUTTON_PRESSED_COLOR_PALETTE LV_PALETTE_GREY
#define CURRENT_BUTTON_PRESSED_TEXT_COLOR lv_color_hex(0x00FF00)
#define CURRENT_BUTTON_PRESSED_BORDER_COLOR lv_color_hex(0x00FF00)

4 changes: 2 additions & 2 deletions main/display/3dprinter/marlin/esp3d_tft_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
**********************/

void create_application(void) {
init_styles();
splashScreen::boot_screen();
ESP3DStyle::init();
splashScreen::enter();
}
2 changes: 0 additions & 2 deletions main/display/3dprinter/marlin/res_320_240/esp3d_styles_res.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,3 @@
#define CURRENT_SCROLL_BAR_WIDTH 10
#define CURRENT_SCROLL_BAR_RADIUS 5

#define FW_LOGO_X 1
#define FW_LOGO_Y -1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
esp3d_styles_splash_screen.h - ESP3D screens styles definition
Copyright (c) 2022 Luc Lebosse. All rights reserved.
This code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#pragma once

#define FW_LOGO_X 1
#define FW_LOGO_Y -1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
esp3d_styles_splash_screen.h - ESP3D screens styles definition
Copyright (c) 2022 Luc Lebosse. All rights reserved.
This code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#pragma once

#define FW_LOGO_X 10
#define FW_LOGO_Y -1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
esp3d_styles_splash_screen.h - ESP3D screens styles definition
Copyright (c) 2022 Luc Lebosse. All rights reserved.
This code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#pragma once

#define FW_LOGO_X 10
#define FW_LOGO_Y -10
5 changes: 1 addition & 4 deletions main/display/3dprinter/marlin/res_800_480/esp3d_styles_res.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,4 @@
#define LIST_LINE_BUTTON_WIDTH 80

#define CURRENT_SCROLL_BAR_WIDTH 10
#define CURRENT_SCROLL_BAR_RADIUS 5

#define FW_LOGO_X 10
#define FW_LOGO_Y -10
#define CURRENT_SCROLL_BAR_RADIUS 5
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
esp3d_styles_splash_screen.h - ESP3D screens styles definition
Copyright (c) 2022 Luc Lebosse. All rights reserved.
This code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#pragma once

#define FW_LOGO_X 10
#define FW_LOGO_Y -10
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ void auto_leveling_screen() {
// Display new screen and delete old one
lv_obj_t *ui_current_screen = lv_scr_act();
lv_scr_load(ui_new_screen);
apply_style(ui_new_screen, ESP3DStyleType::main_bg);
ESP3DStyle::apply(ui_new_screen, ESP3DStyleType::main_bg);
lv_obj_del(ui_current_screen);

homing_done = false;
Expand Down Expand Up @@ -288,7 +288,7 @@ void auto_leveling_screen() {
LV_EVENT_CLICKED, NULL);

label_status = lv_label_create(ui_new_screen);
apply_style(label_status, ESP3DStyleType::bg_label);
ESP3DStyle::apply(label_status, ESP3DStyleType::bg_label);
lv_label_set_text(label_status, "");
lv_obj_align_to(label_status, auto_leveling_screen_table,
LV_ALIGN_OUT_BOTTOM_LEFT, 0, CURRENT_BUTTON_PRESSED_OUTLINE);
Expand Down
Loading

0 comments on commit 3ecfd41

Please sign in to comment.