From 2965b351a5ec309b4528f1ca43a4f2c90a528053 Mon Sep 17 00:00:00 2001 From: Gabor Date: Fri, 18 Aug 2017 17:43:14 +0200 Subject: [PATCH 01/13] lv_sw: skeleton added --- lv_objx/lv_sw.c | 166 ++++++++++++++++++++++++++++++++++++++++++++++++ lv_objx/lv_sw.h | 74 +++++++++++++++++++++ 2 files changed, 240 insertions(+) create mode 100644 lv_objx/lv_sw.c create mode 100644 lv_objx/lv_sw.h diff --git a/lv_objx/lv_sw.c b/lv_objx/lv_sw.c new file mode 100644 index 000000000..3ee6b7287 --- /dev/null +++ b/lv_objx/lv_sw.c @@ -0,0 +1,166 @@ +/** + * @file lv_templ.c + * + */ + +/*Search an replace: template -> object normal name with lower case (e.g. button, label etc.) + * templ -> object short name with lower case(e.g. btn, label etc) + * TEMPL -> object short name with upper case (e.g. BTN, LABEL etc.) + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_conf.h" +#if USE_LV_TEMPL != 0 + +#include "lv_templ.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static bool lv_templ_design(lv_obj_t * templ, const area_t * mask, lv_design_mode_t mode); + +/********************** + * STATIC VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/*----------------- + * Create function + *-----------------*/ + +/** + * Create a template objects + * @param par pointer to an object, it will be the parent of the new template + * @param copy pointer to a template object, if not NULL then the new object will be copied from it + * @return pointer to the created template + */ +lv_obj_t * lv_templ_create(lv_obj_t * par, lv_obj_t * copy) +{ + /*Create the ancestor of template*/ + /*TODO modify it to the ancestor create function */ + lv_obj_t * new_templ = lv_ANCESTOR_create(par, copy); + dm_assert(new_templ); + + /*Allocate the template type specific extended data*/ + lv_templ_ext_t * ext = lv_obj_alloc_ext(new_templ, sizeof(lv_templ_ext_t)); + dm_assert(ext); + + /*Initialize the allocated 'ext' */ + ext->xyz = 0; + + /*The signal and design functions are not copied so set them here*/ + lv_obj_set_signal_f(new_templ, lv_templ_signal); + lv_obj_set_design_f(new_templ, lv_templ_design); + + /*Init the new template template*/ + if(copy == NULL) { + lv_obj_set_style(new_templ, lv_style_get(LV_STYLE_PRETTY, NULL)); + } + /*Copy an existing template*/ + else { + lv_templ_ext_t * copy_ext = lv_obj_get_ext(copy); + + /*Refresh the style with new signal function*/ + lv_obj_refr_style(new_templ); + } + + return new_templ; +} + +/** + * Signal function of the template + * @param templ pointer to a template object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return true: the object is still valid (not deleted), false: the object become invalid + */ +bool lv_templ_signal(lv_obj_t * templ, lv_signal_t sign, void * param) +{ + bool valid; + + /* Include the ancient signal function */ + /* TODO update it to the ancestor's signal function*/ + valid = lv_ANCESTOR_signal(templ, sign, param); + + /* The object can be deleted so check its validity and then + * make the object specific signal handling */ + if(valid != false) { + if(sign == LV_SIGNAL_CLEANUP) { + /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/ + } + } + + return valid; +} + +/*===================== + * Setter functions + *====================*/ + +/* + * New object specific "set" function comes here + */ + + +/*===================== + * Getter functions + *====================*/ + +/* + * New object specific "get" function comes here + */ + + +/********************** + * STATIC FUNCTIONS + **********************/ + + +/** + * Handle the drawing related tasks of the templates + * @param templ 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_templ_design(lv_obj_t * templ, const area_t * mask, lv_design_mode_t mode) +{ + /*Return false if the object is not covers the mask_p area*/ + if(mode == LV_DESIGN_COVER_CHK) { + return false; + } + /*Draw the object*/ + else if(mode == LV_DESIGN_DRAW_MAIN) { + + } + /*Post draw when the children are drawn*/ + else if(mode == LV_DESIGN_DRAW_POST) { + + } + + return true; +} + + +#endif diff --git a/lv_objx/lv_sw.h b/lv_objx/lv_sw.h new file mode 100644 index 000000000..1646e288b --- /dev/null +++ b/lv_objx/lv_sw.h @@ -0,0 +1,74 @@ +/** + * @file lv_sw.h + * + */ + + +/*Search an replace: switch -> object normal name with lower case (e.g. button, label etc.) + * sw -> object short name with lower case(e.g. btn, label etc) + * SW -> object short name with upper case (e.g. BTN, LABEL etc.) + * + */ + +#ifndef LV_SW_H +#define LV_SW_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_conf.h" +#if USE_LV_SW != 0 + +#include "../lv_obj/lv_obj.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +/*Data of switch*/ +typedef struct +{ + /*Ext. of ancestor*/ + /*New data for this type */ +}lv_sw_ext_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a switch objects + * @param par pointer to an object, it will be the parent of the new switch + * @param copy pointer to a switch object, if not NULL then the new object will be copied from it + * @return pointer to the created switch + */ +lv_obj_t * lv_sw_create(lv_obj_t * par, lv_obj_t * copy); + +/** + * Signal function of the switch + * @param sw pointer to a switch object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return true: the object is still valid (not deleted), false: the object become invalid + */ +bool lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param); + + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_SW*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_SW_H*/ From 61c5777a6b3094e315e45d36cfbd8899601daeab Mon Sep 17 00:00:00 2001 From: Gabor Date: Fri, 18 Aug 2017 21:11:22 +0200 Subject: [PATCH 02/13] lv_slider: knob_in + handle negative hpad/vpad to make bigger bg. then knob --- lv_objx/lv_slider.c | 75 +++++++++++++++++++++++++++++++++++++-------- lv_objx/lv_slider.h | 17 ++++++++++ 2 files changed, 80 insertions(+), 12 deletions(-) diff --git a/lv_objx/lv_slider.c b/lv_objx/lv_slider.c index 4eaec2bb5..500088cd9 100644 --- a/lv_objx/lv_slider.c +++ b/lv_objx/lv_slider.c @@ -65,6 +65,7 @@ lv_obj_t * lv_slider_create(lv_obj_t * par, lv_obj_t * copy) ext->cb = NULL; ext->tmp_value = ext->bar.min_value; ext->style_knob = lv_style_get(LV_STYLE_PRETTY, NULL); + ext->knob_in = 0; /* Save the bar design function. * It will be used in the sllider design function*/ @@ -84,6 +85,7 @@ lv_obj_t * lv_slider_create(lv_obj_t * par, lv_obj_t * copy) lv_slider_ext_t * copy_ext = lv_obj_get_ext(copy); ext->style_knob = copy_ext->style_knob; ext->cb = copy_ext->cb; + ext->knob_in = copy_ext->knob_in; /*Refresh the style with new signal function*/ lv_obj_refr_style(new_slider); } @@ -120,11 +122,13 @@ bool lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * param) else if(sign == LV_SIGNAL_PRESSING) { lv_dispi_get_point(param, &p); if(w > h) { + cord_t knob_w = h; p.x -= slider->cords.x1 + h / 2; /*Modify the point to shift with half knob (important on the start and end)*/ - tmp = (int32_t) ((int32_t) p.x * (ext->bar.max_value - ext->bar.min_value + 1)) / (w - h); + tmp = (int32_t) ((int32_t) p.x * (ext->bar.max_value - ext->bar.min_value + 1)) / (w - knob_w); } else { + cord_t knob_h = w; p.y -= slider->cords.y1 + w / 2; /*Modify the point to shift with half knob (important on the start and end)*/ - tmp = (int32_t) ((int32_t) p.y * (ext->bar.max_value - ext->bar.min_value + 1)) / (h - w); + tmp = (int32_t) ((int32_t) p.y * (ext->bar.max_value - ext->bar.min_value + 1)) / (h - knob_h); tmp = ext->bar.max_value - tmp; /*Invert he value: small value means higher y*/ } @@ -146,8 +150,18 @@ bool lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * param) slider->signal_f(slider, LV_SIGNAL_REFR_EXT_SIZE, NULL); } } else if(sign == LV_SIGNAL_REFR_EXT_SIZE) { - cord_t x = MATH_MIN(w, h); - if(slider->ext_size < x) slider->ext_size = x; + if(ext->knob_in == 0) { + cord_t x = MATH_MIN(w, h); /*The smaller size is the knob diameter*/ + if(slider->ext_size < x) slider->ext_size = x; + } else { + lv_style_t * style = lv_obj_get_style(slider); + cord_t pad = MATH_MIN(style->hpad, style->vpad); + if(pad < 0) { + pad = -pad; + if(slider->ext_size < pad) slider->ext_size = pad; + } + + } } else if(sign == LV_SIGNAL_CONTROLL) { lv_slider_ext_t * ext = lv_obj_get_ext(slider); char c = *((char*)param); @@ -194,6 +208,17 @@ void lv_slider_set_style_knob(lv_obj_t * slider, lv_style_t * style) lv_obj_inv(slider); } +/** + * Set the 'knob in' attribute of a slider + * @param slider pointer to slider object + * @param in true: the knob is drawn always in the slider; + * false: the knob can be out on the edges + */ +void lv_slider_set_knob_in(lv_obj_t * slider, bool in) +{ + lv_slider_ext_t * ext = lv_obj_get_ext(slider); + ext->knob_in = in == false ? 0 : 1; +} /*===================== * Getter functions @@ -220,6 +245,18 @@ lv_style_t * lv_slider_get_style_knob(lv_obj_t * slider) return ext->style_knob; } +/** + * Get the 'knob in' attribute of a slider + * @param slider pointer to slider object + * @return true: the knob is drawn always in the slider; + * false: the knob can be out on the edges + */ +bool lv_slider_get_knob_in(lv_obj_t * slider) +{ + lv_slider_ext_t * ext = lv_obj_get_ext(slider); + return ext->knob_in == 0 ? false : true; +} + /********************** * STATIC FUNCTIONS **********************/ @@ -243,6 +280,8 @@ static bool lv_slider_design(lv_obj_t * slider, const area_t * mask, lv_design_m } /*Draw the object*/ else if(mode == LV_DESIGN_DRAW_MAIN) { + lv_slider_ext_t * ext = lv_obj_get_ext(slider); + lv_style_t * style_slider = lv_obj_get_style(slider); lv_style_t * style_knob = lv_slider_get_style_knob(slider); lv_style_t * style_indic = lv_bar_get_style_indic(slider); @@ -251,8 +290,8 @@ static bool lv_slider_design(lv_obj_t * slider, const area_t * mask, lv_design_m area_t area_bar; area_cpy(&area_bar, &slider->cords); /*Be sure at least vpad/hpad width bar will remain*/ - cord_t vpad_bar = style_indic->vpad; - cord_t hpad_bar = style_indic->hpad; + cord_t vpad_bar = style_slider->vpad; + cord_t hpad_bar = style_slider->hpad; if(vpad_bar * 2 + LV_SLIDER_SIZE_MIN > area_get_height(&area_bar)) { vpad_bar = (area_get_height(&area_bar) - LV_SLIDER_SIZE_MIN) >> 1; } @@ -295,27 +334,39 @@ static bool lv_slider_design(lv_obj_t * slider, const area_t * mask, lv_design_m if(slider_w >= slider_h) { area_indic.x2 = (int32_t) ((int32_t)area_get_width(&area_indic) * act_value) / (max_value - min_value); area_indic.x2 += area_indic.x1; + } else { area_indic.y1 = (int32_t) ((int32_t)area_get_height(&area_indic) * act_value) / (max_value - min_value); area_indic.y1 = area_indic.y2 - area_indic.y1; } /*Draw the indicator*/ - lv_draw_rect(&area_indic, mask, style_indic); + if(act_value != min_value) lv_draw_rect(&area_indic, mask, style_indic); area_t knob_area; area_cpy(&knob_area, &slider->cords); if(slider_w >= slider_h) { - knob_area.x1 = area_indic.x2 - slider_h / 2; - knob_area.x2 = knob_area.x1 + slider_h; + if(ext->knob_in == 0) { + knob_area.x1 = area_indic.x2 - slider_h / 2; + knob_area.x2 = knob_area.x1 + slider_h; + } else { + knob_area.x1 = (int32_t) ((int32_t)(slider_w - slider_h) * act_value) / (max_value - min_value); + knob_area.x1 += slider->cords.x1; + knob_area.x2 = knob_area.x1 + slider_h; + } knob_area.y1 = slider->cords.y1; knob_area.y2 = slider->cords.y2; } else { - knob_area.y1 = area_indic.y1 - slider_w / 2; - knob_area.y2 = knob_area.y1 + slider_w; - + if(ext->knob_in == 0) { + knob_area.y1 = area_indic.y1 - slider_w / 2; + knob_area.y2 = knob_area.y1 + slider_w; + } else { + knob_area.y2 = (int32_t) ((int32_t)(slider_h - slider_w) * act_value) / (max_value - min_value); + knob_area.y2 = slider->cords.y2 - knob_area.y2; + knob_area.y1 = knob_area.y2 - slider_w; + } knob_area.x1 = slider->cords.x1; knob_area.x2 = slider->cords.x2; diff --git a/lv_objx/lv_slider.h b/lv_objx/lv_slider.h index b9f277980..946a50517 100644 --- a/lv_objx/lv_slider.h +++ b/lv_objx/lv_slider.h @@ -34,6 +34,7 @@ typedef struct lv_action_t cb; /*Function to call when a new value is set*/ lv_style_t * style_knob; /*Style of the knob*/ int16_t tmp_value; /*Store a temporal value during press until release (Handled by the library)*/ + uint8_t knob_in :1; /*1: Draw the knob inside the bar*/ }lv_slider_ext_t; /*Built-in styles of slider*/ @@ -77,6 +78,14 @@ void lv_slider_set_action(lv_obj_t * slider, lv_action_t cb); */ void lv_slider_set_style_knob(lv_obj_t * slider, lv_style_t * style); +/** + * Set the 'knob in' attribute of a slider + * @param slider pointer to slider object + * @param in true: the knob is drawn always in the slider; + * false: the knob can be out on the edges + */ +void lv_slider_set_knob_in(lv_obj_t * slider, bool in); + /** * Get the slider callback function * @param slider pointer to slider object @@ -91,6 +100,14 @@ lv_action_t lv_slider_get_action(lv_obj_t * slider); */ lv_style_t * lv_slider_get_style_knob(lv_obj_t * slider); +/** + * Get the 'knob in' attribute of a slider + * @param slider pointer to slider object + * @return true: the knob is drawn always in the slider; + * false: the knob can be out on the edges + */ +bool lv_slider_get_knob_in(lv_obj_t * slider); + /********************** * MACROS **********************/ From 237edae7df7a697e586ab484ba21d9dcf5bf9d8b Mon Sep 17 00:00:00 2001 From: Gabor Date: Fri, 18 Aug 2017 21:14:11 +0200 Subject: [PATCH 03/13] lv_sw: all feature is working --- lv_conf_templ.h | 3 ++ lv_objx/lv_sw.c | 102 +++++++++++++++++++++++++++++------------------- lv_objx/lv_sw.h | 16 ++++---- lvgl.h | 1 + 4 files changed, 73 insertions(+), 49 deletions(-) diff --git a/lv_conf_templ.h b/lv_conf_templ.h index 86d23f61d..8082ef48f 100644 --- a/lv_conf_templ.h +++ b/lv_conf_templ.h @@ -146,6 +146,9 @@ /*Check box (dependencies: lv_btn, lv_label)*/ #define USE_LV_CB 1 +/*Switch (dependencies: lv_slider)*/ +#define USE_LV_SW 1 + /*List (dependencies: lv_page, lv_btn, lv_label, lv_img)*/ #define USE_LV_LIST 1 #if USE_LV_LIST != 0 diff --git a/lv_objx/lv_sw.c b/lv_objx/lv_sw.c index 3ee6b7287..85572117c 100644 --- a/lv_objx/lv_sw.c +++ b/lv_objx/lv_sw.c @@ -1,21 +1,15 @@ /** - * @file lv_templ.c + * @file lv_sw.c * */ -/*Search an replace: template -> object normal name with lower case (e.g. button, label etc.) - * templ -> object short name with lower case(e.g. btn, label etc) - * TEMPL -> object short name with upper case (e.g. BTN, LABEL etc.) - * - */ - /********************* * INCLUDES *********************/ #include "lv_conf.h" -#if USE_LV_TEMPL != 0 +#if USE_LV_SW != 0 -#include "lv_templ.h" +#include "lv_sw.h" /********************* * DEFINES @@ -28,8 +22,9 @@ /********************** * STATIC PROTOTYPES **********************/ -static bool lv_templ_design(lv_obj_t * templ, const area_t * mask, lv_design_mode_t mode); - +#if 0 /*Slider design is used*/ +static bool lv_sw_design(lv_obj_t * sw, const area_t * mask, lv_design_mode_t mode); +#endif /********************** * STATIC VARIABLES **********************/ @@ -47,58 +42,63 @@ static bool lv_templ_design(lv_obj_t * templ, const area_t * mask, lv_design_mod *-----------------*/ /** - * Create a template objects - * @param par pointer to an object, it will be the parent of the new template - * @param copy pointer to a template object, if not NULL then the new object will be copied from it - * @return pointer to the created template + * Create a switch objects + * @param par pointer to an object, it will be the parent of the new switch + * @param copy pointer to a switch object, if not NULL then the new object will be copied from it + * @return pointer to the created switch */ -lv_obj_t * lv_templ_create(lv_obj_t * par, lv_obj_t * copy) +lv_obj_t * lv_sw_create(lv_obj_t * par, lv_obj_t * copy) { - /*Create the ancestor of template*/ - /*TODO modify it to the ancestor create function */ - lv_obj_t * new_templ = lv_ANCESTOR_create(par, copy); - dm_assert(new_templ); + /*Create the ancestor of switch*/ + lv_obj_t * new_sw = lv_slider_create(par, copy); + dm_assert(new_sw); - /*Allocate the template type specific extended data*/ - lv_templ_ext_t * ext = lv_obj_alloc_ext(new_templ, sizeof(lv_templ_ext_t)); + /*Allocate the switch type specific extended data*/ + lv_sw_ext_t * ext = lv_obj_alloc_ext(new_sw, sizeof(lv_sw_ext_t)); dm_assert(ext); /*Initialize the allocated 'ext' */ - ext->xyz = 0; + ext->changed = 0; /*The signal and design functions are not copied so set them here*/ - lv_obj_set_signal_f(new_templ, lv_templ_signal); - lv_obj_set_design_f(new_templ, lv_templ_design); + lv_obj_set_signal_f(new_sw, lv_sw_signal); - /*Init the new template template*/ + /*Init the new switch switch*/ if(copy == NULL) { - lv_obj_set_style(new_templ, lv_style_get(LV_STYLE_PRETTY, NULL)); + lv_bar_set_range(new_sw, 0, 1); + lv_obj_set_size(new_sw, LV_DPI, LV_DPI / 2); + lv_slider_set_knob_in(new_sw, true); } - /*Copy an existing template*/ + /*Copy an existing switch*/ else { - lv_templ_ext_t * copy_ext = lv_obj_get_ext(copy); + /*Nothing to copy*/ /*Refresh the style with new signal function*/ - lv_obj_refr_style(new_templ); + lv_obj_refr_style(new_sw); } - return new_templ; + return new_sw; } /** - * Signal function of the template - * @param templ pointer to a template object + * Signal function of the switch + * @param sw pointer to a switch object * @param sign a signal type from lv_signal_t enum * @param param pointer to a signal specific variable * @return true: the object is still valid (not deleted), false: the object become invalid */ -bool lv_templ_signal(lv_obj_t * templ, lv_signal_t sign, void * param) +bool lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param) { bool valid; + lv_sw_ext_t * ext = lv_obj_get_ext(sw); + int16_t old_val = lv_bar_get_value(sw); + + lv_action_t slider_cb = ext->slider.cb; + ext->slider.cb = NULL; /*Do not let the slider to call the callback. The Switch will do it*/ + /* Include the ancient signal function */ - /* TODO update it to the ancestor's signal function*/ - valid = lv_ANCESTOR_signal(templ, sign, param); + valid = lv_slider_signal(sw, sign, param); /* The object can be deleted so check its validity and then * make the object specific signal handling */ @@ -106,8 +106,28 @@ bool lv_templ_signal(lv_obj_t * templ, lv_signal_t sign, void * param) if(sign == LV_SIGNAL_CLEANUP) { /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/ } + else if(sign == LV_SIGNAL_PRESSING) { + int16_t act_val = lv_bar_get_value(sw); + if(act_val != old_val) ext->changed = 1; + } + else if(sign == LV_SIGNAL_PRESS_LOST) { + ext->changed = 0; + } + else if(sign == LV_SIGNAL_RELEASED) { + if(ext->changed == 0) { + int16_t v = lv_bar_get_value(sw); + if(v == 0) lv_bar_set_value(sw, 1); + else lv_bar_set_value(sw, 0); + } + if(slider_cb != NULL) slider_cb(sw, param); + + ext->changed = 0; + } } + /*Restore the callback*/ + ext->slider.cb = slider_cb; + return valid; } @@ -133,10 +153,10 @@ bool lv_templ_signal(lv_obj_t * templ, lv_signal_t sign, void * param) * STATIC FUNCTIONS **********************/ - +#if 0 /*Slider design is used*/ /** - * Handle the drawing related tasks of the templates - * @param templ pointer to an object + * Handle the drawing related tasks of the switchs + * @param sw 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) @@ -144,7 +164,7 @@ bool lv_templ_signal(lv_obj_t * templ, lv_signal_t sign, void * param) * LV_DESIGN_DRAW_POST: drawing after every children are drawn * @param return true/false, depends on 'mode' */ -static bool lv_templ_design(lv_obj_t * templ, const area_t * mask, lv_design_mode_t mode) +static bool lv_sw_design(lv_obj_t * sw, const area_t * mask, lv_design_mode_t mode) { /*Return false if the object is not covers the mask_p area*/ if(mode == LV_DESIGN_COVER_CHK) { @@ -161,6 +181,6 @@ static bool lv_templ_design(lv_obj_t * templ, const area_t * mask, lv_design_mod return true; } - +#endif #endif diff --git a/lv_objx/lv_sw.h b/lv_objx/lv_sw.h index 1646e288b..d5b6b718c 100644 --- a/lv_objx/lv_sw.h +++ b/lv_objx/lv_sw.h @@ -3,13 +3,6 @@ * */ - -/*Search an replace: switch -> object normal name with lower case (e.g. button, label etc.) - * sw -> object short name with lower case(e.g. btn, label etc) - * SW -> object short name with upper case (e.g. BTN, LABEL etc.) - * - */ - #ifndef LV_SW_H #define LV_SW_H @@ -23,7 +16,13 @@ extern "C" { #include "lv_conf.h" #if USE_LV_SW != 0 +/*Testing of dependencies*/ +#if USE_LV_SW == 0 +#error "lv_sw: lv_slider is required. Enable it in lv_conf.h (USE_LV_SLIDER 1)" +#endif + #include "../lv_obj/lv_obj.h" +#include "lv_slider.h" /********************* * DEFINES @@ -35,8 +34,9 @@ extern "C" { /*Data of switch*/ typedef struct { - /*Ext. of ancestor*/ + lv_slider_ext_t slider; /*Ext. of ancestor*/ /*New data for this type */ + uint8_t changed :1; /*Indicates the switch explicitly changed by drag*/ }lv_sw_ext_t; /********************** diff --git a/lvgl.h b/lvgl.h index 1e1b90880..9f16d56e2 100644 --- a/lvgl.h +++ b/lvgl.h @@ -37,6 +37,7 @@ extern "C" { #include "lv_objx/lv_mbox.h" #include "lv_objx/lv_gauge.h" #include "lv_objx/lv_lmeter.h" +#include "lv_objx/lv_sw.h" #include "lv_app/lv_app.h" From 3980f084401ad2965f68ef4a3c19e1e7d0b125c1 Mon Sep 17 00:00:00 2001 From: Gabor Date: Sun, 20 Aug 2017 02:16:21 +0200 Subject: [PATCH 04/13] lv_btnm: add lv_btnm_set_tgl() --- lv_objx/lv_btnm.c | 56 ++++++++++++++++++++++++++++++++++++++++++----- lv_objx/lv_btnm.h | 12 ++++++++++ 2 files changed, 63 insertions(+), 5 deletions(-) diff --git a/lv_objx/lv_btnm.c b/lv_objx/lv_btnm.c index e07eb1dee..aa19d5097 100644 --- a/lv_objx/lv_btnm.c +++ b/lv_objx/lv_btnm.c @@ -70,11 +70,15 @@ lv_obj_t * lv_btnm_create(lv_obj_t * par, lv_obj_t * copy) dm_assert(ext); ext->btn_cnt = 0; ext->btn_pr = LV_BTNM_PR_NONE; + ext->btn_tgl = LV_BTNM_PR_NONE; ext->btn_areas = NULL; ext->cb = NULL; ext->map_p = NULL; ext->style_btn_rel = lv_style_get(LV_STYLE_BTN_REL, NULL); ext->style_btn_pr = lv_style_get(LV_STYLE_BTN_PR, NULL); + ext->style_btn_trel = lv_style_get(LV_STYLE_BTN_TREL, NULL); + ext->style_btn_tpr = lv_style_get(LV_STYLE_BTN_TPR, NULL); + ext->tgl = 0; if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_f(new_btnm); @@ -84,7 +88,7 @@ lv_obj_t * lv_btnm_create(lv_obj_t * par, lv_obj_t * copy) /*Init the new button matrix object*/ if(copy == NULL) { lv_obj_set_size(new_btnm, LV_HOR_RES, LV_VER_RES / 2); - lv_obj_set_style(new_btnm, lv_style_get(LV_STYLE_PLAIN, NULL)); + lv_obj_set_style(new_btnm, lv_style_get(LV_STYLE_PRETTY, NULL)); lv_btnm_set_map(new_btnm, lv_btnm_def_map); } /*Copy an existing object*/ @@ -162,7 +166,7 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param) } if(sign == LV_SIGNAL_RELEASED && ext->btn_pr != LV_BTNM_PR_NONE) { - /*Invalidate to old area*/; + /*Invalidate to old pressed area*/; lv_obj_get_cords(btnm, &btnm_area); area_cpy(&btn_area, &ext->btn_areas[ext->btn_pr]); btn_area.x1 += btnm_area.x1; @@ -171,6 +175,18 @@ 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(ext->tgl != 0) { + /*Invalidate to old toggled area*/; + area_cpy(&btn_area, &ext->btn_areas[ext->btn_tgl]); + btn_area.x1 += btnm_area.x1; + btn_area.y1 += btnm_area.y1; + btn_area.x2 += btnm_area.x1; + btn_area.y2 += btnm_area.y1; + lv_inv_area(&btn_area); + + ext->btn_tgl = ext->btn_pr; + } + ext->btn_pr = LV_BTNM_PR_NONE; } } else if(sign == LV_SIGNAL_PRESS_LOST || sign == LV_SIGNAL_DEFOCUS) { @@ -314,7 +330,28 @@ void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_callback_t cb) } /** - * Set the styles of the buttons of the button matrox + * Enable or disable button toggling + * @param btnm pointer to button matrix object + * @param en true: enable toggling; false: disable toggling + * @param id index of the currently toggled button (ignored if 'en' == false) + */ +void lv_btnm_set_tgl(lv_obj_t * btnm, bool en, uint16_t id) +{ + lv_btnm_ext_t * ext = lv_obj_get_ext(btnm); + + ext->tgl = en == false ? 0 : 1; + if(ext->tgl != 0) { + if(id > ext->btn_cnt) id = LV_BTNM_PR_NONE; + ext->btn_tgl = id; + } else { + ext->btn_tgl = LV_BTNM_PR_NONE; + } + + lv_obj_inv(btnm); +} + +/** + * Set the styles of the buttons of the button matrix * @param btnm pointer to a button matrix object * @param state style in this state (LV_BTN_STATE_PR or LV_BTN_STATE_REL) * @param style pointer to style @@ -373,6 +410,12 @@ lv_style_t * lv_btnm_get_style_btn(lv_obj_t * btnm, lv_btn_state_t state) case LV_BTN_STATE_REL: style = ext->style_btn_rel; break; + case LV_BTN_STATE_TPR: + style = ext->style_btn_tpr; + break; + case LV_BTN_STATE_TREL: + style = ext->style_btn_trel; + break; default: style = NULL; } @@ -420,7 +463,7 @@ static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_ /*Search the next valid text in the map*/ while(strcmp(ext->map_p[txt_i], "\n") == 0) txt_i ++; - if(ext->map_p[txt_i][1] == '\177') continue; + if(ext->map_p[txt_i][1] == '\177' || ext->map_p[txt_i][0] == '\177') continue; lv_obj_get_cords(btnm, &area_btnm); @@ -434,7 +477,10 @@ static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_ btn_h = area_get_height(&area_tmp); /*Load the style*/ - btn_style = lv_btnm_get_style_btn(btnm, ext->btn_pr == btn_i ? LV_BTN_STATE_PR : LV_BTN_STATE_REL); + if(btn_i != ext->btn_pr && btn_i != ext->btn_tgl) btn_style = lv_btnm_get_style_btn(btnm, LV_BTN_STATE_REL); + else if(btn_i == ext->btn_pr && btn_i != ext->btn_tgl) btn_style = lv_btnm_get_style_btn(btnm, LV_BTN_STATE_PR); + else if(btn_i != ext->btn_pr && btn_i == ext->btn_tgl) btn_style = lv_btnm_get_style_btn(btnm, LV_BTN_STATE_TREL); + else if(btn_i == ext->btn_pr && btn_i == ext->btn_tgl) btn_style = lv_btnm_get_style_btn(btnm, LV_BTN_STATE_TPR); lv_draw_rect(&area_tmp, mask, btn_style); diff --git a/lv_objx/lv_btnm.h b/lv_objx/lv_btnm.h index fe7f24628..d43a63d93 100644 --- a/lv_objx/lv_btnm.h +++ b/lv_objx/lv_btnm.h @@ -43,9 +43,13 @@ typedef struct 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)*/ + uint16_t btn_tgl; /*Index of the currently toggled 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_style_t * style_btn_rel; /*Style of the released buttons*/ lv_style_t * style_btn_pr; /*Style of the pressed buttons*/ + lv_style_t * style_btn_trel; /*Style of the released buttons*/ + lv_style_t * style_btn_tpr; /*Style of the pressed buttons*/ + uint8_t tgl :1; /*Enable toggling*/ }lv_btnm_ext_t; /********************** @@ -88,6 +92,14 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map); */ void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_callback_t cb); +/** + * Enable or disable button toggling + * @param btnm pointer to button matrix object + * @param en true: enable toggling; false: disable toggling + * @param id index of the currently toggled button (ignored if 'en' == false) + */ +void lv_btnm_set_tgl(lv_obj_t * btnm, bool en, uint16_t id); + /** * Set the styles of the buttons of the button matrox * @param btnm pointer to a button matrix object From 3a4463d2e424407d0d952b5615ecc8ba04c39d75 Mon Sep 17 00:00:00 2001 From: Gabor Date: Mon, 21 Aug 2017 14:41:28 +0200 Subject: [PATCH 05/13] lv_tab: all working, API not ready --- lv_objx/lv_tab.c | 422 +++++++++++++++++++++++++++++++++++++++++++++++ lv_objx/lv_tab.h | 84 ++++++++++ 2 files changed, 506 insertions(+) create mode 100644 lv_objx/lv_tab.c create mode 100644 lv_objx/lv_tab.h diff --git a/lv_objx/lv_tab.c b/lv_objx/lv_tab.c new file mode 100644 index 000000000..62557bb51 --- /dev/null +++ b/lv_objx/lv_tab.c @@ -0,0 +1,422 @@ +/** + * @file lv_tab.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_conf.h" +#if USE_LV_TAB != 0 + +#include "lv_tab.h" +#include "lv_btnm.h" +#include "misc/gfx/anim.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static bool lv_tab_design(lv_obj_t * tab, const area_t * mask, lv_design_mode_t mode); + +static bool lv_tab_page_signal(lv_obj_t * tab_page, lv_signal_t sign, void * param); +static bool lv_tab_scrl_signal(lv_obj_t * tab_scrl, lv_signal_t sign, void * param); + +static void page_pressed_hadler(lv_obj_t * tab, lv_dispi_t * dispi); +static void page_pressing_hadler(lv_obj_t * tab, lv_obj_t * tab_page, lv_dispi_t * dispi); +static void page_press_lost_hadler(lv_obj_t * tab, lv_obj_t * tab_page, lv_dispi_t * dispi); +static lv_action_res_t tab_btnm_action(lv_obj_t * tab_btnm, uint16_t id); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_signal_f_t page_scrl_signal; +static const char * tab_def[] = {""}; +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/*----------------- + * Create function + *-----------------*/ + +/** + * Create a tab objects + * @param par pointer to an object, it will be the parent of the new tab + * @param copy pointer to a tab object, if not NULL then the new object will be copied from it + * @return pointer to the created tab + */ +lv_obj_t * lv_tab_create(lv_obj_t * par, lv_obj_t * copy) +{ + /*Create the ancestor of tab*/ + lv_obj_t * new_tab = lv_obj_create(par, copy); + dm_assert(new_tab); + + /*Allocate the tab type specific extended data*/ + lv_tab_ext_t * ext = lv_obj_alloc_ext(new_tab, sizeof(lv_tab_ext_t)); + dm_assert(ext); + + /*Initialize the allocated 'ext' */ + ext->drag_h = 0; + ext->draging = 0; + ext->tab_act = 0; + ext->point_last.x = 0; + ext->point_last.y = 0; + ext->content = NULL; + ext->indic = NULL; + ext->tabs = NULL; + ext->tab_name_ptr = dm_alloc(sizeof(char*)); + ext->tab_name_ptr[0] = ""; + + /*The signal and design functions are not copied so set them here*/ + lv_obj_set_signal_f(new_tab, lv_tab_signal); + + /*Init the new tab tab*/ + if(copy == NULL) { + lv_obj_set_size(new_tab, LV_HOR_RES, LV_VER_RES); + lv_obj_set_style(new_tab, lv_style_get(LV_STYLE_PRETTY, NULL)); + + ext->tabs = lv_btnm_create(new_tab, NULL); + lv_btnm_set_map(ext->tabs, tab_def); + lv_obj_set_height(ext->tabs, 3 * LV_DPI / 4); + lv_btnm_set_action(ext->tabs, tab_btnm_action); + lv_btnm_set_tgl(ext->tabs, true, 0); + + ext->indic = lv_obj_create(ext->tabs, NULL); + lv_style_t * style_indic = lv_obj_get_style(ext->indic); + lv_obj_set_size(ext->indic, LV_DPI, style_indic->line_width); + + ext->content = lv_cont_create(new_tab, NULL); + lv_cont_set_fit(ext->content, true, false); + lv_cont_set_layout(ext->content, LV_CONT_LAYOUT_ROW_T); + lv_obj_set_height(ext->content, LV_VER_RES); + lv_obj_set_style(ext->content, lv_style_get(LV_STYLE_TRANSP_TIGHT, NULL)); + lv_obj_align(ext->content, ext->tabs, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0); + + + } + /*Copy an existing tab*/ + else { + lv_tab_ext_t * copy_ext = lv_obj_get_ext(copy); + + /*Refresh the style with new signal function*/ + lv_obj_refr_style(new_tab); + } + + return new_tab; +} + +/** + * Signal function of the tab + * @param tab pointer to a tab object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return true: the object is still valid (not deleted), false: the object become invalid + */ +bool lv_tab_signal(lv_obj_t * tab, lv_signal_t sign, void * param) +{ + bool valid; + + /* Include the ancient signal function */ + valid = lv_obj_signal(tab, sign, param); + + /* The object can be deleted so check its validity and then + * make the object specific signal handling */ + if(valid != false) { + if(sign == LV_SIGNAL_CLEANUP) { + /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/ + } else if(sign == LV_SIGNAL_CORD_CHG) { + lv_tab_ext_t * ext = lv_obj_get_ext(tab); + if(ext->content != NULL && + (lv_obj_get_width(tab) != area_get_width(param) || + lv_obj_get_height(tab) != area_get_height(param))) { + + lv_obj_set_width(ext->tabs, lv_obj_get_width(tab)); + lv_obj_set_height(ext->content, lv_obj_get_height(tab) - lv_obj_get_height(ext->tabs)); + lv_obj_t * pages = lv_obj_get_child(ext->content, NULL); + while(pages != NULL) { + lv_obj_set_size(pages, lv_obj_get_width(tab), lv_obj_get_height(tab) - lv_obj_get_height(ext->tabs)); + pages = lv_obj_get_child(ext->content, pages); + } + + if(ext->tab_num != 0) { + lv_style_t * style_tabs = lv_obj_get_style(ext->tabs); + cord_t indic_width = (lv_obj_get_width(tab) - style_tabs->opad * (ext->tab_num - 1) - 2 * style_tabs->hpad) / ext->tab_num; + lv_obj_set_width(ext->indic, indic_width); + } + } + } + } + + return valid; +} + +/*===================== + * Setter functions + *====================*/ +void lv_tab_set_act(lv_obj_t * tab, uint16_t id) +{ + lv_tab_ext_t * ext = lv_obj_get_ext(tab); + lv_style_t * style = lv_obj_get_style(ext->content); + + anim_t a; + a.var = ext->content; + a.start = lv_obj_get_x(ext->content); + a.end = -(lv_obj_get_width(tab) * id + style->opad * id + style->hpad); + a.fp = (anim_fp_t)lv_obj_set_x; + a.path = anim_get_path(ANIM_PATH_LIN); + a.end_cb = NULL; + a.act_time = 0; + a.time = 300; + a.playback = 0; + a.playback_pause = 0; + a.repeat = 0; + a.repeat_pause = 0; + anim_create(&a); + + /*Move the indicator*/ + cord_t indic_width = lv_obj_get_width(ext->indic); + lv_style_t * indic_style = lv_obj_get_style(ext->indic); + a.var = ext->indic; + a.start = lv_obj_get_x(ext->indic); + a.end = indic_width * id + indic_style->opad * id + indic_style->hpad; + a.fp = (anim_fp_t)lv_obj_set_x; + a.path = anim_get_path(ANIM_PATH_LIN); + a.end_cb = NULL; + a.act_time = 0; + a.time = 300; + a.playback = 0; + a.playback_pause = 0; + a.repeat = 0; + a.repeat_pause = 0; + anim_create(&a); + + lv_btnm_set_tgl(ext->tabs, true, ext->tab_act); + +} + +/*===================== + * Getter functions + *====================*/ + +/* + * New object specific "get" function comes here + */ +/*===================== + * Other functions + *====================*/ + +lv_obj_t * lv_tab_add(lv_obj_t * tab, const char * name) +{ + lv_tab_ext_t * ext = lv_obj_get_ext(tab); + + lv_obj_t * h = lv_page_create(ext->content, NULL); + lv_obj_set_size(h, lv_obj_get_width(tab), lv_obj_get_height(tab)); + lv_obj_set_style(h, lv_style_get(LV_STYLE_PRETTY_COLOR, NULL)); + lv_obj_set_signal_f(h, lv_tab_page_signal); + lv_page_set_sb_mode(h, LV_PAGE_SB_MODE_AUTO); + if(page_scrl_signal == NULL) page_scrl_signal = lv_obj_get_signal_f(lv_page_get_scrl(h)); + lv_obj_set_signal_f(lv_page_get_scrl(h), lv_tab_scrl_signal); + + + lv_obj_t * l = lv_label_create(h, NULL); + lv_label_set_text(l, name); + + ext->tab_num++; + ext->tab_name_ptr = dm_realloc(ext->tab_name_ptr, sizeof(char *) * (ext->tab_num + 1)); + ext->tab_name_ptr[ext->tab_num - 1] = name; + ext->tab_name_ptr[ext->tab_num] = ""; + + lv_btnm_set_map(ext->tabs, ext->tab_name_ptr); + + lv_style_t * style_tabs = lv_obj_get_style(ext->tabs); + cord_t indic_width = (lv_obj_get_width(tab) - style_tabs->opad * (ext->tab_num - 1) - 2 * style_tabs->hpad) / ext->tab_num; + lv_obj_set_width(ext->indic, indic_width); + lv_obj_align(ext->indic, NULL, LV_ALIGN_IN_BOTTOM_LEFT, style_tabs->hpad, - style_tabs->opad); + + return h; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + + +/** + * Handle the drawing related tasks of the tabs + * @param tab 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_tab_design(lv_obj_t * tab, const area_t * mask, lv_design_mode_t mode) +{ + /*Return false if the object is not covers the mask_p area*/ + if(mode == LV_DESIGN_COVER_CHK) { + return false; + } + /*Draw the object*/ + else if(mode == LV_DESIGN_DRAW_MAIN) { + + } + /*Post draw when the children are drawn*/ + else if(mode == LV_DESIGN_DRAW_POST) { + + } + + return true; +} + + +static bool lv_tab_page_signal(lv_obj_t * tab_page, lv_signal_t sign, void * param) +{ + bool valid; + + /* Include the ancient signal function */ + valid = lv_page_signal(tab_page, sign, param); + + /* The object can be deleted so check its validity and then + * make the object specific signal handling */ + if(valid != false) { + lv_obj_t * cont = lv_obj_get_parent(tab_page); + lv_obj_t * tab = lv_obj_get_parent(cont); + if(sign == LV_SIGNAL_PRESSED) { + page_pressed_hadler(tab, param); + } + else if(sign == LV_SIGNAL_PRESSING) { + page_pressing_hadler(tab, tab_page, param); + } + else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) { + page_press_lost_hadler(tab, tab_page, param); + } + + } + + return valid; +} + +static bool lv_tab_scrl_signal(lv_obj_t * tab_scrl, lv_signal_t sign, void * param) +{ + bool valid; + + /* Include the ancient signal function */ + valid = page_scrl_signal(tab_scrl, sign, param); + + /* The object can be deleted so check its validity and then + * make the object specific signal handling */ + if(valid != false) { + lv_obj_t * tab_page = lv_obj_get_parent(tab_scrl); + lv_obj_t * cont = lv_obj_get_parent(tab_page); + lv_obj_t * tab = lv_obj_get_parent(cont); + if(sign == LV_SIGNAL_PRESSED) { + page_pressed_hadler(tab, param); + } + else if(sign == LV_SIGNAL_PRESSING) { + page_pressing_hadler(tab, tab_page, param); + } + else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) { + page_press_lost_hadler(tab, tab_page, param); + } + + } + + return valid; +} +static void page_pressed_hadler(lv_obj_t * tab, lv_dispi_t * dispi) +{ + lv_tab_ext_t * ext = lv_obj_get_ext(tab); + lv_dispi_get_point(dispi, &ext->point_last); +} + +static void page_pressing_hadler(lv_obj_t * tab, lv_obj_t * tab_page, lv_dispi_t * dispi) +{ + lv_tab_ext_t * ext = lv_obj_get_ext(tab); + point_t point_act; + lv_dispi_get_point(dispi, &point_act); + cord_t x_diff = point_act.x - ext->point_last.x; + cord_t y_diff = point_act.y - ext->point_last.y; + + if(ext->draging == 0) { + if(x_diff >= LV_DISPI_DRAG_LIMIT || x_diff<= -LV_DISPI_DRAG_LIMIT) { + ext->drag_h = 1; + ext->draging = 1; + lv_obj_set_drag(lv_page_get_scrl(tab_page), false); + } else if(y_diff >= LV_DISPI_DRAG_LIMIT || y_diff <= -LV_DISPI_DRAG_LIMIT) { + ext->drag_h = 0; + ext->draging = 1; + } + } + if(ext->drag_h != 0) { + lv_obj_set_x(ext->content, lv_obj_get_x(ext->content) + point_act.x - ext->point_last.x); + ext->point_last.x = point_act.x; + ext->point_last.y = point_act.y; + + /*Move the indicator*/ + cord_t indic_width = lv_obj_get_width(ext->indic); + cord_t p = (tab_page->cords.x1 * indic_width) / lv_obj_get_width(tab); + lv_style_t * indic_style = lv_obj_get_style(ext->indic); + lv_obj_set_x(ext->indic, indic_width * ext->tab_act - p + indic_style -> opad - ext->tab_act + indic_style->hpad); + } + +} + +static void page_press_lost_hadler(lv_obj_t * tab, lv_obj_t * tab_page, lv_dispi_t * dispi) +{ + lv_tab_ext_t * ext = lv_obj_get_ext(tab); + ext->drag_h = 0; + ext->draging = 0; + + lv_obj_set_drag(lv_page_get_scrl(tab_page), true); + + point_t point_act; + lv_dispi_get_point(dispi, &point_act); + cord_t x_diff = point_act.x - ext->point_last.x; + cord_t x_predict = 0; + + while(x_diff != 0) { + x_predict += x_diff; + x_diff = x_diff * (100 - LV_DISPI_DRAG_THROW) / 100; + } + + printf("predict: %d\n", x_predict); + + cord_t page_x1 = tab_page->cords.x1 + x_predict; + cord_t page_x2 = tab_page->cords.x2 + x_predict; + + if(page_x1 > (tab->cords.x2 - tab->cords.x1) / 2) { + printf("Right\n"); + if(ext->tab_act != 0) ext->tab_act--; + } else if(page_x2 < (tab->cords.x2 - tab->cords.x1) / 2) { + printf("Left\n"); + if(ext->tab_act < ext->tab_num - 1) ext->tab_act++; + } + + lv_tab_set_act(tab, ext->tab_act); + +} + +static lv_action_res_t tab_btnm_action(lv_obj_t * tab_btnm, uint16_t id) +{ + lv_obj_t * tab = lv_obj_get_parent(tab_btnm); + lv_tab_ext_t * ext = lv_obj_get_ext(tab); + ext->tab_act = id; + lv_tab_set_act(tab, id); + + return LV_ACTION_RES_OK; +} + +#endif diff --git a/lv_objx/lv_tab.h b/lv_objx/lv_tab.h new file mode 100644 index 000000000..42f252bb9 --- /dev/null +++ b/lv_objx/lv_tab.h @@ -0,0 +1,84 @@ +/** + * @file lv_tab.h + * + */ + +#ifndef LV_TAB_H +#define LV_TAB_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_conf.h" +#if USE_LV_TAB != 0 + +#include "../lv_obj/lv_obj.h" +#include "../lv_objx/lv_win.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +/*Data of tab*/ +typedef struct +{ + /*Ext. of ancestor*/ + /*New data for this type */ + lv_obj_t * tabs; + lv_obj_t * indic; + lv_obj_t * content; /*A rectangle to show the current tab*/ + const char ** tab_name_ptr; + point_t point_last; + uint16_t tab_act; + uint16_t tab_num; + uint8_t draging :1; + uint8_t drag_h :1; + +}lv_tab_ext_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a tab objects + * @param par pointer to an object, it will be the parent of the new tab + * @param copy pointer to a tab object, if not NULL then the new object will be copied from it + * @return pointer to the created tab + */ +lv_obj_t * lv_tab_create(lv_obj_t * par, lv_obj_t * copy); + +/** + * Signal function of the tab + * @param tab pointer to a tab object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return true: the object is still valid (not deleted), false: the object become invalid + */ +bool lv_tab_signal(lv_obj_t * tab, lv_signal_t sign, void * param); + +lv_obj_t * lv_tab_add(lv_obj_t * tab, const char * name); + + +lv_obj_t * lv_tab_add_scrollable(lv_obj_t * tab, const char * name); + + + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_TAB*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_TAB_H*/ From 525a9e381f3dbd1f047a52f1daa385c302645ff9 Mon Sep 17 00:00:00 2001 From: Gabor Date: Mon, 21 Aug 2017 14:41:50 +0200 Subject: [PATCH 06/13] lv_objx_templ: updated --- lv_objx/lv_objx_templ.c | 11 +++++++++-- lv_objx/lv_objx_templ.h | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lv_objx/lv_objx_templ.c b/lv_objx/lv_objx_templ.c index 3ee6b7287..59af614f1 100644 --- a/lv_objx/lv_objx_templ.c +++ b/lv_objx/lv_objx_templ.c @@ -116,7 +116,7 @@ bool lv_templ_signal(lv_obj_t * templ, lv_signal_t sign, void * param) *====================*/ /* - * New object specific "set" function comes here + * New object specific "set" functions come here */ @@ -125,9 +125,16 @@ bool lv_templ_signal(lv_obj_t * templ, lv_signal_t sign, void * param) *====================*/ /* - * New object specific "get" function comes here + * New object specific "get" functions come here */ +/*===================== + * Other functions + *====================*/ + +/* + * New object specific "other" functions come here + */ /********************** * STATIC FUNCTIONS diff --git a/lv_objx/lv_objx_templ.h b/lv_objx/lv_objx_templ.h index 15d0d2110..e8410d5f0 100644 --- a/lv_objx/lv_objx_templ.h +++ b/lv_objx/lv_objx_templ.h @@ -35,7 +35,7 @@ extern "C" { /*Data of template*/ typedef struct { - /*Ext. of ancestor*/ + lv_ANCESTOR_ext_t ANCESTOR; /*Ext. of ancestor*/ /*New data for this type */ }lv_templ_ext_t; From 6d68aabc41d9e72b6fa904c9db82746d1560fd6e Mon Sep 17 00:00:00 2001 From: Gabor Date: Tue, 22 Aug 2017 16:41:23 +0200 Subject: [PATCH 07/13] lv_objx_templ: formatting --- lv_objx/lv_objx_templ.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lv_objx/lv_objx_templ.h b/lv_objx/lv_objx_templ.h index e8410d5f0..63cd55447 100644 --- a/lv_objx/lv_objx_templ.h +++ b/lv_objx/lv_objx_templ.h @@ -33,8 +33,7 @@ extern "C" { * TYPEDEFS **********************/ /*Data of template*/ -typedef struct -{ +typedef struct { lv_ANCESTOR_ext_t ANCESTOR; /*Ext. of ancestor*/ /*New data for this type */ }lv_templ_ext_t; From af0c8d57b5429510953fdb895a7cebbe14f934f9 Mon Sep 17 00:00:00 2001 From: Gabor Date: Wed, 23 Aug 2017 09:24:23 +0200 Subject: [PATCH 08/13] lv_kb: add Keyboard object type --- lv_objx/lv_kb.c | 376 ++++++++++++++++++++++++++++++++++++++++++++++++ lv_objx/lv_kb.h | 79 ++++++++++ 2 files changed, 455 insertions(+) create mode 100644 lv_objx/lv_kb.c create mode 100644 lv_objx/lv_kb.h diff --git a/lv_objx/lv_kb.c b/lv_objx/lv_kb.c new file mode 100644 index 000000000..32bc883d6 --- /dev/null +++ b/lv_objx/lv_kb.c @@ -0,0 +1,376 @@ +/** + * @file lv_kb.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_conf.h" +#if USE_LV_KB != 0 + +#include "lv_kb.h" +#include "lv_ta.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +#if 0 /*Use Button matrix design*/ +static bool lv_kb_design(lv_obj_t * kb, const area_t * mask, lv_design_mode_t mode); +#endif + +static lv_action_res_t lv_app_kb_action(lv_obj_t * kb, uint16_t i); + +/********************** + * STATIC VARIABLES + **********************/ +static const char * kb_map_lc[] = { +"\0051#", "\004q", "\004w", "\004e", "\004r", "\004t", "\004y", "\004u", "\004i", "\004o", "\004p", "\007Del", "\n", +"\006ABC", "\003a", "\003s", "\003d", "\003f", "\003g", "\003h", "\003j", "\003k", "\003l", "\010Enter", "\n", +"_", "-", "z", "x", "c", "v", "b", "n", "m", ".", ",", ":", "\n", +"\003Hide", "\003Left", "\006 ", "\003Right", "\003Ok", "" +}; + +static const char * kb_map_uc[] = { +"\0051#", "\004Q", "\004W", "\004E", "\004R", "\004T", "\004Y", "\004U", "\004I", "\004O", "\004P", "\007Del", "\n", +"\006abc", "\003A", "\003S", "\003D", "\003F", "\003G", "\003H", "\003J", "\003K", "\003L", "\010Enter", "\n", +"_", "-", "Z", "X", "C", "V", "B", "N", "M", ".", ",", ":", "\n", +"\003Hide", "\003Left", "\006 ", "\003Right", "\003Ok", "" +}; + +static const char * kb_map_spec[] = { +"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "\002Del", "\n", +"\002abc", "+", "-", "/", "*", "=", "%", "!", "?", "#", "<", ">", "\n", +"\\", "@", "$", "(", ")", "{", "}", "[", "]", ";", "\"", "'", "\n", +"\003Hide", "\003Left", "\006 ", "\003Right", "\003Ok", "" +}; + +static const char * kb_map_num[] = { +"1", "2", "3", "\002Hide","\n", +"4", "5", "6", "\002Ok", "\n", +"7", "8", "9", "\002Del", "\n", +"+/-", "0", ".", "Left", "Right", "" +}; +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/*----------------- + * Create function + *-----------------*/ + +/** + * Create a keyboard objects + * @param par pointer to an object, it will be the parent of the new keyboard + * @param copy pointer to a keyboard object, if not NULL then the new object will be copied from it + * @return pointer to the created keyboard + */ +lv_obj_t * lv_kb_create(lv_obj_t * par, lv_obj_t * copy) +{ + /*Create the ancestor of keyboard*/ + /*TODO modify it to the ancestor create function */ + lv_obj_t * new_kb = lv_btnm_create(par, copy); + dm_assert(new_kb); + + /*Allocate the keyboard type specific extended data*/ + lv_kb_ext_t * ext = lv_obj_alloc_ext(new_kb, sizeof(lv_kb_ext_t)); + dm_assert(ext); + + /*Initialize the allocated 'ext' */ + + ext->ta = NULL; + ext->mode = LV_KB_MODE_TXT; + ext->cur_mng = 0; + ext->close_action = NULL; + ext->ok_action = NULL; + + /*The signal and design functions are not copied so set them here*/ + lv_obj_set_signal_f(new_kb, lv_kb_signal); + + /*Init the new keyboard keyboard*/ + if(copy == NULL) { + lv_obj_set_size(new_kb, LV_HOR_RES, LV_VER_RES / 2); + lv_obj_align(new_kb, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0); + lv_btnm_set_action(new_kb, lv_app_kb_action); + lv_btnm_set_map(new_kb, kb_map_lc); + } + /*Copy an existing keyboard*/ + else { + lv_kb_ext_t * copy_ext = lv_obj_get_ext(copy);ext->ta = NULL; + ext->ta = copy_ext->ta; + ext->mode = copy_ext->mode; + ext->cur_mng = copy_ext->cur_mng; + ext->close_action = copy_ext->close_action; + ext->ok_action = copy_ext->ok_action; + + /*Refresh the style with new signal function*/ + lv_obj_refr_style(new_kb); + } + + return new_kb; +} + +/** + * Signal function of the keyboard + * @param kb pointer to a keyboard object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return true: the object is still valid (not deleted), false: the object become invalid + */ +bool lv_kb_signal(lv_obj_t * kb, lv_signal_t sign, void * param) +{ + bool valid; + + /* Include the ancient signal function */ + valid = lv_btnm_signal(kb, sign, param); + + /* The object can be deleted so check its validity and then + * make the object specific signal handling */ + if(valid != false) { + if(sign == LV_SIGNAL_CLEANUP) { + /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/ + } + } + + return valid; +} + +/*===================== + * Setter functions + *====================*/ + +/** + * Assign a Text Area to the Keyboard. The pressed characters will be put there. + * @param kb pointer to a Keyboard object + * @param ta pointer to a Text Area object to write there + */ +void lv_kb_set_ta(lv_obj_t * kb, lv_obj_t * ta) +{ + lv_kb_ext_t * ext = lv_obj_get_ext(kb); + + if(ext->ta != NULL && ext->cur_mng != 0) lv_ta_set_cursor_show(ext->ta, false); + ext->ta = ta; + if(ext->cur_mng != 0) lv_ta_set_cursor_show(ext->ta, true); +} + +/** + * Set a new a mode (text or number map) + * @param kb pointer to a Keyboard object + * @param mode the mode from 'lv_kb_mode_t' + */ +void lv_kb_set_mode(lv_obj_t * kb, lv_kb_mode_t mode) +{ + lv_kb_ext_t * ext = lv_obj_get_ext(kb); + ext->mode = mode; + if(mode == LV_KB_MODE_TXT) lv_btnm_set_map(kb, kb_map_lc); + else if(mode == LV_KB_MODE_TXT) lv_btnm_set_map(kb, kb_map_num); +} + + +/** + * Automatically hide or show the cursor of Text Area + * @param kb pointer to a Keyboard object + * @param en true: show cursor on the current text area, false: hide cursor + */ +void lv_kb_set_cur_mng(lv_obj_t * kb, bool en) +{ + lv_kb_ext_t * ext = lv_obj_get_ext(kb); + ext->cur_mng = en == false? 0 : 1; + + if(ext->ta != NULL) lv_ta_set_cursor_show(ext->ta, true); +} + +/** + * Set call back to call when the "Ok" button is pressed + * @param kb pointer to Keyboard object + * @param action a callback with 'lv_action_t' type + */ +void lv_kb_set_ok_action(lv_obj_t * kb, lv_action_t action) +{ + lv_kb_ext_t * ext = lv_obj_get_ext(kb); + ext->ok_action = action; +} + +/** + * Set call back to call when the "Hide" button is pressed + * @param kb pointer to Keyboard object + * @param action a callback with 'lv_action_t' type + */ +void lv_kb_set_close_action(lv_obj_t * kb, lv_action_t action) +{ + lv_kb_ext_t * ext = lv_obj_get_ext(kb); + ext->close_action = action; +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Assign a Text Area to the Keyboard. The pressed characters will be put there. + * @param kb pointer to a Keyboard object + * @return pointer to the assigned Text Area object + */ +lv_obj_t * lv_kb_get_ta(lv_obj_t * kb) +{ + lv_kb_ext_t * ext = lv_obj_get_ext(kb); + return ext->ta; +} + +/** + * Set a new a mode (text or number map) + * @param kb pointer to a Keyboard object + * @return the current mode from 'lv_kb_mode_t' + */ +lv_kb_mode_t lv_kb_get_mode(lv_obj_t * kb) +{ + lv_kb_ext_t * ext = lv_obj_get_ext(kb); + return ext->mode; +} + + +/** + * Get the current cursor manage mode. + * @param kb pointer to a Keyboard object + * @return true: show cursor on the current text area, false: hide cursor + */ +bool lv_kb_get_cur_mng(lv_obj_t * kb, bool en) +{ + lv_kb_ext_t * ext = lv_obj_get_ext(kb); + return ext->cur_mng == 0 ? false : true; +} + +/** + * Get the callback to call when the "Ok" button is pressed + * @param kb pointer to Keyboard object + * @return the ok callback + */ +lv_action_t lv_kb_get_ok_action(lv_obj_t * kb, lv_action_t action) +{ + lv_kb_ext_t * ext = lv_obj_get_ext(kb); + return ext->ok_action; +} + +/** + * Get the callback to call when the "Hide" button is pressed + * @param kb pointer to Keyboard object + * @return the close callback + */ +lv_action_t lv_kb_get_close_action(lv_obj_t * kb, lv_action_t action) +{ + lv_kb_ext_t * ext = lv_obj_get_ext(kb); + return ext->close_action; +} + + +/********************** + * STATIC FUNCTIONS + **********************/ + +#if 0 /*Use Button matrix design*/ +/** + * Handle the drawing related tasks of the keyboards + * @param kb 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_kb_design(lv_obj_t * kb, const area_t * mask, lv_design_mode_t mode) +{ + /*Return false if the object is not covers the mask_p area*/ + if(mode == LV_DESIGN_COVER_CHK) { + return false; + } + /*Draw the object*/ + else if(mode == LV_DESIGN_DRAW_MAIN) { + + } + /*Post draw when the children are drawn*/ + else if(mode == LV_DESIGN_DRAW_POST) { + + } + + return true; +} +#endif + +/** + * Called when a button of 'kb_btnm' is released + * @param btnm pointer to 'kb_btnm' + * @param i the index of the released button from the current btnm map + * @return LV_ACTION_RES_INV if the btnm is deleted else LV_ACTION_RES_OK + */ +static lv_action_res_t lv_app_kb_action(lv_obj_t * kb, uint16_t i) +{ + lv_kb_ext_t * ext = lv_obj_get_ext(kb); + if(ext->ta == NULL) return LV_ACTION_RES_OK; + + const char ** map = lv_btnm_get_map(kb); + const char * txt = map[i]; + + /*Ignore the unit size number of the text*/ + if(txt[0] <= '\011') txt++; /*Ignore length specifier*/ + + if(txt[0] == '\177') return LV_ACTION_RES_OK; /*Don't care hidden buttons*/ + + /*Do the corresponding action according to the text of the button*/ + if(strcmp(txt, "abc") == 0) { + lv_btnm_set_map(kb, kb_map_lc); + } else if(strcmp(txt, "ABC") == 0) { + lv_btnm_set_map(kb, kb_map_uc); + } else if(strcmp(txt, "1#") == 0) { + lv_btnm_set_map(kb, kb_map_spec); + } else if(strcmp(txt, "Enter") == 0) { + lv_ta_add_char(ext->ta, '\n'); + } else if(strcmp(txt, "Left") == 0) { + lv_ta_cursor_left(ext->ta); + } else if(strcmp(txt, "Right") == 0) { + lv_ta_cursor_right(ext->ta); + } else if(strcmp(txt, "Del") == 0) { + lv_ta_del(ext->ta); + } else if(strcmp(txt, "+/-") == 0) { + uint16_t cur = lv_ta_get_cursor_pos(ext->ta); + const char * ta_txt = lv_ta_get_txt(ext->ta); + if(ta_txt[0] == '-') { + lv_ta_set_cursor_pos(ext->ta, 1); + lv_ta_del(ext->ta); + lv_ta_add_char(ext->ta, '+'); + lv_ta_set_cursor_pos(ext->ta, cur); + } else if(ta_txt[0] == '+') { + lv_ta_set_cursor_pos(ext->ta, 1); + lv_ta_del(ext->ta); + lv_ta_add_char(ext->ta, '-'); + lv_ta_set_cursor_pos(ext->ta, cur); + } else { + lv_ta_set_cursor_pos(ext->ta, 0); + lv_ta_add_char(ext->ta, '-'); + lv_ta_set_cursor_pos(ext->ta, cur + 1); + } + } else if(strcmp(txt, "Hide") == 0) { + //lv_app_kb_close(false); + return LV_ACTION_RES_INV; + } else if(strcmp(txt, "Ok") == 0) { + //lv_app_kb_close(true); + return LV_ACTION_RES_INV; + } else { + lv_ta_add_text(ext->ta, txt); + } + return LV_ACTION_RES_OK; +} + +#endif diff --git a/lv_objx/lv_kb.h b/lv_objx/lv_kb.h new file mode 100644 index 000000000..0cf737b1c --- /dev/null +++ b/lv_objx/lv_kb.h @@ -0,0 +1,79 @@ +/** + * @file lv_kb.h + * + */ + +#ifndef LV_KB_H +#define LV_KB_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_conf.h" +#if USE_LV_KB != 0 + +#include "../lv_obj/lv_obj.h" +#include "lv_btnm.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +typedef enum { + LV_KB_MODE_TXT, + LV_KB_MODE_NUM, +}lv_kb_mode_t; + + +/*Data of keyboard*/ +typedef struct { + lv_btnm_ext_t btnm; /*Ext. of ancestor*/ + /*New data for this type */ + lv_obj_t * ta; + lv_kb_mode_t mode; + uint8_t cur_mng :1; + lv_action_t ok_action; + lv_action_t close_action; +}lv_kb_ext_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a keyboard objects + * @param par pointer to an object, it will be the parent of the new keyboard + * @param copy pointer to a keyboard object, if not NULL then the new object will be copied from it + * @return pointer to the created keyboard + */ +lv_obj_t * lv_kb_create(lv_obj_t * par, lv_obj_t * copy); + +/** + * Signal function of the keyboard + * @param kb pointer to a keyboard object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return true: the object is still valid (not deleted), false: the object become invalid + */ +bool lv_kb_signal(lv_obj_t * kb, lv_signal_t sign, void * param); + + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_KB*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_KB_H*/ From 1bdc650635c6a4be0e70eca337ec36d085e977e7 Mon Sep 17 00:00:00 2001 From: Gabor Date: Wed, 23 Aug 2017 14:15:33 +0200 Subject: [PATCH 09/13] lv_kb: lv_kb_set_mode bugfix --- lv_objx/lv_kb.c | 2 +- lv_objx/lv_kb.h | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/lv_objx/lv_kb.c b/lv_objx/lv_kb.c index 32bc883d6..94ef44b0b 100644 --- a/lv_objx/lv_kb.c +++ b/lv_objx/lv_kb.c @@ -175,7 +175,7 @@ void lv_kb_set_mode(lv_obj_t * kb, lv_kb_mode_t mode) lv_kb_ext_t * ext = lv_obj_get_ext(kb); ext->mode = mode; if(mode == LV_KB_MODE_TXT) lv_btnm_set_map(kb, kb_map_lc); - else if(mode == LV_KB_MODE_TXT) lv_btnm_set_map(kb, kb_map_num); + else if(mode == LV_KB_MODE_NUM) lv_btnm_set_map(kb, kb_map_num); } diff --git a/lv_objx/lv_kb.h b/lv_objx/lv_kb.h index 0cf737b1c..51dd34ccf 100644 --- a/lv_objx/lv_kb.h +++ b/lv_objx/lv_kb.h @@ -65,6 +65,75 @@ lv_obj_t * lv_kb_create(lv_obj_t * par, lv_obj_t * copy); */ bool lv_kb_signal(lv_obj_t * kb, lv_signal_t sign, void * param); +/** + * Assign a Text Area to the Keyboard. The pressed characters will be put there. + * @param kb pointer to a Keyboard object + * @param ta pointer to a Text Area object to write there + */ +void lv_kb_set_ta(lv_obj_t * kb, lv_obj_t * ta); + +/** + * Set a new a mode (text or number map) + * @param kb pointer to a Keyboard object + * @param mode the mode from 'lv_kb_mode_t' + */ +void lv_kb_set_mode(lv_obj_t * kb, lv_kb_mode_t mode); + +/** + * Automatically hide or show the cursor of Text Area + * @param kb pointer to a Keyboard object + * @param en true: show cursor on the current text area, false: hide cursor + */ +void lv_kb_set_cur_mng(lv_obj_t * kb, bool en); + +/** + * Set call back to call when the "Ok" button is pressed + * @param kb pointer to Keyboard object + * @param action a callback with 'lv_action_t' type + */ +void lv_kb_set_ok_action(lv_obj_t * kb, lv_action_t action); + +/** + * Set call back to call when the "Hide" button is pressed + * @param kb pointer to Keyboard object + * @param action a callback with 'lv_action_t' type + */ +void lv_kb_set_close_action(lv_obj_t * kb, lv_action_t action); + +/** + * Assign a Text Area to the Keyboard. The pressed characters will be put there. + * @param kb pointer to a Keyboard object + * @return pointer to the assigned Text Area object + */ +lv_obj_t * lv_kb_get_ta(lv_obj_t * kb); +/** + * Set a new a mode (text or number map) + * @param kb pointer to a Keyboard object + * @return the current mode from 'lv_kb_mode_t' + */ +lv_kb_mode_t lv_kb_get_mode(lv_obj_t * kb); + + +/** + * Get the current cursor manage mode. + * @param kb pointer to a Keyboard object + * @return true: show cursor on the current text area, false: hide cursor + */ +bool lv_kb_get_cur_mng(lv_obj_t * kb, bool en); + +/** + * Get the callback to call when the "Ok" button is pressed + * @param kb pointer to Keyboard object + * @return the ok callback + */ +lv_action_t lv_kb_get_ok_action(lv_obj_t * kb, lv_action_t action); + +/** + * Get the callback to call when the "Hide" button is pressed + * @param kb pointer to Keyboard object + * @return the close callback + */ +lv_action_t lv_kb_get_close_action(lv_obj_t * kb, lv_action_t action); /********************** * MACROS From 90d8a1191763de6ae1115c588b594d2d092ef760 Mon Sep 17 00:00:00 2001 From: Gabor Date: Wed, 23 Aug 2017 14:19:42 +0200 Subject: [PATCH 10/13] lv_ta: lv_ta_cursor_show() don't let cursor visible if disabled --- lv_objx/lv_ta.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lv_objx/lv_ta.c b/lv_objx/lv_ta.c index 612a363bc..f85eaaacf 100644 --- a/lv_objx/lv_ta.c +++ b/lv_objx/lv_ta.c @@ -522,6 +522,8 @@ void lv_ta_set_cursor_show(lv_obj_t * ta, bool show) { lv_ta_ext_t * ext = lv_obj_get_ext(ta); ext->cursor_show = show == false ? 0 : 1; + ext->cursor_state = 0; + lv_obj_inv(ta); } /** From 7c90b4630b3e99ecda27c78db52bd1476e35de30 Mon Sep 17 00:00:00 2001 From: Gabor Date: Wed, 23 Aug 2017 14:23:07 +0200 Subject: [PATCH 11/13] lv_conf_templ, lvgl.h: update with lv_tabview and lv_kb --- lv_conf_templ.h | 9 +++++++++ lvgl.h | 3 +++ 2 files changed, 12 insertions(+) diff --git a/lv_conf_templ.h b/lv_conf_templ.h index 8082ef48f..138c3a6e4 100644 --- a/lv_conf_templ.h +++ b/lv_conf_templ.h @@ -100,6 +100,12 @@ /*Window (dependencies: lv_cont, lv_btn, lv_label, lv_img, lv_page)*/ #define USE_LV_WIN 1 +/*Tab (dependencies: lv_page, lv_btnm)*/ +#define USE_LV_TABVIEW 1 +#if USE_LV_TABVIEW != 0 +#define LV_TABVIEW_ANIM_TIME 300 /*Time of slide animation [ms] (0: no animation)*/ +#endif + /************************* * Data visualizer object *************************/ @@ -143,6 +149,9 @@ /*Button matrix (dependencies: -)*/ #define USE_LV_BTNM 1 +/*Keyboard (dependencies: lv_btnm)*/ +#define USE_LV_KB 1 + /*Check box (dependencies: lv_btn, lv_label)*/ #define USE_LV_CB 1 diff --git a/lvgl.h b/lvgl.h index 9f16d56e2..3cdee0c7e 100644 --- a/lvgl.h +++ b/lvgl.h @@ -31,13 +31,16 @@ extern "C" { #include "lv_objx/lv_slider.h" #include "lv_objx/lv_led.h" #include "lv_objx/lv_btnm.h" +#include "lv_objx/lv_kb.h" #include "lv_objx/lv_ddlist.h" #include "lv_objx/lv_ta.h" #include "lv_objx/lv_win.h" +#include "lv_objx/lv_tabview.h" #include "lv_objx/lv_mbox.h" #include "lv_objx/lv_gauge.h" #include "lv_objx/lv_lmeter.h" #include "lv_objx/lv_sw.h" +#include "lv_objx/lv_kb.h" #include "lv_app/lv_app.h" From fea552511ef64d8f0f71de9713912a45f696b0d3 Mon Sep 17 00:00:00 2001 From: Gabor Date: Wed, 23 Aug 2017 14:24:11 +0200 Subject: [PATCH 12/13] lv_objx_templ: create 'Add/remove functions' section --- lv_objx/lv_objx_templ.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lv_objx/lv_objx_templ.c b/lv_objx/lv_objx_templ.c index 59af614f1..71ad75fd1 100644 --- a/lv_objx/lv_objx_templ.c +++ b/lv_objx/lv_objx_templ.c @@ -47,7 +47,7 @@ static bool lv_templ_design(lv_obj_t * templ, const area_t * mask, lv_design_mod *-----------------*/ /** - * Create a template objects + * Create a template object * @param par pointer to an object, it will be the parent of the new template * @param copy pointer to a template object, if not NULL then the new object will be copied from it * @return pointer to the created template @@ -111,6 +111,15 @@ bool lv_templ_signal(lv_obj_t * templ, lv_signal_t sign, void * param) return valid; } +/*====================== + * Add/remove functions + *=====================*/ + +/* + * New object specific "add" or "remove" functions come here + */ + + /*===================== * Setter functions *====================*/ From 0ef1fa0627ac20c2d79492f636f53a4ebd164a2d Mon Sep 17 00:00:00 2001 From: Gabor Date: Wed, 23 Aug 2017 14:24:34 +0200 Subject: [PATCH 13/13] lv_tabview: add API --- lv_objx/lv_tab.c | 422 ------------------------------- lv_objx/lv_tab.h | 84 ------- lv_objx/lv_tabview.c | 587 +++++++++++++++++++++++++++++++++++++++++++ lv_objx/lv_tabview.h | 144 +++++++++++ 4 files changed, 731 insertions(+), 506 deletions(-) delete mode 100644 lv_objx/lv_tab.c delete mode 100644 lv_objx/lv_tab.h create mode 100644 lv_objx/lv_tabview.c create mode 100644 lv_objx/lv_tabview.h diff --git a/lv_objx/lv_tab.c b/lv_objx/lv_tab.c deleted file mode 100644 index 62557bb51..000000000 --- a/lv_objx/lv_tab.c +++ /dev/null @@ -1,422 +0,0 @@ -/** - * @file lv_tab.c - * - */ - -/********************* - * INCLUDES - *********************/ -#include "lv_conf.h" -#if USE_LV_TAB != 0 - -#include "lv_tab.h" -#include "lv_btnm.h" -#include "misc/gfx/anim.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * STATIC PROTOTYPES - **********************/ -static bool lv_tab_design(lv_obj_t * tab, const area_t * mask, lv_design_mode_t mode); - -static bool lv_tab_page_signal(lv_obj_t * tab_page, lv_signal_t sign, void * param); -static bool lv_tab_scrl_signal(lv_obj_t * tab_scrl, lv_signal_t sign, void * param); - -static void page_pressed_hadler(lv_obj_t * tab, lv_dispi_t * dispi); -static void page_pressing_hadler(lv_obj_t * tab, lv_obj_t * tab_page, lv_dispi_t * dispi); -static void page_press_lost_hadler(lv_obj_t * tab, lv_obj_t * tab_page, lv_dispi_t * dispi); -static lv_action_res_t tab_btnm_action(lv_obj_t * tab_btnm, uint16_t id); - -/********************** - * STATIC VARIABLES - **********************/ -static lv_signal_f_t page_scrl_signal; -static const char * tab_def[] = {""}; -/********************** - * MACROS - **********************/ - -/********************** - * GLOBAL FUNCTIONS - **********************/ - -/*----------------- - * Create function - *-----------------*/ - -/** - * Create a tab objects - * @param par pointer to an object, it will be the parent of the new tab - * @param copy pointer to a tab object, if not NULL then the new object will be copied from it - * @return pointer to the created tab - */ -lv_obj_t * lv_tab_create(lv_obj_t * par, lv_obj_t * copy) -{ - /*Create the ancestor of tab*/ - lv_obj_t * new_tab = lv_obj_create(par, copy); - dm_assert(new_tab); - - /*Allocate the tab type specific extended data*/ - lv_tab_ext_t * ext = lv_obj_alloc_ext(new_tab, sizeof(lv_tab_ext_t)); - dm_assert(ext); - - /*Initialize the allocated 'ext' */ - ext->drag_h = 0; - ext->draging = 0; - ext->tab_act = 0; - ext->point_last.x = 0; - ext->point_last.y = 0; - ext->content = NULL; - ext->indic = NULL; - ext->tabs = NULL; - ext->tab_name_ptr = dm_alloc(sizeof(char*)); - ext->tab_name_ptr[0] = ""; - - /*The signal and design functions are not copied so set them here*/ - lv_obj_set_signal_f(new_tab, lv_tab_signal); - - /*Init the new tab tab*/ - if(copy == NULL) { - lv_obj_set_size(new_tab, LV_HOR_RES, LV_VER_RES); - lv_obj_set_style(new_tab, lv_style_get(LV_STYLE_PRETTY, NULL)); - - ext->tabs = lv_btnm_create(new_tab, NULL); - lv_btnm_set_map(ext->tabs, tab_def); - lv_obj_set_height(ext->tabs, 3 * LV_DPI / 4); - lv_btnm_set_action(ext->tabs, tab_btnm_action); - lv_btnm_set_tgl(ext->tabs, true, 0); - - ext->indic = lv_obj_create(ext->tabs, NULL); - lv_style_t * style_indic = lv_obj_get_style(ext->indic); - lv_obj_set_size(ext->indic, LV_DPI, style_indic->line_width); - - ext->content = lv_cont_create(new_tab, NULL); - lv_cont_set_fit(ext->content, true, false); - lv_cont_set_layout(ext->content, LV_CONT_LAYOUT_ROW_T); - lv_obj_set_height(ext->content, LV_VER_RES); - lv_obj_set_style(ext->content, lv_style_get(LV_STYLE_TRANSP_TIGHT, NULL)); - lv_obj_align(ext->content, ext->tabs, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0); - - - } - /*Copy an existing tab*/ - else { - lv_tab_ext_t * copy_ext = lv_obj_get_ext(copy); - - /*Refresh the style with new signal function*/ - lv_obj_refr_style(new_tab); - } - - return new_tab; -} - -/** - * Signal function of the tab - * @param tab pointer to a tab object - * @param sign a signal type from lv_signal_t enum - * @param param pointer to a signal specific variable - * @return true: the object is still valid (not deleted), false: the object become invalid - */ -bool lv_tab_signal(lv_obj_t * tab, lv_signal_t sign, void * param) -{ - bool valid; - - /* Include the ancient signal function */ - valid = lv_obj_signal(tab, sign, param); - - /* The object can be deleted so check its validity and then - * make the object specific signal handling */ - if(valid != false) { - if(sign == LV_SIGNAL_CLEANUP) { - /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/ - } else if(sign == LV_SIGNAL_CORD_CHG) { - lv_tab_ext_t * ext = lv_obj_get_ext(tab); - if(ext->content != NULL && - (lv_obj_get_width(tab) != area_get_width(param) || - lv_obj_get_height(tab) != area_get_height(param))) { - - lv_obj_set_width(ext->tabs, lv_obj_get_width(tab)); - lv_obj_set_height(ext->content, lv_obj_get_height(tab) - lv_obj_get_height(ext->tabs)); - lv_obj_t * pages = lv_obj_get_child(ext->content, NULL); - while(pages != NULL) { - lv_obj_set_size(pages, lv_obj_get_width(tab), lv_obj_get_height(tab) - lv_obj_get_height(ext->tabs)); - pages = lv_obj_get_child(ext->content, pages); - } - - if(ext->tab_num != 0) { - lv_style_t * style_tabs = lv_obj_get_style(ext->tabs); - cord_t indic_width = (lv_obj_get_width(tab) - style_tabs->opad * (ext->tab_num - 1) - 2 * style_tabs->hpad) / ext->tab_num; - lv_obj_set_width(ext->indic, indic_width); - } - } - } - } - - return valid; -} - -/*===================== - * Setter functions - *====================*/ -void lv_tab_set_act(lv_obj_t * tab, uint16_t id) -{ - lv_tab_ext_t * ext = lv_obj_get_ext(tab); - lv_style_t * style = lv_obj_get_style(ext->content); - - anim_t a; - a.var = ext->content; - a.start = lv_obj_get_x(ext->content); - a.end = -(lv_obj_get_width(tab) * id + style->opad * id + style->hpad); - a.fp = (anim_fp_t)lv_obj_set_x; - a.path = anim_get_path(ANIM_PATH_LIN); - a.end_cb = NULL; - a.act_time = 0; - a.time = 300; - a.playback = 0; - a.playback_pause = 0; - a.repeat = 0; - a.repeat_pause = 0; - anim_create(&a); - - /*Move the indicator*/ - cord_t indic_width = lv_obj_get_width(ext->indic); - lv_style_t * indic_style = lv_obj_get_style(ext->indic); - a.var = ext->indic; - a.start = lv_obj_get_x(ext->indic); - a.end = indic_width * id + indic_style->opad * id + indic_style->hpad; - a.fp = (anim_fp_t)lv_obj_set_x; - a.path = anim_get_path(ANIM_PATH_LIN); - a.end_cb = NULL; - a.act_time = 0; - a.time = 300; - a.playback = 0; - a.playback_pause = 0; - a.repeat = 0; - a.repeat_pause = 0; - anim_create(&a); - - lv_btnm_set_tgl(ext->tabs, true, ext->tab_act); - -} - -/*===================== - * Getter functions - *====================*/ - -/* - * New object specific "get" function comes here - */ -/*===================== - * Other functions - *====================*/ - -lv_obj_t * lv_tab_add(lv_obj_t * tab, const char * name) -{ - lv_tab_ext_t * ext = lv_obj_get_ext(tab); - - lv_obj_t * h = lv_page_create(ext->content, NULL); - lv_obj_set_size(h, lv_obj_get_width(tab), lv_obj_get_height(tab)); - lv_obj_set_style(h, lv_style_get(LV_STYLE_PRETTY_COLOR, NULL)); - lv_obj_set_signal_f(h, lv_tab_page_signal); - lv_page_set_sb_mode(h, LV_PAGE_SB_MODE_AUTO); - if(page_scrl_signal == NULL) page_scrl_signal = lv_obj_get_signal_f(lv_page_get_scrl(h)); - lv_obj_set_signal_f(lv_page_get_scrl(h), lv_tab_scrl_signal); - - - lv_obj_t * l = lv_label_create(h, NULL); - lv_label_set_text(l, name); - - ext->tab_num++; - ext->tab_name_ptr = dm_realloc(ext->tab_name_ptr, sizeof(char *) * (ext->tab_num + 1)); - ext->tab_name_ptr[ext->tab_num - 1] = name; - ext->tab_name_ptr[ext->tab_num] = ""; - - lv_btnm_set_map(ext->tabs, ext->tab_name_ptr); - - lv_style_t * style_tabs = lv_obj_get_style(ext->tabs); - cord_t indic_width = (lv_obj_get_width(tab) - style_tabs->opad * (ext->tab_num - 1) - 2 * style_tabs->hpad) / ext->tab_num; - lv_obj_set_width(ext->indic, indic_width); - lv_obj_align(ext->indic, NULL, LV_ALIGN_IN_BOTTOM_LEFT, style_tabs->hpad, - style_tabs->opad); - - return h; -} - -/********************** - * STATIC FUNCTIONS - **********************/ - - -/** - * Handle the drawing related tasks of the tabs - * @param tab 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_tab_design(lv_obj_t * tab, const area_t * mask, lv_design_mode_t mode) -{ - /*Return false if the object is not covers the mask_p area*/ - if(mode == LV_DESIGN_COVER_CHK) { - return false; - } - /*Draw the object*/ - else if(mode == LV_DESIGN_DRAW_MAIN) { - - } - /*Post draw when the children are drawn*/ - else if(mode == LV_DESIGN_DRAW_POST) { - - } - - return true; -} - - -static bool lv_tab_page_signal(lv_obj_t * tab_page, lv_signal_t sign, void * param) -{ - bool valid; - - /* Include the ancient signal function */ - valid = lv_page_signal(tab_page, sign, param); - - /* The object can be deleted so check its validity and then - * make the object specific signal handling */ - if(valid != false) { - lv_obj_t * cont = lv_obj_get_parent(tab_page); - lv_obj_t * tab = lv_obj_get_parent(cont); - if(sign == LV_SIGNAL_PRESSED) { - page_pressed_hadler(tab, param); - } - else if(sign == LV_SIGNAL_PRESSING) { - page_pressing_hadler(tab, tab_page, param); - } - else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) { - page_press_lost_hadler(tab, tab_page, param); - } - - } - - return valid; -} - -static bool lv_tab_scrl_signal(lv_obj_t * tab_scrl, lv_signal_t sign, void * param) -{ - bool valid; - - /* Include the ancient signal function */ - valid = page_scrl_signal(tab_scrl, sign, param); - - /* The object can be deleted so check its validity and then - * make the object specific signal handling */ - if(valid != false) { - lv_obj_t * tab_page = lv_obj_get_parent(tab_scrl); - lv_obj_t * cont = lv_obj_get_parent(tab_page); - lv_obj_t * tab = lv_obj_get_parent(cont); - if(sign == LV_SIGNAL_PRESSED) { - page_pressed_hadler(tab, param); - } - else if(sign == LV_SIGNAL_PRESSING) { - page_pressing_hadler(tab, tab_page, param); - } - else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) { - page_press_lost_hadler(tab, tab_page, param); - } - - } - - return valid; -} -static void page_pressed_hadler(lv_obj_t * tab, lv_dispi_t * dispi) -{ - lv_tab_ext_t * ext = lv_obj_get_ext(tab); - lv_dispi_get_point(dispi, &ext->point_last); -} - -static void page_pressing_hadler(lv_obj_t * tab, lv_obj_t * tab_page, lv_dispi_t * dispi) -{ - lv_tab_ext_t * ext = lv_obj_get_ext(tab); - point_t point_act; - lv_dispi_get_point(dispi, &point_act); - cord_t x_diff = point_act.x - ext->point_last.x; - cord_t y_diff = point_act.y - ext->point_last.y; - - if(ext->draging == 0) { - if(x_diff >= LV_DISPI_DRAG_LIMIT || x_diff<= -LV_DISPI_DRAG_LIMIT) { - ext->drag_h = 1; - ext->draging = 1; - lv_obj_set_drag(lv_page_get_scrl(tab_page), false); - } else if(y_diff >= LV_DISPI_DRAG_LIMIT || y_diff <= -LV_DISPI_DRAG_LIMIT) { - ext->drag_h = 0; - ext->draging = 1; - } - } - if(ext->drag_h != 0) { - lv_obj_set_x(ext->content, lv_obj_get_x(ext->content) + point_act.x - ext->point_last.x); - ext->point_last.x = point_act.x; - ext->point_last.y = point_act.y; - - /*Move the indicator*/ - cord_t indic_width = lv_obj_get_width(ext->indic); - cord_t p = (tab_page->cords.x1 * indic_width) / lv_obj_get_width(tab); - lv_style_t * indic_style = lv_obj_get_style(ext->indic); - lv_obj_set_x(ext->indic, indic_width * ext->tab_act - p + indic_style -> opad - ext->tab_act + indic_style->hpad); - } - -} - -static void page_press_lost_hadler(lv_obj_t * tab, lv_obj_t * tab_page, lv_dispi_t * dispi) -{ - lv_tab_ext_t * ext = lv_obj_get_ext(tab); - ext->drag_h = 0; - ext->draging = 0; - - lv_obj_set_drag(lv_page_get_scrl(tab_page), true); - - point_t point_act; - lv_dispi_get_point(dispi, &point_act); - cord_t x_diff = point_act.x - ext->point_last.x; - cord_t x_predict = 0; - - while(x_diff != 0) { - x_predict += x_diff; - x_diff = x_diff * (100 - LV_DISPI_DRAG_THROW) / 100; - } - - printf("predict: %d\n", x_predict); - - cord_t page_x1 = tab_page->cords.x1 + x_predict; - cord_t page_x2 = tab_page->cords.x2 + x_predict; - - if(page_x1 > (tab->cords.x2 - tab->cords.x1) / 2) { - printf("Right\n"); - if(ext->tab_act != 0) ext->tab_act--; - } else if(page_x2 < (tab->cords.x2 - tab->cords.x1) / 2) { - printf("Left\n"); - if(ext->tab_act < ext->tab_num - 1) ext->tab_act++; - } - - lv_tab_set_act(tab, ext->tab_act); - -} - -static lv_action_res_t tab_btnm_action(lv_obj_t * tab_btnm, uint16_t id) -{ - lv_obj_t * tab = lv_obj_get_parent(tab_btnm); - lv_tab_ext_t * ext = lv_obj_get_ext(tab); - ext->tab_act = id; - lv_tab_set_act(tab, id); - - return LV_ACTION_RES_OK; -} - -#endif diff --git a/lv_objx/lv_tab.h b/lv_objx/lv_tab.h deleted file mode 100644 index 42f252bb9..000000000 --- a/lv_objx/lv_tab.h +++ /dev/null @@ -1,84 +0,0 @@ -/** - * @file lv_tab.h - * - */ - -#ifndef LV_TAB_H -#define LV_TAB_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#include "lv_conf.h" -#if USE_LV_TAB != 0 - -#include "../lv_obj/lv_obj.h" -#include "../lv_objx/lv_win.h" - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ -/*Data of tab*/ -typedef struct -{ - /*Ext. of ancestor*/ - /*New data for this type */ - lv_obj_t * tabs; - lv_obj_t * indic; - lv_obj_t * content; /*A rectangle to show the current tab*/ - const char ** tab_name_ptr; - point_t point_last; - uint16_t tab_act; - uint16_t tab_num; - uint8_t draging :1; - uint8_t drag_h :1; - -}lv_tab_ext_t; - -/********************** - * GLOBAL PROTOTYPES - **********************/ - -/** - * Create a tab objects - * @param par pointer to an object, it will be the parent of the new tab - * @param copy pointer to a tab object, if not NULL then the new object will be copied from it - * @return pointer to the created tab - */ -lv_obj_t * lv_tab_create(lv_obj_t * par, lv_obj_t * copy); - -/** - * Signal function of the tab - * @param tab pointer to a tab object - * @param sign a signal type from lv_signal_t enum - * @param param pointer to a signal specific variable - * @return true: the object is still valid (not deleted), false: the object become invalid - */ -bool lv_tab_signal(lv_obj_t * tab, lv_signal_t sign, void * param); - -lv_obj_t * lv_tab_add(lv_obj_t * tab, const char * name); - - -lv_obj_t * lv_tab_add_scrollable(lv_obj_t * tab, const char * name); - - - -/********************** - * MACROS - **********************/ - -#endif /*USE_LV_TAB*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_TAB_H*/ diff --git a/lv_objx/lv_tabview.c b/lv_objx/lv_tabview.c new file mode 100644 index 000000000..d66ef2d57 --- /dev/null +++ b/lv_objx/lv_tabview.c @@ -0,0 +1,587 @@ +/** + * @file lv_tab.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_conf.h" +#if USE_LV_TABVIEW != 0 + +#include +#include "lv_btnm.h" +#include "misc/gfx/anim.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +#if 0 /*Unused*/ +static bool lv_tab_design(lv_obj_t * tab, const area_t * mask, lv_design_mode_t mode); +#endif + +static bool tabpage_signal(lv_obj_t * tab_page, lv_signal_t sign, void * param); +static bool tabscrl_signal(lv_obj_t * tab_scrl, lv_signal_t sign, void * param); + +static void tabpage_pressed_hadler(lv_obj_t * tabview, lv_obj_t * tabpage, lv_dispi_t * dispi); +static void tabpage_pressing_hadler(lv_obj_t * tabview, lv_obj_t * tabpage, lv_dispi_t * dispi); +static void tabpage_press_lost_hadler(lv_obj_t * tabview, lv_obj_t * tabpage, lv_dispi_t * dispi); +static lv_action_res_t tab_btnm_action(lv_obj_t * tab_btnm, uint16_t id); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_signal_f_t page_scrl_signal; +static const char * tab_def[] = {""}; +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/*----------------- + * Create function + *-----------------*/ + +/** + * Create a Tab view object + * @param par pointer to an object, it will be the parent of the new tab + * @param copy pointer to a tab object, if not NULL then the new object will be copied from it + * @return pointer to the created tab + */ +lv_obj_t * lv_tabview_create(lv_obj_t * par, lv_obj_t * copy) +{ + /*Create the ancestor of tab*/ + lv_obj_t * new_tabview = lv_obj_create(par, copy); + dm_assert(new_tabview); + + /*Allocate the tab type specific extended data*/ + lv_tabview_ext_t * ext = lv_obj_alloc_ext(new_tabview, sizeof(lv_tabview_ext_t)); + dm_assert(ext); + + /*Initialize the allocated 'ext' */ + ext->drag_h = 0; + ext->draging = 0; + ext->tab_act = 0; + ext->point_last.x = 0; + ext->point_last.y = 0; + ext->content = NULL; + ext->indic = NULL; + ext->tabs = NULL; + ext->tab_name_ptr = dm_alloc(sizeof(char*)); + ext->tab_name_ptr[0] = ""; + + /*The signal and design functions are not copied so set them here*/ + lv_obj_set_signal_f(new_tabview, lv_tabview_signal); + + /*Init the new tab tab*/ + if(copy == NULL) { + lv_obj_set_size(new_tabview, LV_HOR_RES, LV_VER_RES); + lv_obj_set_style(new_tabview, lv_style_get(LV_STYLE_PRETTY, NULL)); + + ext->tabs = lv_btnm_create(new_tabview, NULL); + lv_btnm_set_map(ext->tabs, tab_def); + lv_obj_set_height(ext->tabs, 3 * LV_DPI / 4); + lv_btnm_set_action(ext->tabs, tab_btnm_action); + lv_btnm_set_tgl(ext->tabs, true, 0); + + ext->indic = lv_obj_create(ext->tabs, NULL); + lv_style_t * style_indic = lv_obj_get_style(ext->indic); + lv_obj_set_size(ext->indic, LV_DPI, style_indic->line_width); + lv_obj_align(ext->indic, ext->tabs, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); + lv_obj_set_click(ext->indic, false); + + ext->content = lv_cont_create(new_tabview, NULL); + lv_cont_set_fit(ext->content, true, false); + lv_cont_set_layout(ext->content, LV_CONT_LAYOUT_ROW_T); + lv_obj_set_height(ext->content, LV_VER_RES); + lv_obj_set_style(ext->content, lv_style_get(LV_STYLE_TRANSP_TIGHT, NULL)); + lv_obj_align(ext->content, ext->tabs, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0); + } + /*Copy an existing tab*/ + else { + lv_tabview_ext_t * copy_ext = lv_obj_get_ext(copy); + ext->point_last.x = 0; + ext->point_last.y = 0; + ext->tabs = lv_btnm_create(new_tabview, copy_ext->tabs); + ext->indic = lv_obj_create(ext->tabs, copy_ext->indic); + ext->content = lv_cont_create(new_tabview, copy_ext->content); + + ext->tab_name_ptr = dm_alloc(sizeof(char*)); + ext->tab_name_ptr[0] = ""; + lv_btnm_set_map(ext->tabs, ext->tab_name_ptr); + + uint16_t i; + for (i = 0; i < copy_ext->tab_cnt; i++) { + lv_tabview_add_tab(new_tabview, copy_ext->tab_name_ptr[i]); + } + + + /*Refresh the style with new signal function*/ + lv_obj_refr_style(new_tabview); + } + + return new_tabview; +} + +/** + * Signal function of the Tab view + * @param tabview pointer to a Tab view object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return true: the object is still valid (not deleted), false: the object become invalid + */ +bool lv_tabview_signal(lv_obj_t * tabview, lv_signal_t sign, void * param) +{ + bool valid; + + /* Include the ancient signal function */ + valid = lv_obj_signal(tabview, sign, param); + + /* The object can be deleted so check its validity and then + * make the object specific signal handling */ + if(valid != false) { + if(sign == LV_SIGNAL_CLEANUP) { + /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/ + } else if(sign == LV_SIGNAL_CORD_CHG) { + lv_tabview_ext_t * ext = lv_obj_get_ext(tabview); + if(ext->content != NULL && + (lv_obj_get_width(tabview) != area_get_width(param) || + lv_obj_get_height(tabview) != area_get_height(param))) + { + lv_tabview_realign(tabview); + } + } + } + + return valid; +} + +/*====================== + * Add/remove functions + *=====================*/ + +/** + * Add a new tab with the given name + * @param tabview pointer to Tab view object where to ass the new tab + * @param name the text on the tab button + * @return pointer to page object (lv_page) which is the containter of the contet + */ +lv_obj_t * lv_tabview_add_tab(lv_obj_t * tabview, const char * name) +{ + lv_tabview_ext_t * ext = lv_obj_get_ext(tabview); + + /*Create the container page*/ + lv_obj_t * h = lv_page_create(ext->content, NULL); + lv_obj_set_size(h, lv_obj_get_width(tabview), lv_obj_get_height(tabview)); + lv_obj_set_style(h, lv_style_get(LV_STYLE_PRETTY_COLOR, NULL)); + lv_obj_set_signal_f(h, tabpage_signal); + lv_page_set_sb_mode(h, LV_PAGE_SB_MODE_AUTO); + if(page_scrl_signal == NULL) page_scrl_signal = lv_obj_get_signal_f(lv_page_get_scrl(h)); + lv_obj_set_signal_f(lv_page_get_scrl(h), tabscrl_signal); + + /*Extend the button matrix map with the new name*/ + ext->tab_cnt++; + ext->tab_name_ptr = dm_realloc(ext->tab_name_ptr, sizeof(char *) * (ext->tab_cnt + 1)); + ext->tab_name_ptr[ext->tab_cnt - 1] = name; + ext->tab_name_ptr[ext->tab_cnt] = ""; + + lv_btnm_set_map(ext->tabs, ext->tab_name_ptr); + + /*Modify the indicator size*/ + lv_style_t * style_tabs = lv_obj_get_style(ext->tabs); + cord_t indic_width = (lv_obj_get_width(tabview) - style_tabs->opad * (ext->tab_cnt - 1) - 2 * style_tabs->hpad) / ext->tab_cnt; + lv_obj_set_width(ext->indic, indic_width); + lv_obj_set_x(ext->indic, indic_width * ext->tab_act + style_tabs->opad * ext->tab_act + style_tabs->hpad); + + return h; +} + +/*===================== + * Setter functions + *====================*/ + +/** + * Set a new tab + * @param tabview pointer to Tab view object + * @param id index of a tab to load + * @param anim_en true: set with sliding animation; false: set immediately + */ +void lv_tabview_set_act(lv_obj_t * tabview, uint16_t id, bool anim_en) +{ + lv_tabview_ext_t * ext = lv_obj_get_ext(tabview); + lv_style_t * style = lv_obj_get_style(ext->content); + + ext->tab_act = id >= ext->tab_cnt ? ext->tab_cnt - 1 : id; + +#if LV_TABVIEW_ANIM_TIME == 0 + anim_en = false; +#endif + + cord_t cont_x = -(lv_obj_get_width(tabview) * id + style->opad * id + style->hpad); + if(anim_en == false) { + lv_obj_set_x(ext->content, cont_x); + } else { + anim_t a; + a.var = ext->content; + a.start = lv_obj_get_x(ext->content); + a.end = cont_x; + a.fp = (anim_fp_t)lv_obj_set_x; + a.path = anim_get_path(ANIM_PATH_LIN); + a.end_cb = NULL; + a.act_time = 0; + a.time = LV_TABVIEW_ANIM_TIME; + a.playback = 0; + a.playback_pause = 0; + a.repeat = 0; + a.repeat_pause = 0; + anim_create(&a); + } + + /*Move the indicator*/ + cord_t indic_width = lv_obj_get_width(ext->indic); + lv_style_t * tabs_style = lv_obj_get_style(ext->tabs); + cord_t indic_x = indic_width * id + tabs_style->opad * id + tabs_style->hpad; + + if(anim_en == false) { + lv_obj_set_x(ext->indic, indic_x); + } else { + anim_t a; + a.var = ext->indic; + a.start = lv_obj_get_x(ext->indic); + a.end = indic_x; + a.fp = (anim_fp_t)lv_obj_set_x; + a.path = anim_get_path(ANIM_PATH_LIN); + a.end_cb = NULL; + a.act_time = 0; + a.time = LV_TABVIEW_ANIM_TIME; + a.playback = 0; + a.playback_pause = 0; + a.repeat = 0; + a.repeat_pause = 0; + anim_create(&a); + } + + lv_btnm_set_tgl(ext->tabs, true, ext->tab_act); +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the index of the currently active tab + * @param tabview pointer to Tab view object + * @return the active tab index + */ +uint16_t lv_tabview_get_tab_act(lv_obj_t * tabview) +{ + lv_tabview_ext_t * ext = lv_obj_get_ext(tabview); + return ext->tab_act; +} + +/** + * Get the number of tabs + * @param tabview pointer to Tab view object + * @return tab count + */ +uint16_t lv_tabview_get_tab_cnt(lv_obj_t * tabview) +{ + lv_tabview_ext_t * ext = lv_obj_get_ext(tabview); + return ext->tab_cnt; +} + +/** + * Get the page (content area) of a tab + * @param tabview pointer to Tab view object + * @param id index of the tab (>= 0) + * @return pointer to page (lv_page) object + */ +lv_obj_t * lv_tabview_get_tab_page(lv_obj_t * tabview, uint16_t id) +{ + lv_tabview_ext_t * ext = lv_obj_get_ext(tabview); + uint16_t i = 0; + lv_obj_t * page = lv_obj_get_child(ext->content, NULL); + + while(page != NULL && i != id) { + i++; + page = lv_obj_get_child(ext->content, page); + } + + if(i == id) return page; + + return NULL; +} + +/** + * Get the tab button matrix (lv_btnm) of a Tab view + * @param tabview pointer to Tab view object + * @return pointer to button matrix (lv_btnm) object which is the tab buttons + */ +lv_obj_t * lv_tabview_get_tabs(lv_obj_t * tabview) +{ + lv_tabview_ext_t * ext = lv_obj_get_ext(tabview); + return ext->tabs; +} + +/** + * Get the indicator rectangle (lv_obj) of a Tab view + * @param tabview pointer to Tab view object + * @return pointer to Base object (lv_obj) which is the indicator rectangle on the tab buttons + */ +lv_obj_t * lv_tabview_get_indic(lv_obj_t * tabview) +{ + lv_tabview_ext_t * ext = lv_obj_get_ext(tabview); + return ext->indic; +} + +/*===================== + * Other functions + *====================*/ + +/** + * Realign and resize the elements of Tab view + * @param tabview pointer to a Tab view object + */ +void lv_tabview_realign(lv_obj_t * tabview) +{ + lv_tabview_ext_t * ext = lv_obj_get_ext(tabview); + + lv_obj_set_width(ext->tabs, lv_obj_get_width(tabview)); + lv_obj_set_height(ext->content, lv_obj_get_height(tabview) - lv_obj_get_height(ext->tabs)); + lv_obj_align(ext->content, ext->tabs, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0); + lv_obj_t * pages = lv_obj_get_child(ext->content, NULL); + while(pages != NULL) { + lv_obj_set_size(pages, lv_obj_get_width(tabview), lv_obj_get_height(tabview) - lv_obj_get_height(ext->tabs)); + pages = lv_obj_get_child(ext->content, pages); + } + + if(ext->tab_cnt != 0) { + lv_style_t * style_tabs = lv_obj_get_style(ext->tabs); + cord_t indic_width = (lv_obj_get_width(tabview) - style_tabs->opad * (ext->tab_cnt - 1) - + 2 * style_tabs->hpad) / ext->tab_cnt; + lv_obj_set_width(ext->indic, indic_width); + } + + lv_obj_align(ext->indic, ext->tabs, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); + + lv_tabview_set_act(tabview, ext->tab_act, false); +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +#if 0 /*Unused*/ +/** + * Handle the drawing related tasks of the tabs + * @param tab 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_tab_design(lv_obj_t * tab, const area_t * mask, lv_design_mode_t mode) +{ + /*Return false if the object is not covers the mask_p area*/ + if(mode == LV_DESIGN_COVER_CHK) { + return false; + } + /*Draw the object*/ + else if(mode == LV_DESIGN_DRAW_MAIN) { + + } + /*Post draw when the children are drawn*/ + else if(mode == LV_DESIGN_DRAW_POST) { + + } + + return true; +} +#endif + +/** + * Signal function of a tab's page + * @param tab pointer to a tab page object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return true: the object is still valid (not deleted), false: the object become invalid + */ +static bool tabpage_signal(lv_obj_t * tab_page, lv_signal_t sign, void * param) +{ + bool valid; + + /* Include the ancient signal function */ + valid = lv_page_signal(tab_page, sign, param); + + /* The object can be deleted so check its validity and then + * make the object specific signal handling */ + if(valid != false) { + lv_obj_t * cont = lv_obj_get_parent(tab_page); + lv_obj_t * tab = lv_obj_get_parent(cont); + if(sign == LV_SIGNAL_PRESSED) { + tabpage_pressed_hadler(tab, tab_page, param); + } + else if(sign == LV_SIGNAL_PRESSING) { + tabpage_pressing_hadler(tab, tab_page, param); + } + else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) { + tabpage_press_lost_hadler(tab, tab_page, param); + } + + } + + return valid; +} +/** + * Signal function of the tab page's scrollable object + * @param tab_scrl pointer to a tab page's scrollable object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return true: the object is still valid (not deleted), false: the object become invalid + */ +static bool tabscrl_signal(lv_obj_t * tab_scrl, lv_signal_t sign, void * param) +{ + bool valid; + + /* Include the ancient signal function */ + valid = page_scrl_signal(tab_scrl, sign, param); + + /* The object can be deleted so check its validity and then + * make the object specific signal handling */ + if(valid != false) { + lv_obj_t * tab_page = lv_obj_get_parent(tab_scrl); + lv_obj_t * cont = lv_obj_get_parent(tab_page); + lv_obj_t * tab = lv_obj_get_parent(cont); + if(sign == LV_SIGNAL_PRESSED) { + tabpage_pressed_hadler(tab, tab_page, param); + } + else if(sign == LV_SIGNAL_PRESSING) { + tabpage_pressing_hadler(tab, tab_page, param); + } + else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) { + tabpage_press_lost_hadler(tab, tab_page, param); + } + + } + + return valid; +} + +/** + * Called when a tab's page or scrollable object is pressed + * @param tabview pointer to the tab view object + * @param tabpage pointer to the page of a tab + * @param dispi pointer to the caller dispi + */ +static void tabpage_pressed_hadler(lv_obj_t * tabview, lv_obj_t * tabpage, lv_dispi_t * dispi) +{ + lv_tabview_ext_t * ext = lv_obj_get_ext(tabview); + lv_dispi_get_point(dispi, &ext->point_last); +} + +/** + * Called when a tab's page or scrollable object is being pressed + * @param tabview pointer to the tab view object + * @param tabpage pointer to the page of a tab + * @param dispi pointer to the caller dispi + */ +static void tabpage_pressing_hadler(lv_obj_t * tabview, lv_obj_t * tabpage, lv_dispi_t * dispi) +{ + lv_tabview_ext_t * ext = lv_obj_get_ext(tabview); + point_t point_act; + lv_dispi_get_point(dispi, &point_act); + cord_t x_diff = point_act.x - ext->point_last.x; + cord_t y_diff = point_act.y - ext->point_last.y; + + if(ext->draging == 0) { + if(x_diff >= LV_DISPI_DRAG_LIMIT || x_diff<= -LV_DISPI_DRAG_LIMIT) { + ext->drag_h = 1; + ext->draging = 1; + lv_obj_set_drag(lv_page_get_scrl(tabpage), false); + } else if(y_diff >= LV_DISPI_DRAG_LIMIT || y_diff <= -LV_DISPI_DRAG_LIMIT) { + ext->drag_h = 0; + ext->draging = 1; + } + } + if(ext->drag_h != 0) { + lv_obj_set_x(ext->content, lv_obj_get_x(ext->content) + point_act.x - ext->point_last.x); + ext->point_last.x = point_act.x; + ext->point_last.y = point_act.y; + + /*Move the indicator*/ + cord_t indic_width = lv_obj_get_width(ext->indic); + lv_style_t * tabs_style = lv_obj_get_style(ext->tabs); + lv_style_t * indic_style = lv_obj_get_style(ext->indic); + cord_t p = ((tabpage->cords.x1 - tabview->cords.x1) * (indic_width + tabs_style->opad)) / lv_obj_get_width(tabview); + + lv_obj_set_x(ext->indic, indic_width * ext->tab_act + tabs_style->opad * ext->tab_act + indic_style->hpad - p); + } +} + +/** + * Called when a tab's page or scrollable object is released or the press id lost + * @param tabview pointer to the tab view object + * @param tabpage pointer to the page of a tab + * @param dispi pointer to the caller dispi + */ +static void tabpage_press_lost_hadler(lv_obj_t * tabview, lv_obj_t * tabpage, lv_dispi_t * dispi) +{ + lv_tabview_ext_t * ext = lv_obj_get_ext(tabview); + ext->drag_h = 0; + ext->draging = 0; + + lv_obj_set_drag(lv_page_get_scrl(tabpage), true); + + point_t point_act; + lv_dispi_get_point(dispi, &point_act); + cord_t x_diff = point_act.x - ext->point_last.x; + cord_t x_predict = 0; + + while(x_diff != 0) { + x_predict += x_diff; + x_diff = x_diff * (100 - LV_DISPI_DRAG_THROW) / 100; + } + + + cord_t page_x1 = tabpage->cords.x1 + x_predict; + cord_t page_x2 = tabpage->cords.x2 + x_predict; + + if(page_x1 > (tabview->cords.x2 - tabview->cords.x1) / 2) { + if(ext->tab_act != 0) ext->tab_act--; + } else if(page_x2 < (tabview->cords.x2 - tabview->cords.x1) / 2) { + if(ext->tab_act < ext->tab_cnt - 1) ext->tab_act++; + } + + lv_tabview_set_act(tabview, ext->tab_act, true); +} + +/** + * Called when a tab button is released + * @param tab_btnm pointer to the tab's button matrix object + * @param id the id of the tab (>= 0) + * @return LV_ACTION_RES_OK because the button matrix in not deleted in the function + */ +static lv_action_res_t tab_btnm_action(lv_obj_t * tab_btnm, uint16_t id) +{ + lv_obj_t * tab = lv_obj_get_parent(tab_btnm); + lv_tabview_ext_t * ext = lv_obj_get_ext(tab); + ext->tab_act = id; + lv_tabview_set_act(tab, id, true); + + return LV_ACTION_RES_OK; +} + +#endif diff --git a/lv_objx/lv_tabview.h b/lv_objx/lv_tabview.h new file mode 100644 index 000000000..173e3f167 --- /dev/null +++ b/lv_objx/lv_tabview.h @@ -0,0 +1,144 @@ +/** + * @file lv_tabview.h + * + */ + +#ifndef LV_TABVIEW_H +#define LV_TABVIEW_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "lv_conf.h" +#if USE_LV_TABVIEW != 0 + + +/*Testing of dependencies*/ +#if USE_LV_BTNM == 0 +#error "lv_tabview: lv_btnm is required. Enable it in lv_conf.h (USE_LV_BTNM 1) " +#endif + +#if USE_LV_PAGE == 0 +#error "lv_tabview: lv_page is required. Enable it in lv_conf.h (USE_LV_PAGE 1) " +#endif + +#include "../lv_obj/lv_obj.h" +#include "../lv_objx/lv_win.h" +#include "../lv_objx/lv_page.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +/*Data of tab*/ +typedef struct +{ + /*Ext. of ancestor*/ + /*New data for this type */ + lv_obj_t * tabs; + lv_obj_t * indic; + lv_obj_t * content; /*A rectangle to show the current tab*/ + const char ** tab_name_ptr; + point_t point_last; + uint16_t tab_act; + uint16_t tab_cnt; + uint8_t draging :1; + uint8_t drag_h :1; + +}lv_tabview_ext_t; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a Tab view objects + * @param par pointer to an object, it will be the parent of the new tab + * @param copy pointer to a tab object, if not NULL then the new object will be copied from it + * @return pointer to the created tab + */ +lv_obj_t * lv_tabview_create(lv_obj_t * par, lv_obj_t * copy); + +/** + * Signal function of the Tab view + * @param tab pointer to a tab object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return true: the object is still valid (not deleted), false: the object become invalid + */ +bool lv_tabview_signal(lv_obj_t * tab, lv_signal_t sign, void * param); + +/** + * Realign and resize the elements of Tab view + * @param tabview pointer to a Tab view object + */ +void lv_tabview_realign(lv_obj_t * tabview); +/** + * Set a new tab + * @param tabview pointer to Tab view object + * @param id index of a tab to load + * @param anim_en true: set with sliding animation; false: set immediately + */ +void lv_tabview_set_act(lv_obj_t * tabview, uint16_t id, bool anim_en); + +/** + * Get the index of the currently active tab + * @param tabview pointer to Tab view object + * @return the active tab index + */ +uint16_t lv_tabview_get_tab_act(lv_obj_t * tabview); +/** + * Get the number of tabs + * @param tabview pointer to Tab view object + * @return tab count + */ +uint16_t lv_tabview_get_tab_cnt(lv_obj_t * tabview); + +/** + * Get the page (content area) of a tab + * @param tabview pointer to Tab view object + * @param id index of the tab (>= 0) + * @return pointer to page (lv_page) object + */ +lv_obj_t * lv_tabview_get_tab_page(lv_obj_t * tabview, uint16_t id); + +/** + * Get the tab button matrix (lv_btnm) of a Tab view + * @param tabview pointer to Tab view object + * @return pointer to button matrix (lv_btnm) object which is the tab buttons + */ +lv_obj_t * lv_tabview_get_tabs(lv_obj_t * tabview); +/** + * Get the indicator rectangle (lv_obj) of a Tab view + * @param tabview pointer to Tab view object + * @return pointer to Base object (lv_obj) which is the indicator rectangle on the tab buttons + */ +lv_obj_t * lv_tabview_get_indic(lv_obj_t * tabview); + +/** + * Add a new tab with the given name + * @param tabview pointer to Tab view object where to ass the new tab + * @param name the text on the tab button + * @return pointer to page object (lv_page) which is the containter of the contet + */ +lv_obj_t * lv_tabview_add_tab(lv_obj_t * tabview, const char * name); + + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_TABVIEW*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_TAB_H*/