screen.hpp (4492B)
1 #ifndef SCREEN_H 2 #define SCREEN_H 3 #include "lvgl.h" 4 #include <cstdint> 5 #include <src/core/lv_obj.h> 6 #include <src/core/lv_obj_pos.h> 7 #include <src/core/lv_obj_style.h> 8 #include <src/core/lv_obj_style_gen.h> 9 #include <src/font/lv_font.h> 10 #include <src/layouts/flex/lv_flex.h> 11 #include <src/layouts/grid/lv_grid.h> 12 #include <src/layouts/lv_layout.h> 13 #include <src/misc/lv_area.h> 14 #include <src/misc/lv_color.h> 15 #include <src/misc/lv_style.h> 16 #include <src/misc/lv_style_gen.h> 17 #include <src/widgets/button/lv_button.h> 18 #include <src/widgets/label/lv_label.h> 19 #include <vector> 20 21 //TODO, fix not working makros 22 #define TIMELINE_COLUMN_WIDTH_PCT LV_PCT(20) 23 #define BUTTONS_COLUMN_WIDTH_PCT LV_PCT(24) 24 #define MIDDLE_COLUMN_WIDTH_PCT \ 25 (LV_PCT(100) - TIMELINE_COLUMN_WIDTH_PCT - BUTTONS_COLUMN_WIDTH_PCT) 26 27 28 #define INSTRUCTIONS_ROW_HEIGHT_PCT LV_PCT(28) 29 #define BOTTOM_ROW_HEIGHT_PCT (LV_PCT(100) - INSTRUCTIONS_ROW_HEIGHT_PCT) 30 //End TODO 31 32 33 34 class Screen { 35 private: 36 //int32_t columnDesc[4] = {TIMELINE_COLUMN_WIDTH_PCT, MIDDLE_COLUMN_WIDTH_PCT, BUTTONS_COLUMN_WIDTH_PCT, LV_GRID_TEMPLATE_LAST}; 37 //int32_t rowDesc[3] = {INSTRUCTIONS_ROW_HEIGHT_PCT, BOTTOM_ROW_HEIGHT_PCT, LV_GRID_TEMPLATE_LAST}; 38 39 int32_t columnDesc[4] = {160, 448, 192, LV_GRID_TEMPLATE_LAST}; 40 int32_t rowDesc[3] = {134, 346, LV_GRID_TEMPLATE_LAST}; 41 42 lv_style_t buttonsContainerStyle; 43 44 45 protected: 46 uint16_t width, height; 47 lv_obj_t *screenPointer; 48 lv_obj_t *timelineContainer; 49 lv_obj_t *instructionsContainer; 50 lv_obj_t *buttonsContainer; 51 lv_obj_t *mainContentContainer; 52 53 lv_obj_t *instructionLabel; 54 55 lv_style_t buttonDefaultStyle; 56 lv_style_t buttonLabelDefaultStyle; 57 lv_style_t instructionDefaultStyle; 58 59 public: 60 Screen() 61 { 62 //create default style for buttons 63 lv_style_init(&buttonDefaultStyle); 64 lv_style_set_size(&buttonDefaultStyle, LV_PCT(100), 72); 65 66 //create default style for button labels 67 lv_style_init(&buttonLabelDefaultStyle); 68 lv_style_set_align(&buttonLabelDefaultStyle, LV_ALIGN_CENTER); 69 lv_style_set_text_font(&buttonLabelDefaultStyle, &lv_font_montserrat_16); 70 71 //create default style for the instructions Text 72 lv_style_init(&instructionDefaultStyle); 73 lv_style_set_text_font(&instructionDefaultStyle, &lv_font_montserrat_24); 74 75 76 screenPointer = lv_obj_create(NULL); 77 //lv_obj_set_size(screenPointer, 800, 480); 78 79 //Set the Layout of the screen to Grid 80 lv_obj_set_grid_dsc_array(screenPointer, columnDesc, rowDesc); 81 lv_obj_set_layout(screenPointer, LV_LAYOUT_GRID); 82 83 //set padding to 0 84 lv_obj_set_style_pad_column(screenPointer, 0, 0); 85 lv_obj_set_style_pad_row(screenPointer, 0, 0); 86 87 //Add empty widdgets to the Grid Layout as containers to be filled by child classes 88 timelineContainer = lv_obj_create(screenPointer); 89 lv_obj_set_grid_cell(timelineContainer, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_STRETCH, 0, 2); 90 91 instructionsContainer = lv_obj_create(screenPointer); 92 lv_obj_set_grid_cell(instructionsContainer, LV_GRID_ALIGN_STRETCH, 1, 1, LV_GRID_ALIGN_STRETCH, 0, 1); 93 94 buttonsContainer = lv_obj_create(screenPointer); 95 lv_obj_set_grid_cell(buttonsContainer, LV_GRID_ALIGN_STRETCH, 2, 1, LV_GRID_ALIGN_STRETCH, 0, 2); 96 97 mainContentContainer = lv_obj_create(screenPointer); 98 lv_obj_set_grid_cell(mainContentContainer, LV_GRID_ALIGN_STRETCH, 1, 1, LV_GRID_ALIGN_STRETCH, 1, 1); 99 /*lv_color_t color; 100 color.blue = 0; 101 color.green = 100; 102 color.red = 0; 103 lv_obj_set_style_bg_color(mainContentContainer, color, 0);*/ 104 105 //Add "instructions" label and set style 106 instructionLabel = lv_label_create(instructionsContainer); 107 lv_label_set_text(instructionLabel, "dummytext"); 108 lv_obj_add_style(instructionLabel, &instructionDefaultStyle, 0); 109 110 //set style & flow of buttons container 111 lv_style_init(&buttonsContainerStyle); 112 lv_style_set_flex_flow(&buttonsContainerStyle, LV_FLEX_FLOW_COLUMN_REVERSE); 113 lv_style_set_flex_main_place(&buttonsContainerStyle, LV_FLEX_ALIGN_END); 114 lv_style_set_flex_cross_place(&buttonsContainerStyle, LV_FLEX_ALIGN_CENTER); 115 lv_style_set_layout(&buttonsContainerStyle, LV_LAYOUT_FLEX); 116 lv_style_set_pad_left(&buttonsContainerStyle, 5); 117 lv_style_set_pad_right(&buttonsContainerStyle, 5); 118 119 lv_obj_add_style(buttonsContainer, &buttonsContainerStyle, 0); 120 121 122 123 124 } 125 126 lv_obj_t *getScreen(){ 127 return screenPointer; 128 } 129 }; 130 #endif