From c4f3838b1e973df71fc7d77602127b16c137796b Mon Sep 17 00:00:00 2001 From: Gabor Date: Tue, 11 Apr 2017 10:50:57 +0200 Subject: [PATCH] further renames --- lv_app/lv_app_util/lv_app_kb.c | 2 +- lv_appx/lv_app_sysmon.c | 76 +++--- lv_obj/lv_obj.h | 7 +- lv_objx/lv_bar.c | 320 ++++++++++++++++++++++++ lv_objx/{lv_pb.h => lv_bar.h} | 68 +++--- lv_objx/lv_btn.h | 19 +- lv_objx/lv_btnm.c | 18 +- lv_objx/lv_btnm.h | 12 +- lv_objx/lv_cb.h | 14 +- lv_objx/lv_chart.c | 8 +- lv_objx/lv_chart.h | 2 +- lv_objx/lv_ddlist.h | 14 +- lv_objx/lv_gauge.c | 88 +++---- lv_objx/lv_gauge.h | 20 +- lv_objx/lv_img.h | 16 +- lv_objx/lv_label.c | 2 +- lv_objx/lv_label.h | 20 +- lv_objx/lv_led.c | 63 ++--- lv_objx/lv_led.h | 11 +- lv_objx/lv_list.c | 2 +- lv_objx/lv_list.h | 6 +- lv_objx/lv_mbox.h | 2 +- lv_objx/lv_page.h | 14 +- lv_objx/lv_pb.c | 431 --------------------------------- lv_objx/lv_rect.c | 29 ++- lv_objx/lv_rect.h | 8 +- lv_objx/lv_ta.c | 11 +- lv_objx/lv_ta.h | 6 +- lvgl.h | 3 +- 29 files changed, 580 insertions(+), 712 deletions(-) create mode 100644 lv_objx/lv_bar.c rename lv_objx/{lv_pb.h => lv_bar.h} (52%) delete mode 100644 lv_objx/lv_pb.c diff --git a/lv_app/lv_app_util/lv_app_kb.c b/lv_app/lv_app_util/lv_app_kb.c index 6a2c8dfa7..90be28aff 100644 --- a/lv_app/lv_app_util/lv_app_kb.c +++ b/lv_app/lv_app_util/lv_app_kb.c @@ -116,7 +116,7 @@ void lv_app_kb_open(lv_obj_t * ta, lv_app_kb_mode_t mode, void (*close)(lv_obj_t kb_btnm = lv_btnm_create(lv_scr_act(), NULL); lv_obj_set_size(kb_btnm, LV_HOR_RES, LV_VER_RES / 2); lv_obj_align(kb_btnm, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0); - lv_btnm_set_cb(kb_btnm, lv_app_kb_action); + lv_btnm_set_action(kb_btnm, lv_app_kb_action); if(mode & LV_APP_KB_MODE_TXT) { kb_btnms.label.font = font_get(LV_APP_FONT_MEDIUM); lv_btnm_set_map(kb_btnm, kb_map_lc); diff --git a/lv_appx/lv_app_sysmon.c b/lv_appx/lv_app_sysmon.c index 8cd4fe341..deb12b63a 100644 --- a/lv_appx/lv_app_sysmon.c +++ b/lv_appx/lv_app_sysmon.c @@ -44,8 +44,8 @@ typedef struct /*Application specific data for a shortcut of this application*/ typedef struct { - lv_obj_t * pb_cpu; - lv_obj_t * pb_mem; + lv_obj_t * bar_cpu; + lv_obj_t * bar_mem; }my_sc_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_pbs_t cpu_pbs; -static lv_pbs_t mem_pbs; +static lv_bars_t cpu_bars; +static lv_bars_t mem_bars; #if USE_DYN_MEM != 0 && DM_CUSTOM == 0 static dm_mon_t mem_mon; #endif @@ -108,31 +108,31 @@ const lv_app_dsc_t * lv_app_sysmon_init(void) memset(mem_pct, 0, sizeof(mem_pct)); memset(cpu_pct, 0, sizeof(cpu_pct)); - /*Create progress bar styles for the shortcut*/ - lv_pbs_get(LV_PBS_DEF, &cpu_pbs); - cpu_pbs.bg.gcolor = COLOR_MAKE(0xFF, 0xE0, 0xE0); - cpu_pbs.bg.base.color = COLOR_MAKE(0xFF, 0xD0, 0xD0); - cpu_pbs.bg.bcolor = COLOR_MAKE(0xFF, 0x20, 0x20); - cpu_pbs.bg.bwidth = 1 * LV_DOWNSCALE; + /*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; - cpu_pbs.bar.gcolor = COLOR_MARRON; - cpu_pbs.bar.base.color = COLOR_RED; - cpu_pbs.bar.bwidth = 0; + cpu_bars.indic.gcolor = COLOR_MARRON; + cpu_bars.indic.base.color = COLOR_RED; + cpu_bars.indic.bwidth = 0; - cpu_pbs.label.base.color = COLOR_MAKE(0x40, 0x00, 0x00); - cpu_pbs.label.font = font_get(LV_APP_FONT_MEDIUM); - cpu_pbs.label.line_space = 0; - cpu_pbs.label.mid = 1; + 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; - memcpy(&mem_pbs, &cpu_pbs, sizeof(mem_pbs)); - mem_pbs.bg.gcolor = COLOR_MAKE(0xD0, 0xFF, 0xD0); - mem_pbs.bg.base.color = COLOR_MAKE(0xE0, 0xFF, 0xE0); - mem_pbs.bg.bcolor = COLOR_MAKE(0x20, 0xFF, 0x20); + 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_pbs.bar.gcolor = COLOR_GREEN; - mem_pbs.bar.base.color = COLOR_LIME; + mem_bars.indic.gcolor = COLOR_GREEN; + mem_bars.indic.base.color = COLOR_LIME; - mem_pbs.label.base.color = COLOR_MAKE(0x00, 0x40, 0x00); + mem_bars.label.base.color = COLOR_MAKE(0x00, 0x40, 0x00); return &my_app_dsc; } @@ -189,19 +189,19 @@ static void my_sc_open(lv_app_inst_t * app, lv_obj_t * sc) cord_t w = lv_obj_get_width(sc) / 5; - /*Create 2 progress bars fr the CPU and the Memory*/ - sc_data->pb_cpu = lv_pb_create(sc, NULL); - lv_obj_set_size(sc_data->pb_cpu, w, 5 * lv_obj_get_height(sc) / 8); - lv_obj_align(sc_data->pb_cpu, NULL, LV_ALIGN_IN_BOTTOM_LEFT, w, - lv_obj_get_height(sc) / 8); - lv_obj_set_style(sc_data->pb_cpu, &cpu_pbs); - lv_obj_set_click(sc_data->pb_cpu, false); - lv_pb_set_min_max_value(sc_data->pb_cpu, 0, 100); - lv_pb_set_format_str(sc_data->pb_cpu, "C\nP\nU"); + /*Create 2 bars for the CPU and the Memory*/ + 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_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->pb_mem = lv_pb_create(sc, sc_data->pb_cpu); - lv_obj_align(sc_data->pb_mem, sc_data->pb_cpu, LV_ALIGN_OUT_RIGHT_MID, w, 0); - lv_obj_set_style(sc_data->pb_mem, &mem_pbs); - lv_pb_set_format_str(sc_data->pb_mem, "M\ne\nm"); + 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_format_str(sc_data->bar_mem, "M\ne\nm"); lv_app_sysmon_refr(); } @@ -387,8 +387,8 @@ static void lv_app_sysmon_refr(void) /*Refresh the shortcut*/ my_sc_data_t * sc_data = app->sc_data; if(sc_data != NULL) { - lv_pb_set_value(sc_data->pb_cpu, cpu_pct[LV_APP_SYSMON_PNUM - 1]); - lv_pb_set_value(sc_data->pb_mem, mem_pct[LV_APP_SYSMON_PNUM - 1]); + lv_bar_set_value(sc_data->bar_cpu, cpu_pct[LV_APP_SYSMON_PNUM - 1]); + lv_bar_set_value(sc_data->bar_mem, mem_pct[LV_APP_SYSMON_PNUM - 1]); } lv_app_com_send(app, LV_APP_COM_TYPE_CHAR, buf_short, strlen(buf_short)); diff --git a/lv_obj/lv_obj.h b/lv_obj/lv_obj.h index 47d3aa05d..0606fe7ea 100644 --- a/lv_obj/lv_obj.h +++ b/lv_obj/lv_obj.h @@ -105,7 +105,9 @@ typedef struct __LV_OBJ_T cord_t ext_size; /*EXTtend the size of the object in every direction. Used to draw shadow, shine etc.*/ +#if LV_OBJ_FREE_NUM != 0 uint8_t free_num; /*Application specific identifier (set it freely)*/ +#endif }lv_obj_t; /*Protect some attributes (max. 8 bit)*/ @@ -113,9 +115,8 @@ typedef enum { LV_PROTECT_NONE = 0x00, LV_PROTECT_CHILD_CHG = 0x01, /*Disable the child change signal. Used by the library*/ - LV_PROTECT_OPA = 0x02, /*Prevent lv_obj_set_opar to modify the opacity*/ - LV_PROTECT_PARENT = 0x04, /*Prevent automatic parent change (e.g. in lv_page)*/ - LV_PROTECT_POS = 0x08, /*Prevent automatic positioning (e.g. in lv_rect layout)*/ + LV_PROTECT_PARENT = 0x02, /*Prevent automatic parent change (e.g. in lv_page)*/ + LV_PROTECT_POS = 0x04, /*Prevent automatic positioning (e.g. in lv_rect layout)*/ }lv_protect_t; typedef enum diff --git a/lv_objx/lv_bar.c b/lv_objx/lv_bar.c new file mode 100644 index 000000000..f492ad202 --- /dev/null +++ b/lv_objx/lv_bar.c @@ -0,0 +1,320 @@ + + +/** + * @file lv_bar.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_conf.h" +#if USE_LV_BAR != 0 + +#include +#include "../lv_draw/lv_draw.h" +#include + +/********************* + * DEFINES + *********************/ +#define LV_BAR_TXT_MAX_LENGTH 64 +#define LV_BAR_DEF_FORMAT "%d %%" +#define LV_BAR_DEF_WIDTH (LV_DPI * 2) +#define LV_BAR_DEF_HEIGHT (LV_DPI / 2) + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static bool lv_bar_design(lv_obj_t * bar, const area_t * mask, lv_design_mode_t mode); +static void lv_bars_init(void); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_bars_t lv_bars_def; +static lv_design_f_t ancestor_design_f; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/*----------------- + * Create function + *-----------------*/ + +/** + * Create a bar objects + * @param par pointer to an object, it will be the parent of the new bar + * @param copy pointer to a bar object, if not NULL then the new object will be copied from it + * @return pointer to the created bar + */ +lv_obj_t * lv_bar_create(lv_obj_t * par, lv_obj_t * copy) +{ + /*Create the ancestor basic object*/ + lv_obj_t * new_bar = lv_rect_create(par, copy); + dm_assert(new_bar); + + /*Allocate the object type specific extended data*/ + lv_bar_ext_t * ext = lv_obj_alloc_ext(new_bar, sizeof(lv_bar_ext_t)); + dm_assert(ext); + ext->min_value = 0; + ext->max_value = 100; + ext->act_value = 0; + ext->format_str = NULL; + ext->label = NULL; + + /* Save the rectangle design function. + * It will be used in the bar design function*/ + if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_f(new_bar); + + lv_obj_set_signal_f(new_bar, lv_bar_signal); + lv_obj_set_design_f(new_bar, lv_bar_design); + + /*Init the new bar object*/ + if(copy == NULL) { + ext->format_str = dm_alloc(strlen(LV_BAR_DEF_FORMAT) + 1); + strcpy(ext->format_str, LV_BAR_DEF_FORMAT); + + ext->label = lv_label_create(new_bar, NULL); + + lv_rect_set_layout(new_bar, LV_RECT_LAYOUT_CENTER); + lv_obj_set_click(new_bar, false); + lv_obj_set_size(new_bar, LV_BAR_DEF_WIDTH, LV_BAR_DEF_HEIGHT); + lv_obj_set_style(new_bar, lv_bars_get(LV_BARS_DEF, NULL)); + + lv_bar_set_value(new_bar, ext->act_value); + } else { + lv_bar_ext_t * ext_copy = lv_obj_get_ext(copy); + ext->format_str = dm_alloc(strlen(ext_copy->format_str) + 1); + strcpy(ext->format_str, ext_copy->format_str); + ext->min_value = ext_copy->min_value; + ext->max_value = ext_copy->max_value; + ext->act_value = ext_copy->act_value; + ext->label = lv_label_create(new_bar, ext_copy->label); + + /*Refresh the style with new signal function*/ + lv_obj_refr_style(new_bar); + + lv_bar_set_value(new_bar, ext->act_value); + + } + return new_bar; +} + +/** + * Signal function of the bar + * @param bar pointer to a bar object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + */ +bool lv_bar_signal(lv_obj_t * bar, lv_signal_t sign, void * param) +{ + bool valid; + + /* Include the ancient signal function */ + valid = lv_rect_signal(bar, sign, param); + + /* The object can be deleted so check its validity and then + * make the object specific signal handling */ + if(valid != false) { + lv_bar_ext_t * ext = lv_obj_get_ext(bar); + lv_bars_t * style = lv_obj_get_style(bar); + point_t p; + char buf[LV_BAR_TXT_MAX_LENGTH]; + + switch(sign) { + case LV_SIGNAL_CLEANUP: + dm_free(ext->format_str); + ext->format_str = NULL; + break; + case LV_SIGNAL_STYLE_CHG: + lv_obj_set_style(ext->label, &style->label); + lv_bar_set_value(bar, lv_bar_get_value(bar)); + break; + default: + break; + } + } + + return valid; +} + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a new value on the bar + * @param bar pointer to a bar object + * @param value new value + */ +void lv_bar_set_value(lv_obj_t * bar, int16_t value) +{ + lv_bar_ext_t * ext = lv_obj_get_ext(bar); + ext->act_value = value > ext->max_value ? ext->max_value : value; + ext->act_value = ext->act_value < ext->min_value ? ext->min_value : ext->act_value; + + char buf[LV_BAR_TXT_MAX_LENGTH]; + sprintf(buf, ext->format_str, ext->act_value); + lv_label_set_text(ext->label, buf); + + lv_obj_inv(bar); +} + +/** + * Set minimum and the maximum values of a bar + * @param bar pointer to he bar object + * @param min minimum value + * @param max maximum value + */ +void lv_bar_set_range(lv_obj_t * bar, int16_t min, int16_t max) +{ + lv_bar_ext_t * ext = lv_obj_get_ext(bar); + ext->max_value = max; + ext->max_value = max; + if(ext->act_value > max) { + ext->act_value = max; + lv_bar_set_value(bar, ext->act_value); + } + lv_obj_inv(bar); +} + +/** + * Set format string for the label of the bar + * @param bar pointer to bar object + * @param format a printf-like format string with one number (e.g. "Loading (%d)") + */ +void lv_bar_set_format_str(lv_obj_t * bar, const char * format) +{ + lv_bar_ext_t * ext = lv_obj_get_ext(bar); + dm_free(ext->format_str); + ext->format_str = dm_alloc(strlen(format) + 1); + strcpy(ext->format_str, format); + lv_bar_set_value(bar, ext->act_value); +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the value of a bar + * @param bar pointer to a bar object + * @return the value of the bar + */ +int16_t lv_bar_get_value(lv_obj_t * bar) +{ + lv_bar_ext_t * ext = lv_obj_get_ext(bar); + return ext->act_value; +} + +/** + * Return with a pointer to a built-in style and/or copy it to a variable + * @param style a style name from lv_bars_builtin_t enum + * @param copy copy the style to this variable. (NULL if unused) + * @return pointer to an lv_bars_t style + */ +lv_bars_t * lv_bars_get(lv_bars_builtin_t style, lv_bars_t * copy) +{ + static bool style_inited = false; + + /*Make the style initialization if it is not done yet*/ + if(style_inited == false) { + lv_bars_init(); + style_inited = true; + } + + lv_bars_t *style_p; + + switch(style) { + case LV_BARS_DEF: + style_p = &lv_bars_def; + break; + default: + style_p = &lv_bars_def; + } + + if(copy != NULL) memcpy(copy, style_p, sizeof(lv_bars_t)); + + return style_p; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + + +/** + * Handle the drawing related tasks of the bars + * @param bar pointer to an object + * @param mask the object will be drawn only in this area + * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area + * (return 'true' if yes) + * LV_DESIGN_DRAW: draw the object (always return 'true') + * LV_DESIGN_DRAW_POST: drawing after every children are drawn + * @param return true/false, depends on 'mode' + */ +static bool lv_bar_design(lv_obj_t * bar, const area_t * mask, lv_design_mode_t mode) +{ + if(ancestor_design_f == NULL) return false; + + if(mode == LV_DESIGN_COVER_CHK) { + /*Return false if the object is not covers the mask_p area*/ + return ancestor_design_f(bar, mask, mode); + } else if(mode == LV_DESIGN_DRAW_MAIN) { + ancestor_design_f(bar, mask, mode); + + lv_bar_ext_t * ext = lv_obj_get_ext(bar); + lv_bars_t * style = lv_obj_get_style(bar); + area_t bar_area; + uint32_t tmp; + area_cpy(&bar_area, &bar->cords); + + cord_t w = lv_obj_get_width(bar); + cord_t h = lv_obj_get_height(bar); + + if(w >= h) { + bar_area.x2 = (int32_t) ((int32_t)w * ext->act_value) / (ext->max_value - ext->min_value); + bar_area.x2 += bar_area.x1; + } else { + bar_area.y1 = (int32_t) ((int32_t)h * ext->act_value) / (ext->max_value - ext->min_value); + bar_area.y1 = bar_area.y2 - bar_area.y1; + } + + /*Draw the main bar*/ + lv_draw_rect(&bar_area, mask, &style->indic); + } + return true; +} + +/** + * Initialize the bar styles + */ +static void lv_bars_init(void) +{ + /*Default style*/ + lv_rects_get(LV_RECTS_FANCY, &lv_bars_def.bg); /*Background*/ + lv_bars_def.bg.base.color = COLOR_WHITE; + lv_bars_def.bg.gcolor = COLOR_SILVER, + lv_bars_def.bg.bcolor = COLOR_BLACK; + + lv_rects_get(LV_RECTS_FANCY, &lv_bars_def.indic); /*Bar*/ + lv_bars_def.indic.base.color = COLOR_LIME; + lv_bars_def.indic.gcolor = COLOR_GREEN; + lv_bars_def.indic.bcolor = COLOR_BLACK; + lv_bars_def.indic.swidth = 0; + + lv_labels_get(LV_LABELS_TXT, &lv_bars_def.label); /*Label*/ + lv_bars_def.label.line_space = 0; + +} +#endif diff --git a/lv_objx/lv_pb.h b/lv_objx/lv_bar.h similarity index 52% rename from lv_objx/lv_pb.h rename to lv_objx/lv_bar.h index 7de556963..fc5b044e7 100644 --- a/lv_objx/lv_pb.h +++ b/lv_objx/lv_bar.h @@ -1,24 +1,24 @@ /** - * @file lv_pb.h + * @file lv_bar.h * */ -#ifndef LV_PB_H -#define LV_PB_H +#ifndef LV_BAR_H +#define LV_BAR_H /********************* * INCLUDES *********************/ #include "lv_conf.h" -#if USE_LV_PB != 0 +#if USE_LV_BAR != 0 /*Testing of dependencies*/ #if USE_LV_RECT == 0 -#error "lv_pb: lv_rect is required. Enable it in lv_conf.h (USE_LV_RECT 1) " +#error "lv_bar: lv_rect is required. Enable it in lv_conf.h (USE_LV_RECT 1) " #endif #if USE_LV_LABEL == 0 -#error "lv_pb: lv_label is required. Enable it in lv_conf.h (USE_LV_LABEL 1) " +#error "lv_bar: lv_label is required. Enable it in lv_conf.h (USE_LV_LABEL 1) " #endif #include "../lv_obj/lv_obj.h" @@ -34,36 +34,32 @@ * TYPEDEFS **********************/ -/*Data of progress bar*/ +/*Data of bar*/ typedef struct { lv_rect_ext_t rect_ext; /*Ext. of ancestor*/ /*New data for this type */ - lv_obj_t * label; /*Pointer to the label on the progress bar*/ - int16_t act_value; /*Current value of the progress bar*/ - int16_t tmp_value; /*Value when settings from a display input*/ - int16_t min_value; /*Minimum value of the progress bar*/ - int16_t max_value; /*Maximum value of the progress bar*/ + lv_obj_t * label; /*Pointer to the label on the bar*/ + int16_t act_value; /*Current value of the bar*/ + int16_t min_value; /*Minimum value of the bar*/ + int16_t max_value; /*Maximum value of the bar*/ char * format_str; /*Format string of the label. E.g. "Progress: %d"*/ -}lv_pb_ext_t; +}lv_bar_ext_t; -/*Style of progress bar*/ +/*Style of bar*/ typedef struct { lv_rects_t bg; /*Style of the background (inherited)*/ - lv_rects_t bar; /*Style of the bar*/ + lv_rects_t indic; /*Style of the indicator*/ lv_labels_t label; /*Style of the label*/ - lv_rects_t btn; /*Style of the button (it is rectangle but acts as a button)*/ - cord_t btn_size; /*Width or height of the button (depending on the orientation of the pb)*/ -}lv_pbs_t; +}lv_bars_t; -/*Built-in styles of progress bar*/ +/*Built-in styles of bar*/ typedef enum { - LV_PBS_DEF, - LV_PBS_SLIDER, -}lv_pbs_builtin_t; + LV_BARS_DEF, +}lv_bars_builtin_t; /********************** * GLOBAL PROTOTYPES @@ -75,52 +71,52 @@ typedef enum * @param copy pointer to a progress bar object, if not NULL then the new object will be copied from it * @return pointer to the created progress bar */ -lv_obj_t * lv_pb_create(lv_obj_t * par, lv_obj_t * copy); +lv_obj_t * lv_bar_create(lv_obj_t * par, lv_obj_t * copy); /** * Signal function of the progress bar - * @param pb pointer to a progress bar object + * @param bar pointer to a progress bar object * @param sign a signal type from lv_signal_t enum * @param param pointer to a signal specific variable */ -bool lv_pb_signal(lv_obj_t * pb, lv_signal_t sign, void * param); +bool lv_bar_signal(lv_obj_t * bar, lv_signal_t sign, void * param); /** * Set a new value on the progress bar - * @param pb pointer to a progress bar object + * @param bar pointer to a progress bar object * @param value new value */ -void lv_pb_set_value(lv_obj_t * pb, int16_t value); +void lv_bar_set_value(lv_obj_t * bar, int16_t value); /** * Set minimum and the maximum values of a progress bar - * @param pb pointer to he progress bar object + * @param bar pointer to he progress bar object * @param min minimum value * @param max maximum value */ -void lv_pb_set_min_max_value(lv_obj_t * pb, int16_t min, int16_t max); +void lv_bar_set_range(lv_obj_t * bar, int16_t min, int16_t max); /** * Set format string for the label of the progress bar - * @param pb pointer to progress bar object + * @param bar pointer to progress bar object * @param format a printf-like format string with one number (e.g. "Loading (%d)") */ -void lv_pb_set_format_str(lv_obj_t * pb, const char * format); +void lv_bar_set_format_str(lv_obj_t * bar, const char * format); /** * Get the value of a progress bar - * @param pb pointer to a progress bar object + * @param bar pointer to a progress bar object * @return the value of the progress bar */ -int16_t lv_pb_get_value(lv_obj_t * pb); +int16_t lv_bar_get_value(lv_obj_t * bar); /** * Return with a pointer to a built-in style and/or copy it to a variable - * @param style a style name from lv_pbs_builtin_t enum + * @param style a style name from lv_bars_builtin_t enum * @param copy copy the style to this variable. (NULL if unused) - * @return pointer to an lv_pbs_t style + * @return pointer to an lv_bars_t style */ -lv_pbs_t * lv_pbs_get(lv_pbs_builtin_t style, lv_pbs_t * copy); +lv_bars_t * lv_bars_get(lv_bars_builtin_t style, lv_bars_t * copy); /********************** * MACROS diff --git a/lv_objx/lv_btn.h b/lv_objx/lv_btn.h index 924f27346..976ddfbca 100644 --- a/lv_objx/lv_btn.h +++ b/lv_objx/lv_btn.h @@ -28,6 +28,7 @@ * TYPEDEFS **********************/ +/*Button states*/ typedef enum { LV_BTN_STATE_PR, @@ -41,16 +42,16 @@ typedef enum /*Data of button*/ typedef struct { - lv_rect_ext_t rect_ext; /*Ext. of ancestor*/ + lv_rect_ext_t rect; /*Ext. of ancestor*/ /*New data for this type */ - lv_action_t pr_action; - lv_action_t rel_action; - lv_action_t lpr_action; - lv_action_t lpr_rep_action; + lv_action_t pr_action; /*A function to call when the button is pressed (NULL if unused)*/ + lv_action_t rel_action; /*A function to call when the button is released (NULL if unused)*/ + lv_action_t lpr_action; /*A function to call when the button is long pressed (NULL if unused)*/ + lv_action_t lpr_rep_action; /*A function to call periodically after long press (NULL if unused)*/ - lv_btn_state_t state; - uint8_t tgl :1; /*1: Toggle enabled*/ - uint8_t lpr_exec :1; /*1: long press action executed (Not for user)*/ + lv_btn_state_t state; /*Current state of the button from 'lv_btn_state_t' enum*/ + uint8_t tgl :1; /*1: Toggle enabled*/ + uint8_t lpr_exec :1; /*1: Long press action executed (Handled by the library)*/ }lv_btn_ext_t; /*Style of button*/ @@ -58,7 +59,7 @@ typedef struct { lv_rects_t current; /*Current style according to the state. Library use this. Style of ancestor*/ /*New style element for this type */ - lv_rects_t state_style[LV_BTN_STATE_NUM]; + lv_rects_t state_style[LV_BTN_STATE_NUM]; /*Rectangle styles for each state*/ }lv_btns_t; /*Built-in styles of button*/ diff --git a/lv_objx/lv_btnm.c b/lv_objx/lv_btnm.c index 88d49439e..c9d414f53 100644 --- a/lv_objx/lv_btnm.c +++ b/lv_objx/lv_btnm.c @@ -17,7 +17,7 @@ /********************* * DEFINES *********************/ -#define LV_BTNM_BTN_PR_INVALID 0xFFFF +#define LV_BTNM_PR_NONE 0xFFFF /********************** * TYPEDEFS @@ -71,7 +71,7 @@ lv_obj_t * lv_btnm_create(lv_obj_t * par, lv_obj_t * copy) lv_btnm_ext_t * ext = lv_obj_alloc_ext(new_btnm, sizeof(lv_btnm_ext_t)); dm_assert(ext); ext->btn_cnt = 0; - ext->btn_pr = LV_BTNM_BTN_PR_INVALID; + ext->btn_pr = LV_BTNM_PR_NONE; ext->btn_areas = NULL; ext->cb = NULL; ext->map_p = NULL; @@ -134,7 +134,7 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param) lv_obj_get_cords(btnm, &btnm_area); if(new_btn != ext->btn_pr) { lv_dispi_reset_lpr(param); - if(ext->btn_pr != LV_BTNM_BTN_PR_INVALID) { + if(ext->btn_pr != LV_BTNM_PR_NONE) { area_cpy(&btn_area, &ext->btn_areas[ext->btn_pr]); btn_area.x1 += btnm_area.x1; btn_area.y1 += btnm_area.y1; @@ -142,7 +142,7 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param) btn_area.y2 += btnm_area.y1; lv_inv_area(&btn_area); } - if(new_btn != LV_BTNM_BTN_PR_INVALID) { + if(new_btn != LV_BTNM_PR_NONE) { area_cpy(&btn_area, &ext->btn_areas[new_btn]); btn_area.x1 += btnm_area.x1; btn_area.y1 += btnm_area.y1; @@ -157,7 +157,7 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param) case LV_SIGNAL_RELEASED: case LV_SIGNAL_LONG_PRESS_REP: if(ext->cb != NULL && - ext->btn_pr != LV_BTNM_BTN_PR_INVALID) { + ext->btn_pr != LV_BTNM_PR_NONE) { uint16_t txt_i = 0; uint16_t btn_i = 0; /*Search the next valid text in the map*/ @@ -169,7 +169,7 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param) ext->cb(btnm, txt_i); } - if(sign == LV_SIGNAL_RELEASED && ext->btn_pr != LV_BTNM_BTN_PR_INVALID) { + if(sign == LV_SIGNAL_RELEASED && ext->btn_pr != LV_BTNM_PR_NONE) { /*Invalidate to old area*/; lv_obj_get_cords(btnm, &btnm_area); area_cpy(&btn_area, &ext->btn_areas[ext->btn_pr]); @@ -179,7 +179,7 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param) btn_area.y2 += btnm_area.y1; lv_inv_area(&btn_area); - ext->btn_pr = LV_BTNM_BTN_PR_INVALID; + ext->btn_pr = LV_BTNM_PR_NONE; } break; default: @@ -294,7 +294,7 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map) * @param btnm: pointer to button matrix object * @param cb pointer to a callback function */ -void lv_btnm_set_cb(lv_obj_t * btnm, lv_btnm_callback_t cb) +void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_callback_t cb) { LV_EA(btnm, lv_btnm_ext_t)->cb = cb; } @@ -509,7 +509,7 @@ static uint16_t lv_btnm_get_btn_from_point(lv_obj_t * btnm, point_t * p) } } - if(i == ext->btn_cnt) i = LV_BTNM_BTN_PR_INVALID; + if(i == ext->btn_cnt) i = LV_BTNM_PR_NONE; return i; } diff --git a/lv_objx/lv_btnm.h b/lv_objx/lv_btnm.h index f68020baa..851b7eb8b 100644 --- a/lv_objx/lv_btnm.h +++ b/lv_objx/lv_btnm.h @@ -35,7 +35,7 @@ * TYPEDEFS **********************/ -/* Type of callback function which is called when a button is released +/* Type of callback function which is called when a button is released on the button matrix * Parameters: button matrix, released button index in the map string * return LV_ACTION_RES_INV: the button matrix is deleted else LV_ACTION_RES_OK*/ typedef lv_action_res_t (*lv_btnm_callback_t) (lv_obj_t *, uint16_t); @@ -46,10 +46,10 @@ typedef struct lv_rect_ext_t bg; /*Ext. of ancestor*/ /*New data for this type */ const char ** map_p; /*Pointer to the current map*/ - area_t * btn_areas; - uint16_t btn_cnt; - uint16_t btn_pr; - lv_btnm_callback_t cb; + area_t * btn_areas; /*Array of areas for the buttons (Handled by the library)*/ + uint16_t btn_cnt; /*Number of button in 'map_p'(Handled by the library)*/ + uint16_t btn_pr; /*Index of the currently pressed button or LV_BTNM_PR_NONE (Handled by the library)*/ + lv_btnm_callback_t cb; /*A function to call when a button is releases*/ }lv_btnm_ext_t; /*Style of button matrix*/ @@ -106,7 +106,7 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map); * @param btnm: pointer to button matrix object * @param cb pointer to a callback function */ -void lv_btnm_set_cb(lv_obj_t * btnm, lv_btnm_callback_t cb); +void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_callback_t cb); /** * Get the current map of a button matrix diff --git a/lv_objx/lv_cb.h b/lv_objx/lv_cb.h index 524a9216b..f3408169d 100644 --- a/lv_objx/lv_cb.h +++ b/lv_objx/lv_cb.h @@ -37,24 +37,24 @@ typedef struct { lv_btn_ext_t bg_btn; /*Ext. of ancestor*/ /*New data for this type */ - lv_obj_t * bullet; - lv_obj_t * label; + lv_obj_t * bullet; /*Pointer to button*/ + lv_obj_t * label; /*Pointer to label*/ }lv_cb_ext_t; /*Style of check box*/ typedef struct { - lv_btns_t bg; /*Style of ancestor*/ + lv_btns_t bg; /*Style of the background button*/ /*New style element for this type */ - lv_btns_t bullet; - lv_labels_t label; - cord_t bullet_size; + lv_btns_t bullet; /*Style of the bullet*/ + lv_labels_t label; /*Style of the label*/ + cord_t bullet_size; /*Size of bullet (square)*/ }lv_cbs_t; /*Built-in styles of check box*/ typedef enum { - LV_CBS_DEF, + LV_CBS_DEF, /*Default style with transparent background*/ }lv_cbs_builtin_t; /********************** diff --git a/lv_objx/lv_chart.c b/lv_objx/lv_chart.c index 13634e4f5..608e5f27c 100644 --- a/lv_objx/lv_chart.c +++ b/lv_objx/lv_chart.c @@ -427,7 +427,7 @@ static void lv_chart_draw_lines(lv_obj_t * chart, const area_t * mask) lv_lines_t lines; lv_lines_get(LV_LINES_DEF, &lines); lines.width = style->width; - lines.base.opa = (uint16_t)((uint16_t)style->bg.base.opa * style->data_opa) >> 8; + lines.base.opa = (uint16_t)((uint16_t)style->bg_rect.base.opa * style->data_opa) >> 8; /*Go through all data lines*/ LL_READ_BACK(ext->dl_ll, y_data) { @@ -481,7 +481,7 @@ static void lv_chart_draw_points(lv_obj_t * chart, const area_t * mask) rects.bwidth = 0; rects.empty = 0; rects.radius = LV_RECT_CIRCLE; - rects.base.opa = (uint16_t)((uint16_t)style->bg.base.opa * style->data_opa) >> 8; + rects.base.opa = (uint16_t)((uint16_t)style->bg_rect.base.opa * style->data_opa) >> 8; /*Go through all data lines*/ LL_READ_BACK(ext->dl_ll, y_data) { @@ -531,7 +531,7 @@ static void lv_chart_draw_cols(lv_obj_t * chart, const area_t * mask) rects.bwidth = 0; rects.empty = 0; rects.radius = 0; - rects.base.opa = (uint16_t)((uint16_t)style->bg.base.opa * style->data_opa) >> 8; + rects.base.opa = (uint16_t)((uint16_t)style->bg_rect.base.opa * style->data_opa) >> 8; col_a.y2 = chart->cords.y2; @@ -574,7 +574,7 @@ static void lv_charts_init(void) { /*Default style*/ /* Background */ - lv_rects_get(LV_RECTS_FANCY, &lv_charts_def.bg); + lv_rects_get(LV_RECTS_FANCY, &lv_charts_def.bg_rect); /* Div. line */ lv_lines_get(LV_LINES_DEF, &lv_charts_def.div_line); diff --git a/lv_objx/lv_chart.h b/lv_objx/lv_chart.h index 70df5e06f..1b846b587 100644 --- a/lv_objx/lv_chart.h +++ b/lv_objx/lv_chart.h @@ -59,7 +59,7 @@ typedef enum /*Style of chart*/ typedef struct { - lv_rects_t bg; /*Style of the ancestor*/ + lv_rects_t bg_rect; /*Style of the ancestor*/ /*New style element for this type */ lv_lines_t div_line; color_t color[LV_CHART_DL_NUM]; /*Line/Point/Col colors */ diff --git a/lv_objx/lv_ddlist.h b/lv_objx/lv_ddlist.h index 91a4fd101..0b7e7e5d1 100644 --- a/lv_objx/lv_ddlist.h +++ b/lv_objx/lv_ddlist.h @@ -27,11 +27,11 @@ typedef struct { lv_page_ext_t page; /*Ext. of ancestor*/ /*New data for this type */ - lv_obj_t * opt_label; /*Label for the options*/ - lv_action_res_t (*cb)(lv_obj_t *, uint16_t); - uint16_t sel_opt; - uint8_t opened :1; - uint8_t auto_size :1; + lv_obj_t * opt_label; /*Label for the options*/ + lv_action_res_t (*cb)(lv_obj_t *, uint16_t); /*Pointer to function to call when an option is slected*/ + uint16_t sel_opt; /*Index of the current option*/ + uint8_t opened :1; /*1: The list is opened*/ + uint8_t auto_size :1; /*1: Set height to show all options. 0: Set height maximum to the parent bottom*/ }lv_ddlist_ext_t; /*Style of drop down list*/ @@ -39,14 +39,14 @@ typedef struct { lv_pages_t page; /*Style of ancestor*/ /*New style element for this type */ - lv_rects_t sel; /*Select rectangle*/ + lv_rects_t sel; /*Select the 'selected' rectangle*/ lv_labels_t label; /*Style of labels*/ }lv_ddlists_t; /*Built-in styles of drop down list*/ typedef enum { - LV_DDLISTS_DEF, + LV_DDLISTS_DEF, /*Default drop down list*/ }lv_ddlists_builtin_t; /********************** diff --git a/lv_objx/lv_gauge.c b/lv_objx/lv_gauge.c index 38d0abb0b..536ddcfbd 100644 --- a/lv_objx/lv_gauge.c +++ b/lv_objx/lv_gauge.c @@ -72,7 +72,7 @@ lv_obj_t * lv_gauge_create(lv_obj_t * par, lv_obj_t * copy) /*Initialize the allocated 'ext' */ ext->min = 0; ext->max = 100; - ext->needle_num = 1; + ext->needle_num = 0; ext->low_critical = 0; ext->values = NULL; ext->txt = NULL; @@ -156,7 +156,12 @@ void lv_gauge_set_needle_num(lv_obj_t * gauge, uint8_t num) lv_gauge_ext_t * ext = lv_obj_get_ext(gauge); if(ext->values != NULL) dm_free(ext->values); - ext->values = dm_alloc(num * sizeof(int16_t)); + ext->values = dm_realloc(ext->values, num * sizeof(int16_t)); + + uint8_t n; + for(n = ext->needle_num; n < num; n++) { + ext->values[n] = ext->min; + } ext->needle_num = num; lv_obj_inv(gauge); @@ -312,10 +317,7 @@ lv_gauges_t * lv_gauges_get(lv_gauges_builtin_t style, lv_gauges_t * copy) style_p = &lv_gauges_def; } - if(copy != NULL) { - if(style_p != NULL) memcpy(copy, style_p, sizeof(lv_gauges_t)); - else memcpy(copy, &lv_gauges_def, sizeof(lv_gauges_t)); - } + if(copy != NULL) memcpy(copy, style_p, sizeof(lv_gauges_t)); return style_p; } @@ -347,8 +349,8 @@ static bool lv_gauge_design(lv_obj_t * gauge, const area_t * mask, lv_design_mod /* Draw the background * Re-color the gauge according to the critical value*/ - color_t mcolor_min = style->rects.objs.color; - color_t gcolor_min = style->rects.gcolor; + color_t mcolor_min = style->bg_rect.base.color; + color_t gcolor_min = style->bg_rect.gcolor; int16_t critical_val = ext->low_critical == 0 ? ext->min : ext->max; uint8_t i; @@ -361,11 +363,11 @@ static bool lv_gauge_design(lv_obj_t * gauge, const area_t * mask, lv_design_mod if(ext->low_critical != 0) ratio = OPA_COVER - ratio; - style->rects.objs.color= color_mix(style->mcolor_critical, mcolor_min, ratio); - style->rects.gcolor = color_mix(style->gcolor_critical, gcolor_min, ratio); + style->bg_rect.base.color= color_mix(style->critical_mcolor, mcolor_min, ratio); + style->bg_rect.gcolor = color_mix(style->critical_gcolor, gcolor_min, ratio); ancestor_design_f(gauge, mask, mode); - style->rects.objs.color= mcolor_min; - style->rects.gcolor = gcolor_min; + style->bg_rect.base.color= mcolor_min; + style->bg_rect.gcolor = gcolor_min; lv_gauge_draw_scale(gauge, mask); @@ -391,7 +393,7 @@ static void lv_gauge_draw_scale(lv_obj_t * gauge, const area_t * mask) char scale_txt[16]; - cord_t r = lv_obj_get_width(gauge) / 2 - style->scale_pad; + cord_t r = lv_obj_get_width(gauge) / 2 - style->bg_rect.opad; cord_t x_ofs = lv_obj_get_width(gauge) / 2 + gauge->cords.x1; cord_t y_ofs = lv_obj_get_height(gauge) / 2 + gauge->cords.y1; int16_t angle_ofs = 90 + (360 - style->scale_angle) / 2; @@ -413,7 +415,7 @@ static void lv_gauge_draw_scale(lv_obj_t * gauge, const area_t * mask) area_t label_cord; point_t label_size; - txt_get_size(&label_size, scale_txt, font_get(style->scale_labels.font), + txt_get_size(&label_size, scale_txt, style->scale_labels.font, style->scale_labels.letter_space, style->scale_labels.line_space, LV_CORD_MAX, TXT_FLAG_NONE); @@ -423,7 +425,7 @@ static void lv_gauge_draw_scale(lv_obj_t * gauge, const area_t * mask) label_cord.x2 = label_cord.x1 + label_size.x; label_cord.y2 = label_cord.y1 + label_size.y; - lv_draw_label(&label_cord, mask, &style->scale_labels, OPA_COVER, scale_txt, TXT_FLAG_NONE); + lv_draw_label(&label_cord, mask, &style->scale_labels, scale_txt, TXT_FLAG_NONE); } /*Calculate the critical value*/ @@ -440,7 +442,7 @@ static void lv_gauge_draw_scale(lv_obj_t * gauge, const area_t * mask) area_t label_cord; point_t label_size; - txt_get_size(&label_size, value_txt, font_get(style->value_labels.font), + txt_get_size(&label_size, value_txt, style->value_labels.font, style->value_labels.letter_space, style->value_labels.line_space, LV_CORD_MAX, TXT_FLAG_NONE); @@ -452,7 +454,7 @@ static void lv_gauge_draw_scale(lv_obj_t * gauge, const area_t * mask) label_cord.x2 = label_cord.x1 + label_size.x; label_cord.y2 = label_cord.y1 + label_size.y; - lv_draw_label(&label_cord, mask, &style->value_labels, OPA_COVER, value_txt, TXT_FLAG_NONE); + lv_draw_label(&label_cord, mask, &style->value_labels, value_txt, TXT_FLAG_NONE); } } @@ -466,7 +468,7 @@ static void lv_gauge_draw_needle(lv_obj_t * gauge, const area_t * mask) lv_gauges_t * style = lv_obj_get_style(gauge); lv_gauge_ext_t * ext = lv_obj_get_ext(gauge); - cord_t r = lv_obj_get_width(gauge) / 2 - style->scale_pad; + cord_t r = lv_obj_get_width(gauge) / 2 - style->bg_rect.opad; cord_t x_ofs = lv_obj_get_width(gauge) / 2 + gauge->cords.x1; cord_t y_ofs = lv_obj_get_height(gauge) / 2 + gauge->cords.y1; int16_t angle_ofs = 90 + (360 - style->scale_angle) / 2; @@ -484,27 +486,27 @@ static void lv_gauge_draw_needle(lv_obj_t * gauge, const area_t * mask) p_end.x = (trigo_sin(needle_angle + 90) * r) / TRIGO_SIN_MAX + x_ofs; /*Draw the needle with the corresponding color*/ - style->needle_lines.objs.color = style->needle_color[i]; + style->needle_lines.base.color = style->needle_color[i]; - lv_draw_line(&p_mid, &p_end, mask, &style->needle_lines, style->needle_opa); + lv_draw_line(&p_mid, &p_end, mask, &style->needle_lines); } /*Draw the needle middle area*/ lv_rects_t nm; area_t nm_cord; - lv_rects_get(LV_RECTS_DEF, &nm); + lv_rects_get(LV_RECTS_PLAIN, &nm); nm.bwidth = 0; nm.radius = LV_RECT_CIRCLE; - nm.objs.color = style->needle_mid_color; + nm.base.color = style->needle_mid_color; nm.gcolor = style->needle_mid_color; - nm_cord.x1 = x_ofs - style->needle_mid_r; - nm_cord.y1 = y_ofs - style->needle_mid_r; - nm_cord.x2 = x_ofs + style->needle_mid_r; - nm_cord.y2 = y_ofs + style->needle_mid_r; + nm_cord.x1 = x_ofs - style->needle_mid_size; + nm_cord.y1 = y_ofs - style->needle_mid_size; + nm_cord.x2 = x_ofs + style->needle_mid_size; + nm_cord.y2 = y_ofs + style->needle_mid_size; - lv_draw_rect(&nm_cord, mask, &nm, OPA_100); + lv_draw_rect(&nm_cord, mask, &nm); } @@ -514,28 +516,30 @@ static void lv_gauge_draw_needle(lv_obj_t * gauge, const area_t * mask) static void lv_gauges_init(void) { /*Default style*/ - lv_rects_get(LV_RECTS_DEF, &lv_gauges_def.rects); - lv_gauges_def.rects.radius = LV_RECT_CIRCLE; - lv_gauges_def.rects.bwidth = 4 * LV_DOWNSCALE; - lv_gauges_def.rects.objs.color = COLOR_MAKE(0x00, 0xaa, 0x00);//GREEN; - lv_gauges_def.rects.gcolor = COLOR_BLACK; - lv_gauges_def.rects.bcolor = COLOR_BLACK; + lv_rects_get(LV_RECTS_FANCY, &lv_gauges_def.bg_rect); + lv_gauges_def.bg_rect.radius = LV_RECT_CIRCLE; + lv_gauges_def.bg_rect.bwidth = 4 * LV_DOWNSCALE; + lv_gauges_def.bg_rect.base.color = COLOR_MAKE(0x00, 0xaa, 0x00);//GREEN; + lv_gauges_def.bg_rect.gcolor = COLOR_BLACK; + lv_gauges_def.bg_rect.bcolor = COLOR_BLACK; + lv_gauges_def.bg_rect.opad = LV_DPI / 4; - lv_gauges_def.gcolor_critical = COLOR_BLACK; - lv_gauges_def.mcolor_critical = COLOR_MAKE(0xff, 0x50, 0x50); + lv_gauges_def.critical_gcolor = COLOR_BLACK; + lv_gauges_def.critical_mcolor = COLOR_MAKE(0xff, 0x50, 0x50); - lv_labels_get(LV_LABELS_DEF, &lv_gauges_def.scale_labels); - lv_gauges_def.scale_labels.objs.color = COLOR_MAKE(0xd0, 0xd0, 0xd0); + lv_labels_get(LV_LABELS_TXT, &lv_gauges_def.scale_labels); + lv_gauges_def.scale_labels.base.color = COLOR_MAKE(0xd0, 0xd0, 0xd0); - lv_labels_get(LV_LABELS_DEF, &lv_gauges_def.value_labels); - lv_gauges_def.value_labels.objs.color = COLOR_WHITE; + lv_labels_get(LV_LABELS_TITLE, &lv_gauges_def.value_labels); + lv_gauges_def.value_labels.base.color = COLOR_WHITE; lv_gauges_def.value_labels.letter_space = 3 * LV_DOWNSCALE; lv_gauges_def.value_labels.mid = 1; lv_gauges_def.value_pos = 75; lv_lines_get(LV_LINES_DEF, &lv_gauges_def.needle_lines); - lv_gauges_def.needle_lines.objs.color = COLOR_WHITE; + lv_gauges_def.needle_lines.base.color = COLOR_WHITE; /*Overwritten by needle_color[]*/ + lv_gauges_def.needle_lines.base.opa = OPA_80; lv_gauges_def.needle_lines.width = 3 * LV_DOWNSCALE; lv_gauges_def.needle_color[0] = COLOR_SILVER; @@ -543,10 +547,8 @@ static void lv_gauges_init(void) lv_gauges_def.needle_color[2] = COLOR_MAKE(0x50, 0xe0, 0x50); lv_gauges_def.needle_color[3] = COLOR_MAKE(0xff, 0xff, 0x70); - lv_gauges_def.needle_mid_r = 5 * LV_DOWNSCALE; + lv_gauges_def.needle_mid_size = 5 * LV_DOWNSCALE; lv_gauges_def.needle_mid_color = COLOR_GRAY; - lv_gauges_def.needle_opa = OPA_80; - lv_gauges_def.scale_pad = 20 * LV_DOWNSCALE; lv_gauges_def.scale_label_num = 6; lv_gauges_def.scale_angle = 220; } diff --git a/lv_objx/lv_gauge.h b/lv_objx/lv_gauge.h index ed7c8531c..8e694f743 100644 --- a/lv_objx/lv_gauge.h +++ b/lv_objx/lv_gauge.h @@ -48,37 +48,35 @@ /*Data of gauge*/ typedef struct { - lv_rect_ext_t rect; /*Ext. of ancestor*/ + lv_rect_ext_t bg_rect; /*Ext. of ancestor*/ /*New data for this type */ int16_t min; /*Minimum value of the scale*/ int16_t max; /*Maximum value of the scale*/ int16_t * values; /*Array of the set values (for needles) */ char * txt; /*Printf-like text to display with the most critical value (e.g. "Value: %d")*/ uint8_t needle_num; /*Number of needles*/ - uint8_t low_critical :1; /*0: the higher value is more critical, 1: the lower value is more critical*/ + uint8_t low_critical:1; /*0: the higher value is more critical, 1: the lower value is more critical*/ }lv_gauge_ext_t; /*Style of gauge*/ typedef struct { - lv_rects_t rects; /*Style of ancestor*/ + lv_rects_t bg_rect; /*Style of ancestor*/ /*New style element for this type */ - color_t mcolor_critical; /*Top color at critical.*/ - color_t gcolor_critical; /*Bottom color at critical*/ + color_t critical_mcolor; /*Top color at critical value*/ + color_t critical_gcolor; /*Bottom color at critical value*/ /*Scale settings*/ - uint16_t scale_angle; /*Angle of the scale in deg. (~220)*/ + uint16_t scale_angle; /*Angle of the scale in deg. (e.g. 220)*/ lv_labels_t scale_labels; /*Style of the scale labels*/ - cord_t scale_pad; /*Padding of scale labels from the edge*/ uint8_t scale_label_num; /*Number of scale labels (~6)*/ /*Needle settings*/ lv_lines_t needle_lines; /*Style of neddles*/ color_t needle_color[LV_GAUGE_MAX_NEEDLE]; /*Color of needles*/ - color_t needle_mid_color; /*Color of middle where the needles start*/ - cord_t needle_mid_r; /*Radius of the needle middle area*/ - opa_t needle_opa; /*Opacity of the needles*/ + color_t needle_mid_color; /*Color of middle where the needles start*/ + cord_t needle_mid_size; /*Size of the needle middle area (circle diameter)*/ /*Value text settings*/ lv_labels_t value_labels; /*Style of the value label*/ - uint8_t value_pos; /*Vertical position of the value label in percentage of object height (0..100 %)*/ + uint8_t value_pos; /*Vertical position of the value label in percentage of object height (0..100 %)*/ }lv_gauges_t; /*Built-in styles of gauge*/ diff --git a/lv_objx/lv_img.h b/lv_objx/lv_img.h index 0db3a061d..69ddd21bb 100644 --- a/lv_objx/lv_img.h +++ b/lv_objx/lv_img.h @@ -41,12 +41,12 @@ typedef struct { /*No inherited ext. because inherited from the base object*/ /*Ext. of ancestor*/ /*New data for this type */ - char* fn; /*Image file name. E.g. "U:/my_image"*/ - cord_t w; /*Width of the image (doubled when upscaled)*/ - cord_t h; /*Height of the image (doubled when upscaled)*/ - uint8_t auto_size :1; /*1: automatically set the object size to the image size*/ - uint8_t upscale :1; /*1: upscale to double size*/ - uint8_t transp :1; /*Transp. bit in the image header (library handles this)*/ + char* fn; /*Image file name. E.g. "U:/my_image"*/ + cord_t w; /*Width of the image (doubled when upscaled)*/ + cord_t h; /*Height of the image (doubled when upscaled)*/ + uint8_t auto_size :1; /*1: automatically set the object size to the image size*/ + uint8_t upscale :1; /*1: upscale to double size with antialaissing*/ + uint8_t transp :1; /*Transp. bit in the image header (Handled by the library)*/ }lv_img_ext_t; /*Style of image*/ @@ -54,9 +54,9 @@ typedef struct { lv_objs_t base; /*Style of ancestor*/ /*New style element for this type */ - opa_t recolor_opa; /*Intensity of recoloring (OPA_TRANSP, OPA_10 ... OPA_COVER)*/ + opa_t recolor_opa; /*Intensity of recoloring with base.color (OPA_TRANSP, OPA_10 ... OPA_COVER)*/ #if LV_IMG_ENABLE_SYMBOLS != 0 - const font_t * sym_font; /*Symbol font*/ + const font_t * sym_font; /*Symbol font is the image is used as icon*/ #endif }lv_imgs_t; diff --git a/lv_objx/lv_label.c b/lv_objx/lv_label.c index 2ed276aac..18ab2aa7f 100644 --- a/lv_objx/lv_label.c +++ b/lv_objx/lv_label.c @@ -668,7 +668,7 @@ static void lv_labels_init(void) { /*Text style*/ lv_objs_get(LV_OBJS_PLAIN, &lv_labels_txt.base); - lv_labels_txt.base.color = COLOR_MAKE(0x10, 0x18, 0x20); + lv_labels_txt.base.color = COLOR_MAKE(0x20, 0x20, 0x20); lv_labels_txt.font = font_get(LV_FONT_DEFAULT); lv_labels_txt.letter_space = 1 * LV_DOWNSCALE; lv_labels_txt.line_space = 2 * LV_DOWNSCALE; diff --git a/lv_objx/lv_label.h b/lv_objx/lv_label.h index 62ef494f6..bae3dc3c5 100644 --- a/lv_objx/lv_label.h +++ b/lv_objx/lv_label.h @@ -42,9 +42,9 @@ typedef struct char * txt; /*Text of the label*/ lv_label_long_mode_t long_mode; /*Determinate what to do with the long texts*/ char dot_tmp[LV_LABEL_DOT_NUM]; /*Store character which are replaced with dots*/ - uint16_t dot_end; /* The text end position in dot mode*/ - uint8_t static_txt :1; /* Flag to indicate the text is static*/ - uint8_t recolor :1; /* Enable in-line letter recoloring*/ + uint16_t dot_end; /*The text end position in dot mode*/ + uint8_t static_txt :1; /*Flag to indicate the text is static*/ + uint8_t recolor :1; /*Enable in-line letter re-coloring*/ }lv_label_ext_t; /*Style of label*/ @@ -52,18 +52,18 @@ typedef struct { lv_objs_t base; /*Style of ancestor*/ /*New style element for this type */ - const font_t * font; /*Pointer to a font*/ - cord_t letter_space; - cord_t line_space; - uint8_t mid :1; /*1: Align the lines into the middle*/ + const font_t * font; /*Pointer to a font*/ + cord_t letter_space; /*Letter space in px*/ + cord_t line_space; /*Line space in px*/ + uint8_t mid:1; /*1: Align the lines into the middle*/ }lv_labels_t; /*Built-in styles of label*/ typedef enum { - LV_LABELS_TITLE, - LV_LABELS_TXT, - LV_LABELS_BTN, + LV_LABELS_TXT, /*General text style*/ + LV_LABELS_TITLE, /*Like text style but greater spaces*/ + LV_LABELS_BTN, /*Mid. aligned style for buttons*/ }lv_labels_builtin_t; /********************** diff --git a/lv_objx/lv_led.c b/lv_objx/lv_led.c index c11410c09..edb89632f 100644 --- a/lv_objx/lv_led.c +++ b/lv_objx/lv_led.c @@ -16,10 +16,9 @@ /********************* * DEFINES *********************/ -#define LV_LED_WIDTH_DEF (30 * LV_DOWNSCALE) -#define LV_LED_HEIGHT_DEF (30 * LV_DOWNSCALE) -#define LV_LED_BRIGHT_DEF 128 -#define LV_LED_BRIGHT_OFF 60 +#define LV_LED_WIDTH_DEF (LV_DPI / 2) +#define LV_LED_HEIGHT_DEF (LV_DPI / 2) +#define LV_LED_BRIGHT_OFF 40 #define LV_LED_BRIGHT_ON 255 /********************** @@ -35,11 +34,11 @@ static void lv_leds_init(void); /********************** * STATIC VARIABLES **********************/ - -static lv_leds_t lv_leds_def; static lv_leds_t lv_leds_red; static lv_leds_t lv_leds_green; + static lv_design_f_t ancestor_design_f; + /********************** * MACROS **********************/ @@ -67,7 +66,7 @@ lv_obj_t * lv_led_create(lv_obj_t * par, lv_obj_t * copy) /*Allocate the object type specific extended data*/ lv_led_ext_t * ext = lv_obj_alloc_ext(new_led, sizeof(lv_led_ext_t)); dm_assert(ext); - ext->bright = LV_LED_BRIGHT_DEF; + ext->bright = LV_LED_BRIGHT_ON; if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_f(new_led); @@ -76,7 +75,7 @@ lv_obj_t * lv_led_create(lv_obj_t * par, lv_obj_t * copy) /*Init the new led object*/ if(copy == NULL) { - lv_obj_set_style(new_led, lv_leds_get(LV_LEDS_DEF, NULL)); + lv_obj_set_style(new_led, lv_leds_get(LV_LEDS_RED, NULL)); lv_obj_set_size(new_led, LV_LED_WIDTH_DEF, LV_LED_HEIGHT_DEF); } /*Copy an existing object*/ @@ -203,9 +202,6 @@ lv_leds_t * lv_leds_get(lv_leds_builtin_t style, lv_leds_t * copy) lv_leds_t *style_p; switch(style) { - case LV_LEDS_DEF: - style_p = &lv_leds_def; - break; case LV_LEDS_RED: style_p = &lv_leds_red; break; @@ -213,13 +209,10 @@ lv_leds_t * lv_leds_get(lv_leds_builtin_t style, lv_leds_t * copy) style_p = &lv_leds_green; break; default: - style_p = &lv_leds_def; + style_p = &lv_leds_red; } - if(copy != NULL) { - if(style_p != NULL) memcpy(copy, style_p, sizeof(lv_leds_t)); - else memcpy(copy, &lv_leds_def, sizeof(lv_leds_t)); - } + if(copy != NULL) memcpy(copy, style_p, sizeof(lv_leds_t)); return style_p; } @@ -253,14 +246,11 @@ static bool lv_led_design(lv_obj_t * led, const area_t * mask, lv_design_mode_t memcpy(&leds_tmp, style, sizeof(leds_tmp)); /*Mix. the color with black proportionally with brightness*/ - leds_tmp.bg_rect.objs.color = color_mix(leds_tmp.bg_rect.objs.color, COLOR_BLACK, ext->bright); + leds_tmp.bg_rect.base.color = color_mix(leds_tmp.bg_rect.base.color, COLOR_BLACK, ext->bright); leds_tmp.bg_rect.gcolor = color_mix(leds_tmp.bg_rect.gcolor, COLOR_BLACK, ext->bright); - /*Set smaller light size with lower brightness*/ - /*light = 0 comes to LV_LED_BRIGHTNESS_OFF and the original light comes to LV_LED_BRIGHTNESS_ON*/ - leds_tmp.bg_rect.light = (uint16_t)((uint16_t)(ext->bright - LV_LED_BRIGHT_OFF) * style->bg_rect.light) / - (LV_LED_BRIGHT_ON - LV_LED_BRIGHT_OFF); - + /*Set the current swidth according to brightness proportionally between LV_LED_BRIGHT_OFF and LV_LED_BRIGHT_ON*/ + leds_tmp.bg_rect.swidth = (uint16_t)(uint16_t)(ext->bright * style->bg_rect.swidth) >> 8; led->style_p = &leds_tmp; ancestor_design_f(led, mask, mode); @@ -275,28 +265,23 @@ static bool lv_led_design(lv_obj_t * led, const area_t * mask, lv_design_mode_t static void lv_leds_init(void) { /*Default style (red)*/ - lv_rects_get(LV_RECTS_DEF, &lv_leds_def.bg_rect); - lv_leds_def.bg_rect.objs.color = COLOR_RED; - lv_leds_def.bg_rect.gcolor = COLOR_MARRON, - lv_leds_def.bg_rect.bcolor = COLOR_MAKE(0x40, 0x00, 0x00); - lv_leds_def.bg_rect.lcolor = COLOR_RED; - lv_leds_def.bg_rect.bwidth = 4 * LV_DOWNSCALE; - lv_leds_def.bg_rect.bopa = 50; - lv_leds_def.bg_rect.light = 15 * LV_DOWNSCALE; - lv_leds_def.bg_rect.radius = LV_RECT_CIRCLE; - lv_leds_def.bg_rect.hpad = 0; - lv_leds_def.bg_rect.vpad = 0; - lv_leds_def.bg_rect.opad = 0; + lv_rects_get(LV_RECTS_PLAIN, &lv_leds_red.bg_rect); + lv_leds_red.bg_rect.base.color = COLOR_RED; + lv_leds_red.bg_rect.gcolor = COLOR_MARRON, + lv_leds_red.bg_rect.bcolor = COLOR_MAKE(0x40, 0x00, 0x00); + lv_leds_red.bg_rect.scolor = COLOR_RED; + lv_leds_red.bg_rect.bwidth = 3 * LV_DOWNSCALE; + lv_leds_red.bg_rect.bopa = OPA_50; + lv_leds_red.bg_rect.swidth = LV_DPI / 4; + lv_leds_red.bg_rect.radius = LV_RECT_CIRCLE; - /*Red style*/ - memcpy(&lv_leds_red, &lv_leds_def, sizeof(lv_leds_t)); /* Green style */ - memcpy(&lv_leds_green, &lv_leds_def, sizeof(lv_leds_t)); - lv_leds_green.bg_rect.objs.color = COLOR_LIME; + memcpy(&lv_leds_green, &lv_leds_red, sizeof(lv_leds_t)); + lv_leds_green.bg_rect.base.color = COLOR_LIME; lv_leds_green.bg_rect.gcolor = COLOR_GREEN; lv_leds_green.bg_rect.bcolor = COLOR_MAKE(0x00, 0x40, 0x00); - lv_leds_green.bg_rect.lcolor = COLOR_LIME; + lv_leds_green.bg_rect.scolor = COLOR_LIME; } #endif diff --git a/lv_objx/lv_led.h b/lv_objx/lv_led.h index 939bebdf4..f746cb35f 100644 --- a/lv_objx/lv_led.h +++ b/lv_objx/lv_led.h @@ -30,24 +30,23 @@ /*Data of led*/ typedef struct { - lv_rect_ext_t rect_ext; /*Ext. of ancestor*/ + lv_rect_ext_t bg_rect; /*Ext. of ancestor*/ /*New data for this type */ - uint8_t bright; /*Current brightness of the LED*/ + uint8_t bright; /*Current brightness of the LED (0..255)*/ }lv_led_ext_t; /*Style of led*/ typedef struct { - lv_rects_t bg_rect;/*Style of ancestor*/ + lv_rects_t bg_rect; /*Style of ancestor*/ /*New style element for this type */ }lv_leds_t; /*Built-in styles of led*/ typedef enum { - LV_LEDS_DEF, - LV_LEDS_RED, - LV_LEDS_GREEN, + LV_LEDS_RED, /*Red LED style*/ + LV_LEDS_GREEN, /*Green LED style*/ }lv_leds_builtin_t; /********************** diff --git a/lv_objx/lv_list.c b/lv_objx/lv_list.c index bb1a7b53f..77bc23813 100644 --- a/lv_objx/lv_list.c +++ b/lv_objx/lv_list.c @@ -68,7 +68,7 @@ lv_obj_t * lv_list_create(lv_obj_t * par, lv_obj_t * copy) if(copy == NULL) { lv_obj_set_size_us(new_list, 120, 150); lv_obj_set_style(new_list, lv_lists_get(LV_LISTS_DEF, NULL)); - lv_rect_set_layout(LV_EA(new_list, lv_list_ext_t)->page_ext.scrl, LV_LIST_LAYOUT_DEF); + lv_rect_set_layout(LV_EA(new_list, lv_list_ext_t)->page.scrl, LV_LIST_LAYOUT_DEF); } else { /*Refresh the style with new signal function*/ lv_obj_refr_style(new_list); diff --git a/lv_objx/lv_list.h b/lv_objx/lv_list.h index a3f0eeaa4..cbb4c1147 100644 --- a/lv_objx/lv_list.h +++ b/lv_objx/lv_list.h @@ -41,7 +41,7 @@ /*Data of list*/ typedef struct { - lv_page_ext_t page_ext; /*Ext. of ancestor*/ + lv_page_ext_t page; /*Ext. of ancestor*/ /*New data for this type */ /*No new data*/ }lv_list_ext_t; @@ -60,8 +60,8 @@ typedef struct /*Built-in styles of list*/ typedef enum { - LV_LISTS_DEF, - LV_LISTS_TRANSP, + LV_LISTS_DEF, /*Default list style. Transparent background, visible scrlollable object*/ + LV_LISTS_TRANSP, /*Transparent list style. Transparent background and scrollable object*/ }lv_lists_builtin_t; /********************** diff --git a/lv_objx/lv_mbox.h b/lv_objx/lv_mbox.h index 63dd0b9cf..5cf8fcbcc 100644 --- a/lv_objx/lv_mbox.h +++ b/lv_objx/lv_mbox.h @@ -53,7 +53,7 @@ typedef struct /*Style of message box*/ typedef struct { - lv_rects_t bg; /*Style of ancestor*/ + lv_rects_t bg; /*Style of ancestor*/ /*New style element for this type */ lv_labels_t title; /*Style of the title*/ lv_labels_t txt; /*Style of the text*/ diff --git a/lv_objx/lv_page.h b/lv_objx/lv_page.h index 8ab794adb..8cdde5515 100644 --- a/lv_objx/lv_page.h +++ b/lv_objx/lv_page.h @@ -31,15 +31,15 @@ /*Data of page*/ typedef struct { - lv_rect_ext_t rect_ext; /*Ext. of ancestor*/ + lv_rect_ext_t bg_rect; /*Ext. of ancestor*/ /*New data for this type */ lv_obj_t * scrl; /*The scrollable object on the background*/ - lv_action_t rel_action; /*Release action*/ - lv_action_t pr_action; /*Press action*/ - area_t sbh; /*Horizontal scrollbar area (relative to the page) */ - area_t sbv; /*Vertical scrollbar area (relative to the page)*/ - uint8_t sbh_draw :1; /*1: horizontal scrollbar is visible now*/ - uint8_t sbv_draw :1; /*1: vertical scrollbar is visible now*/ + lv_action_t rel_action; /*Function to call when the page is released*/ + lv_action_t pr_action; /*Function to call when the page is pressed*/ + area_t sbh; /*Horizontal scrollbar area relative to the page. (Handled by the library) */ + area_t sbv; /*Vertical scrollbar area relative to the page (Handled by the library)*/ + uint8_t sbh_draw :1; /*1: horizontal scrollbar is visible now (Handled by the library)*/ + uint8_t sbv_draw :1; /*1: vertical scrollbar is visible now (Handled by the library)*/ }lv_page_ext_t; /*Scrollbar modes: shows when should the scrollbars be visible*/ diff --git a/lv_objx/lv_pb.c b/lv_objx/lv_pb.c deleted file mode 100644 index 9673b53da..000000000 --- a/lv_objx/lv_pb.c +++ /dev/null @@ -1,431 +0,0 @@ - - -/** - * @file lv_pb.c - * - */ - -/********************* - * INCLUDES - *********************/ -#include "lv_conf.h" -#if USE_LV_PB != 0 - -#include "lv_pb.h" -#include "../lv_draw/lv_draw.h" -#include - -/********************* - * DEFINES - *********************/ -#define LV_PB_TXT_MAX_LENGTH 64 -#define LV_PB_DEF_FORMAT "%d %%" -#define LV_PB_DEF_WIDTH (120 * LV_DOWNSCALE) -#define LV_PB_DEF_HEIGHT (40 * LV_DOWNSCALE) - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * STATIC PROTOTYPES - **********************/ -static bool lv_pb_design(lv_obj_t * pb, const area_t * mask, lv_design_mode_t mode); -static void lv_pbs_init(void); - -/********************** - * STATIC VARIABLES - **********************/ -static lv_pbs_t lv_pbs_def; -static lv_pbs_t lv_pbs_slider; -static lv_design_f_t ancestor_design_f; - -/********************** - * MACROS - **********************/ - -/********************** - * GLOBAL FUNCTIONS - **********************/ - -/*----------------- - * Create function - *-----------------*/ - -/** - * Create a progress bar objects - * @param par pointer to an object, it will be the parent of the new progress bar - * @param copy pointer to a progress bar object, if not NULL then the new object will be copied from it - * @return pointer to the created progress bar - */ -lv_obj_t * lv_pb_create(lv_obj_t * par, lv_obj_t * copy) -{ - /*Create the ancestor basic object*/ - lv_obj_t * new_pb = lv_rect_create(par, copy); - dm_assert(new_pb); - - /*Allocate the object type specific extended data*/ - lv_pb_ext_t * ext = lv_obj_alloc_ext(new_pb, sizeof(lv_pb_ext_t)); - dm_assert(ext); - ext->min_value = 0; - ext->max_value = 100; - ext->act_value = 0; - ext->tmp_value = 0; - ext->format_str = NULL; - ext->label = NULL; - - /* Save the rectangle design function. - * It will be used in the progress bar design function*/ - if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_f(new_pb); - - lv_obj_set_signal_f(new_pb, lv_pb_signal); - lv_obj_set_design_f(new_pb, lv_pb_design); - - /*Init the new progress bar object*/ - if(copy == NULL) { - ext->format_str = dm_alloc(strlen(LV_PB_DEF_FORMAT) + 1); - strcpy(ext->format_str, LV_PB_DEF_FORMAT); - - ext->label = lv_label_create(new_pb, NULL); - - lv_rect_set_layout(new_pb, LV_RECT_LAYOUT_CENTER); - lv_obj_set_click(new_pb, false); - lv_obj_set_size(new_pb, LV_PB_DEF_WIDTH, LV_PB_DEF_HEIGHT); - lv_obj_set_style(new_pb, lv_pbs_get(LV_PBS_DEF, NULL)); - - lv_pb_set_value(new_pb, ext->act_value); - } else { - lv_pb_ext_t * ext_copy = lv_obj_get_ext(copy); - ext->format_str = dm_alloc(strlen(ext_copy->format_str) + 1); - strcpy(ext->format_str, ext_copy->format_str); - ext->min_value = ext_copy->min_value; - ext->max_value = ext_copy->max_value; - ext->act_value = ext_copy->act_value; - ext->label = lv_label_create(new_pb, ext_copy->label); - - /*Refresh the style with new signal function*/ - lv_obj_refr_style(new_pb); - - lv_pb_set_value(new_pb, ext->act_value); - - } - return new_pb; -} - -/** - * Signal function of the progress bar - * @param pb pointer to a progress bar object - * @param sign a signal type from lv_signal_t enum - * @param param pointer to a signal specific variable - */ -bool lv_pb_signal(lv_obj_t * pb, lv_signal_t sign, void * param) -{ - bool valid; - - /* Include the ancient signal function */ - valid = lv_rect_signal(pb, sign, param); - - /* The object can be deleted so check its validity and then - * make the object specific signal handling */ - if(valid != false) { - lv_pb_ext_t * ext = lv_obj_get_ext(pb); - lv_pbs_t * style = lv_obj_get_style(pb); - point_t p; - char buf[LV_PB_TXT_MAX_LENGTH]; - - switch(sign) { - case LV_SIGNAL_CORD_CHG: - lv_pb_set_value(pb, ext->act_value); - break; - case LV_SIGNAL_CLEANUP: - dm_free(ext->format_str); - ext->format_str = NULL; - break; - case LV_SIGNAL_STYLE_CHG: - lv_obj_set_style(ext->label, &style->label); - lv_pb_set_value(pb, lv_pb_get_value(pb)); - break; - case LV_SIGNAL_PRESSING: - lv_dispi_get_point(param, &p); - if(lv_obj_get_width(pb) > lv_obj_get_height(pb)) { - p.x -= pb->cords.x1 + style->btn_size / 2; - ext->tmp_value = (int32_t) ((int32_t) p.x * (ext->max_value - ext->min_value + 1)) / - (lv_obj_get_width(pb) - style->btn_size); - } else { - p.y -= pb->cords.y1 + style->btn_size / 2; - ext->tmp_value = (int32_t) ((int32_t) p.y * (ext->max_value - ext->min_value + 1)) / - (lv_obj_get_height(pb) - style->btn_size); - - /*Invert the value: greater y means smaller value - * because it on a lower position on the screen*/ - ext->tmp_value = ext->max_value - ext->tmp_value; - } - - ext->tmp_value = ext->tmp_value > ext->max_value ? ext->max_value : ext->tmp_value; - ext->tmp_value = ext->tmp_value < ext->min_value ? ext->min_value : ext->tmp_value; - - sprintf(buf, ext->format_str, ext->tmp_value); - lv_label_set_text(ext->label, buf); - - lv_obj_inv(pb); - break; - case LV_SIGNAL_PRESS_LOST: - ext->tmp_value = ext->act_value; - sprintf(buf, ext->format_str, ext->act_value); - lv_label_set_text(ext->label, buf); - lv_obj_inv(pb); - break; - case LV_SIGNAL_RELEASED: - lv_pb_set_value(pb, ext->tmp_value); - break; - default: - break; - } - } - - return valid; -} - -/*===================== - * Setter functions - *====================*/ - -/** - * Set a new value on the progress bar - * @param pb pointer to a progress bar object - * @param value new value - */ -void lv_pb_set_value(lv_obj_t * pb, int16_t value) -{ - lv_pb_ext_t * ext = lv_obj_get_ext(pb); - ext->act_value = value > ext->max_value ? ext->max_value : value; - ext->act_value = ext->act_value < ext->min_value ? ext->min_value : ext->act_value; - - ext->tmp_value = ext->act_value; - char buf[LV_PB_TXT_MAX_LENGTH]; - sprintf(buf, ext->format_str, ext->act_value); - lv_label_set_text(ext->label, buf); - - lv_obj_inv(pb); -} - -/** - * Set minimum and the maximum values of a progress bar - * @param pb pointer to he progress bar object - * @param min minimum value - * @param max maximum value - */ -void lv_pb_set_min_max_value(lv_obj_t * pb, int16_t min, int16_t max) -{ - lv_pb_ext_t * ext = lv_obj_get_ext(pb); - ext->max_value = max; - ext->max_value = max; - if(ext->act_value > max) { - ext->act_value = max; - lv_pb_set_value(pb, ext->act_value); - } - lv_obj_inv(pb); -} - -/** - * Set format string for the label of the progress bar - * @param pb pointer to progress bar object - * @param format a printf-like format string with one number (e.g. "Loading (%d)") - */ -void lv_pb_set_format_str(lv_obj_t * pb, const char * format) -{ - lv_pb_ext_t * ext = lv_obj_get_ext(pb); - dm_free(ext->format_str); - ext->format_str = dm_alloc(strlen(format) + 1); - strcpy(ext->format_str, format); - lv_pb_set_value(pb, ext->act_value); -} - -/*===================== - * Getter functions - *====================*/ - -/** - * Get the value of a progress bar - * @param pb pointer to a progress bar object - * @return the value of the progress bar - */ -int16_t lv_pb_get_value(lv_obj_t * pb) -{ - lv_pb_ext_t * ext = lv_obj_get_ext(pb); - return ext->act_value; -} - -/** - * Return with a pointer to a built-in style and/or copy it to a variable - * @param style a style name from lv_pbs_builtin_t enum - * @param copy copy the style to this variable. (NULL if unused) - * @return pointer to an lv_pbs_t style - */ -lv_pbs_t * lv_pbs_get(lv_pbs_builtin_t style, lv_pbs_t * copy) -{ - static bool style_inited = false; - - /*Make the style initialization if it is not done yet*/ - if(style_inited == false) { - lv_pbs_init(); - style_inited = true; - } - - lv_pbs_t *style_p; - - switch(style) { - case LV_PBS_DEF: - style_p = &lv_pbs_def; - break; - case LV_PBS_SLIDER: - style_p = &lv_pbs_slider; - break; - default: - style_p = &lv_pbs_def; - } - - if(copy != NULL) { - if(style_p != NULL) memcpy(copy, style_p, sizeof(lv_pbs_t)); - else memcpy(copy, &lv_pbs_def, sizeof(lv_pbs_t)); - } - - return style_p; -} - -/********************** - * STATIC FUNCTIONS - **********************/ - - -/** - * Handle the drawing related tasks of the progress bars - * @param pb pointer to an object - * @param mask the object will be drawn only in this area - * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area - * (return 'true' if yes) - * LV_DESIGN_DRAW: draw the object (always return 'true') - * LV_DESIGN_DRAW_POST: drawing after every children are drawn - * @param return true/false, depends on 'mode' - */ -static bool lv_pb_design(lv_obj_t * pb, const area_t * mask, lv_design_mode_t mode) -{ - if(ancestor_design_f == NULL) return false; - - if(mode == LV_DESIGN_COVER_CHK) { - /*Return false if the object is not covers the mask_p area*/ - return ancestor_design_f(pb, mask, mode); - } else if(mode == LV_DESIGN_DRAW_MAIN) { - ancestor_design_f(pb, mask, mode); - - lv_pb_ext_t * ext = lv_obj_get_ext(pb); - lv_pbs_t * style = lv_obj_get_style(pb); - area_t bar_area; - uint32_t tmp; - area_cpy(&bar_area, &pb->cords); - - cord_t w = lv_obj_get_width(pb); - cord_t h = lv_obj_get_height(pb); - - if(w >= h) { - tmp = (int32_t)ext->tmp_value * (w - style->btn_size); - tmp = (int32_t) tmp / (ext->max_value - ext->min_value); - bar_area.x2 = bar_area.x1 + style->btn_size + (cord_t) tmp; - } else { - tmp = (int32_t)ext->tmp_value * (h - style->btn_size); - tmp = (int32_t) tmp / (ext->max_value - ext->min_value); - bar_area.y1 = bar_area.y2 - style->btn_size - (cord_t) tmp; - } - - /*Draw the main bar*/ - lv_draw_rect(&bar_area, mask, &style->bar); - - /*Draw a button if its size is not 0*/ - if(style->btn_size != 0) { - lv_rects_t tmp_rects; - memcpy(&tmp_rects, &style->btn, sizeof(lv_rects_t)); - - if(w >= h) { - bar_area.x1 = bar_area.x2 - style->btn_size ; - - if(bar_area.x1 < pb->cords.x1) { - bar_area.x1 = pb->cords.x1; - bar_area.x2 = bar_area.x1 + style->btn_size; - } - - if(bar_area.x2 > pb->cords.x2) { - bar_area.x2 = pb->cords.x2; - bar_area.x1 = bar_area.x2 - style->btn_size; - } - } else { - bar_area.y2 = bar_area.y1 + style->btn_size ; - - if(bar_area.y1 < pb->cords.y1) { - bar_area.y1 = pb->cords.y1; - bar_area.y2 = bar_area.y1 + style->btn_size; - } - - if(bar_area.y2 > pb->cords.y2) { - bar_area.y2 = pb->cords.y2; - bar_area.y1 = bar_area.y2 - style->btn_size; - } - - } - lv_draw_rect(&bar_area, mask, &tmp_rects ); - } - } - return true; -} - -/** - * Set a new temporal (ghost) value on the progress bar - * @param pb pointer to a progress bar object - * @param value new value - */ -void lv_pb_set_tmp_value(lv_obj_t * pb, int16_t value) -{ - lv_pb_ext_t * ext = lv_obj_get_ext(pb); - ext->act_value = value > ext->max_value ? ext->max_value : value; - - char buf[LV_PB_TXT_MAX_LENGTH]; - sprintf(buf, ext->format_str, ext->act_value); - lv_label_set_text(ext->label, buf); - - lv_obj_inv(pb); -} - -/** - * Initialize the progress bar styles - */ -static void lv_pbs_init(void) -{ - /*Default style*/ - lv_rects_get(LV_RECTS_PLAIN, &lv_pbs_def.bg); /*Background*/ - lv_pbs_def.bg.base.color = COLOR_WHITE; - lv_pbs_def.bg.gcolor = COLOR_SILVER, - lv_pbs_def.bg.bcolor = COLOR_BLACK; - - lv_rects_get(LV_RECTS_PLAIN, &lv_pbs_def.bar); /*Bar*/ - lv_pbs_def.bar.base.color = COLOR_LIME; - lv_pbs_def.bar.gcolor = COLOR_GREEN; - lv_pbs_def.bar.bcolor = COLOR_BLACK; - - lv_rects_get(LV_RECTS_FANCY, &lv_pbs_def.btn); /*Button*/ - lv_pbs_def.btn.base.color = COLOR_WHITE; - lv_pbs_def.btn.gcolor = COLOR_GRAY; - lv_pbs_def.btn.bcolor = COLOR_GRAY; - lv_pbs_def.btn.bopa = 100; - lv_pbs_def.btn_size = 0; - - lv_labels_get(LV_LABELS_TXT, &lv_pbs_def.label); /*Label*/ - lv_pbs_def.label.line_space = 0; - - /*Slider style*/ - memcpy(&lv_pbs_slider, &lv_pbs_def, sizeof(lv_pbs_t)); - lv_pbs_slider.bg.radius = LV_RECT_CIRCLE; - lv_pbs_slider.bar.radius = LV_RECT_CIRCLE; - lv_pbs_slider.btn.radius = LV_RECT_CIRCLE; - lv_pbs_slider.btn_size = 40 * LV_DOWNSCALE; - -} -#endif diff --git a/lv_objx/lv_rect.c b/lv_objx/lv_rect.c index bde81cacf..3c7c012e5 100644 --- a/lv_objx/lv_rect.c +++ b/lv_objx/lv_rect.c @@ -80,8 +80,8 @@ lv_obj_t * lv_rect_create(lv_obj_t * par, lv_obj_t * copy) lv_obj_alloc_ext(new_rect, sizeof(lv_rect_ext_t)); lv_rect_ext_t * ext = lv_obj_get_ext(new_rect); dm_assert(ext); - ext->hfit_en = 0; - ext->vfit_en = 0; + ext->hpad_en = 0; + ext->vpad_en = 0; ext->layout = LV_RECT_LAYOUT_OFF; lv_obj_set_design_f(new_rect, lv_rect_design); @@ -94,8 +94,8 @@ lv_obj_t * lv_rect_create(lv_obj_t * par, lv_obj_t * copy) /*Copy an existing object*/ else { lv_rect_ext_t * copy_ext = lv_obj_get_ext(copy); - ext->hfit_en = copy_ext->hfit_en; - ext->vfit_en = copy_ext->vfit_en; + ext->hpad_en = copy_ext->hpad_en; + ext->vpad_en = copy_ext->vpad_en; ext->layout = copy_ext->layout; /*Refresh the style with new signal function*/ @@ -183,8 +183,8 @@ void lv_rect_set_fit(lv_obj_t * rect, bool hor_en, bool ver_en) { lv_obj_inv(rect); lv_rect_ext_t * ext = lv_obj_get_ext(rect); - ext->hfit_en = hor_en == false ? 0 : 1; - ext->vfit_en = ver_en == false ? 0 : 1; + ext->hpad_en = hor_en == false ? 0 : 1; + ext->vpad_en = ver_en == false ? 0 : 1; /*Send a signal to set a new size*/ rect->signal_f(rect, LV_SIGNAL_CORD_CHG, rect); @@ -213,7 +213,7 @@ lv_rect_layout_t lv_rect_get_layout(lv_obj_t * rect) bool lv_rect_get_hfit(lv_obj_t * rect) { lv_rect_ext_t * ext = lv_obj_get_ext(rect); - return ext->hfit_en == 0 ? false : true; + return ext->hpad_en == 0 ? false : true; } /** @@ -224,7 +224,7 @@ bool lv_rect_get_hfit(lv_obj_t * rect) bool lv_rect_get_vfit(lv_obj_t * rect) { lv_rect_ext_t * ext = lv_obj_get_ext(rect); - return ext->vfit_en == 0 ? false : true; + return ext->vpad_en == 0 ? false : true; } @@ -673,8 +673,8 @@ static void lv_rect_refr_autofit(lv_obj_t * rect) { lv_rect_ext_t * ext = lv_obj_get_ext(rect); - if(ext->hfit_en == 0 && - ext->vfit_en == 0) { + if(ext->hpad_en == 0 && + ext->vpad_en == 0) { return; } @@ -704,14 +704,14 @@ static void lv_rect_refr_autofit(lv_obj_t * rect) /*If the value is not the init value then the page has >=1 child.*/ if(new_cords.x1 != LV_CORD_MAX) { - if(ext->hfit_en != 0) { + if(ext->hpad_en != 0) { new_cords.x1 -= hpad; new_cords.x2 += hpad; } else { new_cords.x1 = rect->cords.x1; new_cords.x2 = rect->cords.x2; } - if(ext->vfit_en != 0) { + if(ext->vpad_en != 0) { new_cords.y1 -= vpad; new_cords.y2 += vpad; } else { @@ -763,9 +763,9 @@ static void lv_rects_init(void) lv_objs_get(LV_OBJS_PLAIN, &lv_rects_fancy.base); lv_rects_fancy.gcolor = COLOR_MAKE(0xd3, 0xe1, 0xea); lv_rects_fancy.bcolor = COLOR_WHITE; - lv_rects_fancy.scolor = COLOR_GRAY; + lv_rects_fancy.scolor = COLOR_BLACK; lv_rects_fancy.bwidth = (LV_DPI / 30) == 0 ? 1 * LV_DOWNSCALE : LV_DPI / 30; - lv_rects_fancy.swidth = LV_DPI / 8; + lv_rects_fancy.swidth = LV_DPI / 6; lv_rects_fancy.bopa = OPA_50; lv_rects_fancy.radius = LV_DPI / 10; lv_rects_fancy.empty = 0; @@ -773,7 +773,6 @@ static void lv_rects_init(void) lv_rects_fancy.vpad = LV_DPI / 4; lv_rects_fancy.opad = LV_DPI / 6; - /*Transparent style*/ memcpy(&lv_rects_transp, &lv_rects_plain, sizeof(lv_rects_t)); /* Do not use opa=OPA_TRANSP because design function will not be called diff --git a/lv_objx/lv_rect.h b/lv_objx/lv_rect.h index 3a17e0108..51c66832f 100644 --- a/lv_objx/lv_rect.h +++ b/lv_objx/lv_rect.h @@ -18,7 +18,7 @@ /********************* * DEFINES *********************/ -#define LV_RECT_CIRCLE 0xFFFF /*A very big radius to always draw as circle*/ +#define LV_RECT_CIRCLE ((cord_t)-1) /*A very big radius to always draw as circle*/ /********************** * TYPEDEFS @@ -43,9 +43,9 @@ typedef struct { /*Inherited from 'base_obj' so no inherited ext. */ /*Ext. of ancestor*/ /*New data for this type */ - uint8_t layout :5; - uint8_t hfit_en :1; - uint8_t vfit_en :1; + uint8_t layout :5; /*Set a layout from 'lv_rect_layout_t' enum*/ + uint8_t hpad_en :1; /*Enable horizontal padding according to the children*/ + uint8_t vpad_en :1; /*Enable horizontal padding according to the children*/ }lv_rect_ext_t; diff --git a/lv_objx/lv_ta.c b/lv_objx/lv_ta.c index 7d7996d71..30dfef3c8 100644 --- a/lv_objx/lv_ta.c +++ b/lv_objx/lv_ta.c @@ -532,17 +532,17 @@ static bool lv_ta_scrling_design(lv_obj_t * scrling, const area_t * mask, lv_des area_t cur_area; lv_labels_t * labels_p = lv_obj_get_style(ta_ext->label); - cur_area.x1 = letter_pos.x + ta_ext->label->cords.x1 - (ta_style->cursor_width >> 1); + cur_area.x1 = letter_pos.x + ta_ext->label->cords.x1; cur_area.y1 = letter_pos.y + ta_ext->label->cords.y1; - cur_area.x2 = letter_pos.x + ta_ext->label->cords.x1 + (ta_style->cursor_width >> 1); + cur_area.x2 = letter_pos.x + ta_ext->label->cords.x1 + LV_DOWNSCALE ; cur_area.y2 = letter_pos.y + ta_ext->label->cords.y1 + (font_get_height(labels_p->font) >> LV_FONT_ANTIALIAS); lv_rects_t cur_rects; lv_rects_get(LV_RECTS_PLAIN, &cur_rects); cur_rects.radius = 0; cur_rects.bwidth = 0; - cur_rects.base.color = ta_style->cursor_color; - cur_rects.gcolor = ta_style->cursor_color; + cur_rects.base.color = ta_style->label.base.color; + cur_rects.gcolor = ta_style->label.base.color; lv_draw_rect(&cur_area, mask, &cur_rects); } } @@ -588,8 +588,7 @@ static void lv_tas_init(void) lv_labels_get(LV_LABELS_TXT, &lv_tas_def.label); - lv_tas_def.cursor_color = COLOR_MAKE(0x10, 0x10, 0x10); - lv_tas_def.cursor_width = 1 * LV_DOWNSCALE; /*>=1 px for visible cursor*/ + lv_tas_def.label.base.color = COLOR_MAKE(0x10, 0x10, 0x10); lv_tas_def.cursor_show = 1; } diff --git a/lv_objx/lv_ta.h b/lv_objx/lv_ta.h index 6af19129f..412b12e56 100644 --- a/lv_objx/lv_ta.h +++ b/lv_objx/lv_ta.h @@ -50,10 +50,8 @@ typedef struct { lv_pages_t page; /*Style of ancestor*/ /*New style element for this type */ - lv_labels_t label; - color_t cursor_color; - cord_t cursor_width; - uint8_t cursor_show :1; + lv_labels_t label; /*Style of the label*/ + uint8_t cursor_show :1; /*Flag to indicate the cursor is now being shown or not (Handled by the library)*/ }lv_tas_t; /*Built-in styles of text area*/ diff --git a/lvgl.h b/lvgl.h index 12fac2b0f..f73b0848b 100644 --- a/lvgl.h +++ b/lvgl.h @@ -38,7 +38,8 @@ #include "lv_objx/lv_list.h" #include "lv_objx/lv_chart.h" #include "lv_objx/lv_cb.h" -#include "lv_objx/lv_pb.h" +#include "lv_objx/lv_bar.h" +#include "lv_objx/lv_slider.h" #include "lv_objx/lv_led.h" #include "lv_objx/lv_btnm.h" #include "lv_objx/lv_ddlist.h"