Apply the new style system on the applications too

This commit is contained in:
Gabor
2017-04-13 13:34:57 +02:00
parent 6116e83815
commit f431f262be
22 changed files with 361 additions and 438 deletions

View File

@@ -143,11 +143,9 @@ static void my_com_rec(lv_app_inst_t * app_send, lv_app_inst_t * app_rec,
static void my_sc_open(lv_app_inst_t * app, lv_obj_t * sc)
{
my_sc_data_t * sc_data = app->sc_data;
lv_app_style_t * app_style = lv_app_style_get();
sc_data->label = lv_label_create(sc, NULL);
lv_label_set_text(sc_data->label, "Empty");
lv_obj_set_style(sc_data->label, &app_style->sc_txt_style);
lv_obj_align(sc_data->label, NULL, LV_ALIGN_CENTER, 0, 0);
}

View File

@@ -112,7 +112,7 @@ static lv_app_dsc_t my_app_dsc =
.win_data_size = sizeof(my_win_data_t),
};
static lv_labels_t sc_labels;
static lv_style_t style_sc_label;
/**********************
@@ -130,9 +130,8 @@ static lv_labels_t sc_labels;
const lv_app_dsc_t * lv_app_files_init(void)
{
lv_app_style_t * app_style = lv_app_style_get();
memcpy(&sc_labels, &app_style->sc_txt_style, sizeof(lv_labels_t));
sc_labels.font = font_get(LV_APP_FONT_LARGE);
memcpy(&style_sc_label, &app_style->sc_rec_rel, sizeof(lv_style_t));
style_sc_label.font = font_get(LV_APP_FONT_LARGE);
return &my_app_dsc;
}
@@ -219,7 +218,7 @@ static void my_sc_open(lv_app_inst_t * app, lv_obj_t * sc)
sc_data->label = lv_label_create(sc, NULL);
lv_obj_set_style(sc_data->label, &sc_labels);
lv_obj_set_style(sc_data->label, &style_sc_label);
lv_label_set_text(sc_data->label, fs_get_last(app_data->path));
lv_obj_align(sc_data->label, NULL, LV_ALIGN_CENTER, 0, 0);
}
@@ -298,10 +297,10 @@ static void my_conf_open(lv_app_inst_t * app, lv_obj_t * conf_win)
if(app_data->send_crc != 0) lv_btn_set_state(cb, LV_BTN_STATE_TREL);
else lv_btn_set_state(cb, LV_BTN_STATE_REL);
/*Create a text area the type chunk size*/
/*Create a text area to type chunk size*/
lv_obj_t * val_set_h;
val_set_h = lv_rect_create(conf_win, NULL);
lv_obj_set_style(val_set_h, lv_rects_get(LV_RECTS_TRANSP, NULL));
lv_obj_set_style(val_set_h, lv_style_get(LV_STYLE_PLAIN_COLOR, NULL));
lv_obj_set_click(val_set_h, false);
lv_rect_set_fit(val_set_h, true, true);
lv_rect_set_layout(val_set_h, LV_RECT_LAYOUT_ROW_M);
@@ -313,7 +312,6 @@ static void my_conf_open(lv_app_inst_t * app, lv_obj_t * conf_win)
lv_obj_t * ta;
char buf[32];
ta = lv_ta_create(val_set_h, NULL);
lv_obj_set_style(ta, lv_tas_get(LV_TAS_DEF, NULL));
lv_rect_set_fit(ta, false, true);
lv_obj_set_free_num(ta, SEND_SETTINGS_CHUNK_SIZE);
lv_obj_set_free_p(ta, app);
@@ -342,7 +340,6 @@ static void my_conf_open(lv_app_inst_t * app, lv_obj_t * conf_win)
*/
static void win_create_list(lv_app_inst_t * app)
{
lv_app_style_t * app_style = lv_app_style_get();
my_win_data_t * win_data = app->win_data;
/*Delete the previous list*/
@@ -352,8 +349,8 @@ static void win_create_list(lv_app_inst_t * app)
/*Create a new list*/
win_data->file_list = lv_list_create(app->win, NULL);
lv_obj_set_width(win_data->file_list, app_style->win_useful_w);
lv_obj_set_style(win_data->file_list, lv_lists_get(LV_LISTS_TRANSP, NULL));
lv_obj_set_width(win_data->file_list, lv_win_get_width(app->win));
//TODO lv_obj_set_style(win_data->file_list, lv_lists_get(LV_LISTS_TRANSP, NULL));
lv_obj_set_drag_parent(win_data->file_list, true);
lv_obj_set_drag_parent(lv_page_get_scrl(win_data->file_list), true);
lv_rect_set_fit(win_data->file_list, false, true);

View File

@@ -36,8 +36,8 @@ typedef struct
typedef struct
{
lv_obj_t * chart;
cord_t * cpu_dl;
cord_t * mem_dl;
lv_chart_dl_t * cpu_dl;
lv_chart_dl_t * mem_dl;
lv_obj_t * label;
}my_win_data_t;
@@ -83,8 +83,8 @@ static lv_app_dsc_t my_app_dsc =
static uint8_t mem_pct[LV_APP_SYSMON_PNUM];
static uint8_t cpu_pct[LV_APP_SYSMON_PNUM];
static lv_bars_t cpu_bars;
static lv_bars_t mem_bars;
static lv_style_t cpu_bars;
static lv_style_t mem_bars;
#if USE_DYN_MEM != 0 && DM_CUSTOM == 0
static dm_mon_t mem_mon;
#endif
@@ -109,30 +109,21 @@ const lv_app_dsc_t * lv_app_sysmon_init(void)
memset(cpu_pct, 0, sizeof(cpu_pct));
/*Create bar styles for the shortcut*/
lv_bars_get(LV_BARS_DEF, &cpu_bars);
cpu_bars.bg.gcolor = COLOR_MAKE(0xFF, 0xE0, 0xE0);
cpu_bars.bg.base.color = COLOR_MAKE(0xFF, 0xD0, 0xD0);
cpu_bars.bg.bcolor = COLOR_MAKE(0xFF, 0x20, 0x20);
cpu_bars.bg.bwidth = 1 * LV_DOWNSCALE;
lv_style_get(LV_STYLE_PRETTY_COLOR, &cpu_bars);
cpu_bars.indic.gcolor = COLOR_MARRON;
cpu_bars.indic.base.color = COLOR_RED;
cpu_bars.indic.bwidth = 0;
cpu_bars.gcolor = COLOR_MARRON;
cpu_bars.mcolor = COLOR_RED;
cpu_bars.bwidth = 0;
cpu_bars.label.base.color = COLOR_MAKE(0x40, 0x00, 0x00);
cpu_bars.label.font = font_get(LV_APP_FONT_MEDIUM);
cpu_bars.label.line_space = 0;
cpu_bars.label.mid = 1;
cpu_bars.ccolor = COLOR_MAKE(0x40, 0x00, 0x00);
cpu_bars.font = font_get(LV_APP_FONT_MEDIUM);
cpu_bars.line_space = 0;
cpu_bars.txt_align = 1;
memcpy(&mem_bars, &cpu_bars, sizeof(cpu_bars));
mem_bars.bg.gcolor = COLOR_MAKE(0xD0, 0xFF, 0xD0);
mem_bars.bg.base.color = COLOR_MAKE(0xE0, 0xFF, 0xE0);
mem_bars.bg.bcolor = COLOR_MAKE(0x20, 0xFF, 0x20);
mem_bars.indic.gcolor = COLOR_GREEN;
mem_bars.indic.base.color = COLOR_LIME;
mem_bars.label.base.color = COLOR_MAKE(0x00, 0x40, 0x00);
mem_bars.gcolor = COLOR_GREEN;
mem_bars.mcolor = COLOR_LIME;
mem_bars.ccolor = COLOR_MAKE(0x00, 0x40, 0x00);
return &my_app_dsc;
}
@@ -193,14 +184,14 @@ static void my_sc_open(lv_app_inst_t * app, lv_obj_t * sc)
sc_data->bar_cpu = lv_bar_create(sc, NULL);
lv_obj_set_size(sc_data->bar_cpu, w, 5 * lv_obj_get_height(sc) / 8);
lv_obj_align(sc_data->bar_cpu, NULL, LV_ALIGN_IN_BOTTOM_LEFT, w, - lv_obj_get_height(sc) / 8);
lv_obj_set_style(sc_data->bar_cpu, &cpu_bars);
lv_bar_set_style_indic(sc_data->bar_cpu, &cpu_bars);
lv_obj_set_click(sc_data->bar_cpu, false);
lv_bar_set_range(sc_data->bar_cpu, 0, 100);
lv_bar_set_format_str(sc_data->bar_cpu, "C\nP\nU");
sc_data->bar_mem = lv_bar_create(sc, sc_data->bar_cpu);
lv_obj_align(sc_data->bar_mem, sc_data->bar_cpu, LV_ALIGN_OUT_RIGHT_MID, w, 0);
lv_obj_set_style(sc_data->bar_mem, &mem_bars);
lv_bar_set_style_indic(sc_data->bar_mem, &mem_bars);
lv_bar_set_format_str(sc_data->bar_mem, "M\ne\nm");
lv_app_sysmon_refr();
@@ -225,7 +216,6 @@ static void my_sc_close(lv_app_inst_t * app)
static void my_win_open(lv_app_inst_t * app, lv_obj_t * win)
{
my_win_data_t * win_data = app->win_data;
lv_app_style_t * app_style = lv_app_style_get();
/*Create a chart with two data lines*/
win_data->chart = lv_chart_create(win, NULL);
@@ -235,21 +225,19 @@ static void my_win_open(lv_app_inst_t * app, lv_obj_t * win)
lv_chart_set_range(win_data->chart, 0, 100);
lv_chart_set_type(win_data->chart, LV_CHART_LINE);
win_data->cpu_dl = lv_chart_add_dataline(win_data->chart);
win_data->mem_dl = lv_chart_add_dataline(win_data->chart);
win_data->cpu_dl = lv_chart_add_dataline(win_data->chart, COLOR_RED, 2 * LV_DOWNSCALE);
win_data->mem_dl = lv_chart_add_dataline(win_data->chart, COLOR_BLUE, 2 * LV_DOWNSCALE);
uint16_t i;
for(i = 0; i < LV_APP_SYSMON_PNUM; i ++) {
win_data->cpu_dl[i] = cpu_pct[i];
win_data->mem_dl[i] = mem_pct[i];
win_data->cpu_dl->points[i] = cpu_pct[i];
win_data->mem_dl->points[i] = mem_pct[i];
}
/*Create a label for the details of Memory and CPU usage*/
cord_t opad = app_style->win.page.scrl.opad;
win_data->label = lv_label_create(win, NULL);
lv_label_set_recolor(win_data->label, true);
lv_obj_align(win_data->label, win_data->chart, LV_ALIGN_OUT_RIGHT_MID, opad, 0);
lv_obj_set_style(win_data->label, &app_style->win_txt_style);
lv_obj_align(win_data->label, win_data->chart, LV_ALIGN_OUT_RIGHT_MID, LV_DPI / 4, 0);
lv_app_sysmon_refr();
@@ -317,7 +305,7 @@ static void sysmon_task(void * param)
if(mem_mon.size_free < LV_APP_SYSMON_MEM_WARN && mem_warn_report == false) {
mem_warn_report = true;
lv_obj_t * not = lv_app_notice_add("Critically low memory");
lv_obj_set_style(not, lv_mboxs_get(LV_MBOXS_WARN, NULL));
//TODO lv_obj_set_style(not, lv_mboxs_get(LV_MBOXS_WARN, NULL));
}
if(mem_mon.size_free > LV_APP_SYSMON_MEM_WARN) mem_warn_report = false;
@@ -327,7 +315,7 @@ static void sysmon_task(void * param)
if(frag_warn_report == false) {
frag_warn_report = true;
lv_obj_t * not =lv_app_notice_add("Critical memory\nfragmentation");
lv_obj_set_style(not, lv_mboxs_get(LV_MBOXS_WARN, NULL));
//TODO lv_obj_set_style(not, lv_mboxs_get(LV_MBOXS_WARN, NULL));
dm_defrag(); /*Defrag. if the fragmentation is critical*/
}
@@ -369,8 +357,6 @@ static void lv_app_sysmon_refr(void)
sprintf(buf_long, "%s%c%s MEMORY: N/A%c", buf_long, TXT_RECOLOR_CMD, MEM_LABEL_COLOR, TXT_RECOLOR_CMD);
sprintf(buf_short, "%sMem: N/A\nFrag: N/A", buf_short);
#endif
lv_app_style_t * app_style = lv_app_style_get();
cord_t opad = app_style->win.page.scrl.opad;
lv_app_inst_t * app;
app = lv_app_get_next(NULL, &my_app_dsc);
while(app != NULL) {
@@ -378,7 +364,7 @@ static void lv_app_sysmon_refr(void)
my_win_data_t * win_data = app->win_data;
if(win_data != NULL) {
lv_label_set_text(win_data->label, buf_long);
lv_obj_align(win_data->label, win_data->chart, LV_ALIGN_OUT_RIGHT_TOP, opad, 0);
lv_chart_set_next(win_data->chart, win_data->mem_dl, mem_pct[LV_APP_SYSMON_PNUM - 1]);
lv_chart_set_next(win_data->chart, win_data->cpu_dl, cpu_pct[LV_APP_SYSMON_PNUM - 1]);

View File

@@ -31,6 +31,7 @@
/*********************
* DEFINES
*********************/
#define OBJ_PAD (LV_DPI / 4)
/**********************
* TYPEDEFS
@@ -99,11 +100,10 @@ static lv_app_dsc_t my_app_dsc =
.win_data_size = sizeof(my_win_data_t),
};
const char * com_type_list_txt[] = {"Character", "Integer", "Log", "None", ""};
lv_app_com_type_t com_type_list[] = {LV_APP_COM_TYPE_CHAR, LV_APP_COM_TYPE_INT, LV_APP_COM_TYPE_LOG, LV_APP_COM_TYPE_INV};
const char * txt_format_list_txt[] = {"ASCII", "Hexadecimal", ""};
lv_objs_t sc_txt_bgs;
lv_labels_t sc_txts;
static const char * com_type_list_txt[] = {"Character", "Integer", "Log", "None", ""};
static lv_app_com_type_t com_type_list[] = {LV_APP_COM_TYPE_CHAR, LV_APP_COM_TYPE_INT, LV_APP_COM_TYPE_LOG, LV_APP_COM_TYPE_INV};
static const char * txt_format_list_txt[] = {"ASCII", "Hexadecimal", ""};
static lv_style_t style_sc_term;
/**********************
* MACROS
@@ -119,17 +119,13 @@ lv_labels_t sc_txts;
*/
const lv_app_dsc_t * lv_app_terminal_init(void)
{
lv_app_style_t * app_style = lv_app_style_get();
memcpy(&sc_txts, &app_style->sc_txt_style, sizeof(lv_labels_t));
sc_txts.line_space = 0;
sc_txts.letter_space = 0;
sc_txts.mid = 0;
sc_txts.base.color = COLOR_WHITE;
lv_objs_get(LV_OBJS_PLAIN, &sc_txt_bgs);
sc_txt_bgs.color = COLOR_MAKE(0x20, 0x20, 0x20);
lv_style_get(LV_STYLE_PLAIN, &style_sc_term);
style_sc_term.line_space = 0;
style_sc_term.letter_space = 0;
style_sc_term.txt_align = 0;
style_sc_term.ccolor = COLOR_WHITE;
style_sc_term.mcolor = COLOR_MAKE(0x20, 0x20, 0x20);
style_sc_term.gcolor = COLOR_MAKE(0x20, 0x20, 0x20);
return &my_app_dsc;
}
@@ -218,13 +214,12 @@ static void my_sc_open(lv_app_inst_t * app, lv_obj_t * sc)
/*Create a dark background*/
lv_obj_t * txt_bg = lv_obj_create(sc, NULL);
lv_obj_set_size(txt_bg, 7 * LV_APP_SC_WIDTH / 8 , app->sc->cords.y2 - app->sc_title->cords.y2 - 10 * LV_DOWNSCALE);
lv_obj_set_style(txt_bg, &sc_txt_bgs);
lv_obj_set_style(txt_bg, &style_sc_term);
lv_obj_align(txt_bg, app->sc_title, LV_ALIGN_OUT_BOTTOM_MID, 0, 3 * LV_DOWNSCALE);
lv_obj_set_click(txt_bg, false);
/*Add a text with the text of the terminal*/
sc_data->label = lv_label_create(txt_bg, NULL);
lv_obj_set_style(sc_data->label, &sc_txts);
lv_label_set_long_mode(sc_data->label, LV_LABEL_LONG_BREAK);
lv_obj_set_width(sc_data->label, lv_obj_get_width(txt_bg) - LV_APP_SC_WIDTH / 8);
lv_label_set_text_static(sc_data->label, app_data->txt);
@@ -250,18 +245,11 @@ static void my_win_open(lv_app_inst_t * app, lv_obj_t * win)
{
my_win_data_t * win_data = app->win_data;
my_app_data_t * app_data = app->app_data;
lv_app_style_t * app_style = lv_app_style_get();
cord_t opad = app_style->win.page.scrl.opad;
/*Create a label for the text of the terminal*/
win_data->label = lv_label_create(win, NULL);
lv_label_set_long_mode(win_data->label, LV_LABEL_LONG_BREAK);
lv_obj_set_width(win_data->label, LV_HOR_RES -
2 * (app_style->win.page.bg.hpad +
app_style->win.page.scrl.hpad));
lv_obj_set_style(win_data->label, &app_style->win_txt_style);
lv_obj_set_width(win_data->label, lv_win_get_width(win));
lv_label_set_text_static(win_data->label, app_data->txt); /*Use the app. data text directly*/
/*Create a text area. Text can be added to the terminal from here by app. keyboard.*/
@@ -270,9 +258,8 @@ static void my_win_open(lv_app_inst_t * app, lv_obj_t * win)
lv_obj_set_free_p(win_data->ta, app);
lv_page_set_rel_action(win_data->ta, win_ta_rel_action);
lv_ta_set_text(win_data->ta, "");
lv_obj_set_style(win_data->ta, lv_tas_get(LV_TAS_DEF, NULL));
if(app_data->txt[0] != '\0') lv_obj_align(win_data->ta, win_data->label, LV_ALIGN_OUT_BOTTOM_LEFT, opad, opad);
else lv_obj_align(win_data->ta, NULL, LV_ALIGN_IN_TOP_LEFT, opad, opad);
if(app_data->txt[0] != '\0') lv_obj_align(win_data->ta, win_data->label, LV_ALIGN_OUT_BOTTOM_LEFT, OBJ_PAD, OBJ_PAD);
else lv_obj_align(win_data->ta, NULL, LV_ALIGN_IN_TOP_LEFT, OBJ_PAD, OBJ_PAD);
/*Create a clear button*/
win_data->clear_btn = lv_btn_create(win, NULL);
@@ -280,13 +267,12 @@ static void my_win_open(lv_app_inst_t * app, lv_obj_t * win)
lv_obj_set_free_p(win_data->clear_btn, app);
lv_btn_set_rel_action(win_data->clear_btn, win_clear_rel_action);
lv_obj_t * btn_label = lv_label_create(win_data->clear_btn, NULL);
lv_obj_set_style(btn_label, lv_labels_get(LV_LABELS_BTN, NULL));
lv_label_set_text(btn_label, "Clear");
lv_obj_align(win_data->clear_btn, win_data->ta, LV_ALIGN_OUT_RIGHT_TOP, opad, 0);
lv_obj_align(win_data->clear_btn, win_data->ta, LV_ALIGN_OUT_RIGHT_TOP, OBJ_PAD, 0);
/*Align the window to see the text area on the bottom*/
lv_obj_align(lv_page_get_scrl(app->win), NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0,
- app_style->win.page.scrl.vpad);
lv_obj_t * page = lv_win_get_page(app->win);
lv_obj_align(lv_page_get_scrl(page), NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, - LV_VER_RES);
}
@@ -308,12 +294,10 @@ static void my_win_close(lv_app_inst_t * app)
static void my_conf_open(lv_app_inst_t * app, lv_obj_t * conf_win)
{
my_app_data_t * app_data = app->app_data;
lv_app_style_t * app_style = lv_app_style_get();
lv_obj_t * label;
label = lv_label_create(conf_win, NULL);
lv_label_set_text(label, "Communication type");
lv_obj_set_style(label, &app_style->win_txt_style);
lv_obj_t * ddl;
ddl = lv_ddlist_create(conf_win, NULL);
@@ -405,13 +389,11 @@ static lv_action_res_t win_clear_rel_action(lv_obj_t * btn, lv_dispi_t * dispi)
}
if(win_data != NULL) {
lv_app_style_t * app_style =lv_app_style_get();
cord_t opad = app_style->win.page.scrl.opad;
lv_label_set_text_static(win_data->label, app_data->txt);
lv_obj_align(win_data->ta, NULL, LV_ALIGN_IN_TOP_LEFT, opad, opad);
lv_obj_align(win_data->clear_btn, win_data->ta, LV_ALIGN_OUT_RIGHT_TOP, opad, 0);
lv_obj_align(lv_page_get_scrl(app->win), NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0,
- app_style->win.page.scrl.vpad);
lv_obj_align(win_data->ta, NULL, LV_ALIGN_IN_TOP_LEFT, OBJ_PAD, OBJ_PAD);
lv_obj_align(win_data->clear_btn, win_data->ta, LV_ALIGN_OUT_RIGHT_TOP, OBJ_PAD, 0);
lv_obj_t * page = lv_win_get_page(app->win);
lv_obj_align(lv_page_get_scrl(page), NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, - LV_VER_RES);
}
return LV_ACTION_RES_OK;
@@ -489,15 +471,13 @@ static void add_data(lv_app_inst_t * app, const void * data, uint16_t data_len)
my_win_data_t * win_data = app->win_data;
my_sc_data_t * sc_data = app->sc_data;
lv_app_style_t * app_style = lv_app_style_get();
if(win_data != NULL) {
cord_t opad = app_style->win.page.scrl.opad;
lv_label_set_text_static(win_data->label, app_data->txt);
lv_obj_align(win_data->ta, win_data->label, LV_ALIGN_OUT_BOTTOM_LEFT, opad, opad);
lv_obj_align(win_data->clear_btn, win_data->ta, LV_ALIGN_OUT_RIGHT_TOP, opad, 0);
lv_obj_align(lv_page_get_scrl(app->win), NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0,
- app_style->win.page.scrl.vpad);
lv_obj_align(win_data->ta, win_data->label, LV_ALIGN_OUT_BOTTOM_LEFT, OBJ_PAD, OBJ_PAD);
lv_obj_align(win_data->clear_btn, win_data->ta, LV_ALIGN_OUT_RIGHT_TOP, OBJ_PAD, 0);
lv_obj_t * page = lv_win_get_page(app->win);
lv_obj_align(lv_page_get_scrl(page), NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, - LV_VER_RES);
}
/*Set the last line on the shortcut*/

View File

@@ -139,11 +139,9 @@ static void my_com_rec(lv_app_inst_t * app_send, lv_app_inst_t * app_rec,
static void my_sc_open(lv_app_inst_t * app, lv_obj_t * sc)
{
my_sc_data_t * sc_data = app->sc_data;
lv_app_style_t * app_style = lv_app_style_get();
sc_data->label = lv_label_create(sc, NULL);
lv_label_set_text(sc_data->label, "Empty");
lv_obj_set_style(sc_data->label, &app_style->sc_txt_style);
lv_obj_align(sc_data->label, NULL, LV_ALIGN_CENTER, 0, 0);
}