BigW Consortium Gitlab

Commit bf1903d1 by Gabor Kiss-Vamosi

API updates

parent 2ea1af59
...@@ -42,7 +42,7 @@ static lv_indev_t *indev_list = NULL; ...@@ -42,7 +42,7 @@ static lv_indev_t *indev_list = NULL;
* @param driver Input Device driver structure * @param driver Input Device driver structure
* @return pointer to the new input device * @return pointer to the new input device
*/ */
lv_indev_t * lv_indev_drv_register(lv_hal_indev_drv_t *driver) lv_indev_t * lv_indev_register(lv_hal_indev_drv_t *driver)
{ {
lv_indev_t *node; lv_indev_t *node;
...@@ -88,7 +88,7 @@ lv_indev_t * lv_indev_next(lv_indev_t * indev) ...@@ -88,7 +88,7 @@ lv_indev_t * lv_indev_next(lv_indev_t * indev)
* @param data input device will write its data here * @param data input device will write its data here
* @return false: no more data; true: there more data to read (buffered) * @return false: no more data; true: there more data to read (buffered)
*/ */
bool lv_indev_get(lv_indev_t * indev, lv_hal_indev_data_t *data) bool lv_indev_read(lv_indev_t * indev, lv_hal_indev_data_t *data)
{ {
bool cont = false; bool cont = false;
......
...@@ -17,8 +17,8 @@ extern "C" { ...@@ -17,8 +17,8 @@ extern "C" {
*********************/ *********************/
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include "lv_hal.h"
#include "misc/gfx/area.h" #include "misc/gfx/area.h"
#include <lvgl/lv_hal/lv_hal.h>
/********************* /*********************
* DEFINES * DEFINES
...@@ -99,15 +99,15 @@ typedef struct _lv_indev_t { ...@@ -99,15 +99,15 @@ typedef struct _lv_indev_t {
* @param driver Input Device driver structure * @param driver Input Device driver structure
* @return 0 on success, -ve on error * @return 0 on success, -ve on error
*/ */
lv_indev_t * lv_indev_drv_register(lv_hal_indev_drv_t *driver); lv_indev_t * lv_indev_register(lv_hal_indev_drv_t *driver);
/** /**
* Ask data fro man input device. * Ask data from an input device.
* @param data input device data * @param data input device data
* @return false: no more data; true: there more data to read (buffered) * @return false: no more data; true: there more data to read (buffered)
*/ */
bool lv_indev_get(lv_indev_t * indev, lv_hal_indev_data_t *data); bool lv_indev_read(lv_indev_t * indev, lv_hal_indev_data_t *data);
/** /**
* Get the next input device. * Get the next input device.
......
...@@ -201,7 +201,7 @@ static void indev_proc_task(void * param) ...@@ -201,7 +201,7 @@ static void indev_proc_task(void * param)
if(i->state.disable == 0) { if(i->state.disable == 0) {
/*Read the data*/ /*Read the data*/
lv_indev_get(i, &data); lv_indev_read(i, &data);
i->state.pressed = data.state; i->state.pressed = data.state;
/*Move the cursor if set and moved*/ /*Move the cursor if set and moved*/
...@@ -283,12 +283,12 @@ static void indev_proc_press(lv_indev_state_t * state) ...@@ -283,12 +283,12 @@ static void indev_proc_press(lv_indev_state_t * state)
/*If there is no last object then search*/ /*If there is no last object then search*/
if(state->act_obj == NULL) { if(state->act_obj == NULL) {
pr_obj = indev_search_obj(state, lv_layer_top()); pr_obj = indev_search_obj(state, lv_layer_top());
if(pr_obj == NULL) pr_obj = indev_search_obj(state, lv_screen_act()); if(pr_obj == NULL) pr_obj = indev_search_obj(state, lv_scr_act());
} }
/*If there is last object but it is not dragged also search*/ /*If there is last object but it is not dragged also search*/
else if(state->drag_in_prog == 0) {/*Now act_obj != NULL*/ else if(state->drag_in_prog == 0) {/*Now act_obj != NULL*/
pr_obj = indev_search_obj(state, lv_layer_top()); pr_obj = indev_search_obj(state, lv_layer_top());
if(pr_obj == NULL) pr_obj = indev_search_obj(state, lv_screen_act()); if(pr_obj == NULL) pr_obj = indev_search_obj(state, lv_scr_act());
} }
/*If a dragable object was the last then keep it*/ /*If a dragable object was the last then keep it*/
else { else {
...@@ -520,7 +520,6 @@ static void indev_drag_throw(lv_indev_state_t * state) ...@@ -520,7 +520,6 @@ static void indev_drag_throw(lv_indev_state_t * state)
lv_obj_t * drag_obj = state->last_obj; lv_obj_t * drag_obj = state->last_obj;
/*If drag parent is active check recursively the drag_parent attribute*/ /*If drag parent is active check recursively the drag_parent attribute*/
while(lv_obj_get_drag_parent(drag_obj) != false && while(lv_obj_get_drag_parent(drag_obj) != false &&
drag_obj != NULL) { drag_obj != NULL) {
drag_obj = lv_obj_get_parent(drag_obj); drag_obj = lv_obj_get_parent(drag_obj);
......
...@@ -364,7 +364,7 @@ void lv_obj_invalidate(lv_obj_t * obj) ...@@ -364,7 +364,7 @@ void lv_obj_invalidate(lv_obj_t * obj)
{ {
/*Invalidate the object only if it belongs to the 'act_scr'*/ /*Invalidate the object only if it belongs to the 'act_scr'*/
lv_obj_t * obj_scr = lv_obj_get_screen(obj); lv_obj_t * obj_scr = lv_obj_get_screen(obj);
if(obj_scr == lv_screen_act() || if(obj_scr == lv_scr_act() ||
obj_scr == lv_layer_top() || obj_scr == lv_layer_top() ||
obj_scr == lv_layer_sys()) { obj_scr == lv_layer_sys()) {
/*Truncate recursively to the parents*/ /*Truncate recursively to the parents*/
...@@ -404,7 +404,7 @@ void lv_obj_invalidate(lv_obj_t * obj) ...@@ -404,7 +404,7 @@ void lv_obj_invalidate(lv_obj_t * obj)
* Load a new screen * Load a new screen
* @param scr pointer to a screen * @param scr pointer to a screen
*/ */
void lv_screen_load(lv_obj_t * scr) void lv_scr_load(lv_obj_t * scr)
{ {
act_scr = scr; act_scr = scr;
...@@ -496,10 +496,10 @@ void lv_obj_set_pos(lv_obj_t * obj, cord_t x, cord_t y) ...@@ -496,10 +496,10 @@ void lv_obj_set_pos(lv_obj_t * obj, cord_t x, cord_t y)
/** /**
* Set relative the position of an object (relative to the parent). * Set relative the position of an object (relative to the parent).
* The coordinates will be upscaled with LV_DOWNSCALE. * The coordinates will be up scaled LV_ANTIALIAS is enabled.
* @param obj pointer to an object * @param obj pointer to an object
* @param x new distance from the left side of the parent. (will be multiplied with LV_DOWNSCALE) * @param x new distance from the left side of the parent.
* @param y new distance from the top of the parent. (will be multiplied with LV_DOWNSCALE) * @param y new distance from the top of the parent.
*/ */
void lv_obj_set_pos_scale(lv_obj_t * obj, cord_t x, cord_t y) void lv_obj_set_pos_scale(lv_obj_t * obj, cord_t x, cord_t y)
{ {
...@@ -518,9 +518,9 @@ void lv_obj_set_x(lv_obj_t * obj, cord_t x) ...@@ -518,9 +518,9 @@ void lv_obj_set_x(lv_obj_t * obj, cord_t x)
/** /**
* Set the x coordinate of a object. * Set the x coordinate of a object.
* The coordinate will be upscaled with LV_DOWNSCALE. * The coordinate will be up scaled LV_ANTIALIAS is enabled.
* @param obj pointer to an object * @param obj pointer to an object
* @param x new distance from the left side from the parent. (will be multiplied with LV_DOWNSCALE) * @param x new distance from the left side from the parent.
*/ */
void lv_obj_set_x_scale(lv_obj_t * obj, cord_t x) void lv_obj_set_x_scale(lv_obj_t * obj, cord_t x)
{ {
...@@ -539,9 +539,9 @@ void lv_obj_set_y(lv_obj_t * obj, cord_t y) ...@@ -539,9 +539,9 @@ void lv_obj_set_y(lv_obj_t * obj, cord_t y)
/** /**
* Set the y coordinate of a object. * Set the y coordinate of a object.
* The coordinate will be upscaled with LV_DOWNSCALE. * The coordinate will be up scaled LV_ANTIALIAS is enabled.
* @param obj pointer to an object * @param obj pointer to an object
* @param y new distance from the top of the parent. (will be multiplied with LV_DOWNSCALE) * @param y new distance from the top of the parent.
*/ */
void lv_obj_set_y_scale(lv_obj_t * obj, cord_t y) void lv_obj_set_y_scale(lv_obj_t * obj, cord_t y)
{ {
...@@ -588,10 +588,11 @@ void lv_obj_set_size(lv_obj_t * obj, cord_t w, cord_t h) ...@@ -588,10 +588,11 @@ void lv_obj_set_size(lv_obj_t * obj, cord_t w, cord_t h)
} }
/** /**
* Set the size of an object. The coordinates will be upscaled with LV_DOWNSCALE. * Set the size of an object.
* The coordinates will be up scaled LV_ANTIALIAS is enabled.
* @param obj pointer to an object * @param obj pointer to an object
* @param w new width (will be multiplied with LV_DOWNSCALE) * @param w new width
* @param h new height (will be multiplied with LV_DOWNSCALE) * @param h new height
*/ */
void lv_obj_set_size_scale(lv_obj_t * obj, cord_t w, cord_t h) void lv_obj_set_size_scale(lv_obj_t * obj, cord_t w, cord_t h)
{ {
...@@ -609,9 +610,10 @@ void lv_obj_set_width(lv_obj_t * obj, cord_t w) ...@@ -609,9 +610,10 @@ void lv_obj_set_width(lv_obj_t * obj, cord_t w)
} }
/** /**
* Set the width of an object. The width will be upscaled with LV_DOWNSCALE * Set the width of an object.
* The coordinates will be up scaled LV_ANTIALIAS is enabled.
* @param obj pointer to an object * @param obj pointer to an object
* @param w new width (will be multiplied with LV_DOWNSCALE) * @param w new width
*/ */
void lv_obj_set_width_scale(lv_obj_t * obj, cord_t w) void lv_obj_set_width_scale(lv_obj_t * obj, cord_t w)
{ {
...@@ -629,9 +631,10 @@ void lv_obj_set_height(lv_obj_t * obj, cord_t h) ...@@ -629,9 +631,10 @@ void lv_obj_set_height(lv_obj_t * obj, cord_t h)
} }
/** /**
* Set the height of an object. The height will be upscaled with LV_DOWNSCALE * Set the height of an object.
* The coordinate will be up scaled LV_ANTIALIAS is enabled.
* @param obj pointer to an object * @param obj pointer to an object
* @param h new height (will be multiplied with LV_DOWNSCALE) * @param h new height
*/ */
void lv_obj_set_height_scale(lv_obj_t * obj, cord_t h) void lv_obj_set_height_scale(lv_obj_t * obj, cord_t h)
{ {
...@@ -777,30 +780,19 @@ void lv_obj_align(lv_obj_t * obj,lv_obj_t * base, lv_align_t align, cord_t x_mod ...@@ -777,30 +780,19 @@ void lv_obj_align(lv_obj_t * obj,lv_obj_t * base, lv_align_t align, cord_t x_mod
/** /**
* Align an object to an other object. The coordinates will be upscaled with LV_DOWNSCALE. * Align an object to an other object.
* The coordinates will be up scaled LV_ANTIALIAS is enabled.
* @param obj pointer to an object to align * @param obj pointer to an object to align
* @param base pointer to an object (if NULL the parent is used). 'obj' will be aligned to it. * @param base pointer to an object (if NULL the parent is used). 'obj' will be aligned to it.
* @param align type of alignment (see 'lv_align_t' enum) * @param align type of alignment (see 'lv_align_t' enum)
* @param x_mod x coordinate shift after alignment (will be multiplied with LV_DOWNSCALE) * @param x_mod x coordinate shift after alignment
* @param y_mod y coordinate shift after alignment (will be multiplied with LV_DOWNSCALE) * @param y_mod y coordinate shift after alignment
*/ */
void lv_obj_align_scale(lv_obj_t * obj,lv_obj_t * base, lv_align_t align, cord_t x_mod, cord_t y_mod) void lv_obj_align_scale(lv_obj_t * obj,lv_obj_t * base, lv_align_t align, cord_t x_mod, cord_t y_mod)
{ {
lv_obj_align(obj, base, align, x_mod << LV_ANTIALIAS, y_mod << LV_ANTIALIAS); lv_obj_align(obj, base, align, x_mod << LV_ANTIALIAS, y_mod << LV_ANTIALIAS);
} }
/**
* Set the extended size of an object
* @param obj pointer to an object
* @param ext_size the extended size
*/
void lv_obj_set_ext_size(lv_obj_t * obj, cord_t ext_size)
{
obj->ext_size = ext_size;
lv_obj_invalidate(obj);
}
/*--------------------- /*---------------------
* Appearance set * Appearance set
*--------------------*/ *--------------------*/
...@@ -1108,7 +1100,7 @@ void lv_obj_animate(lv_obj_t * obj, lv_anim_builtin_t type, uint16_t time, uint1 ...@@ -1108,7 +1100,7 @@ void lv_obj_animate(lv_obj_t * obj, lv_anim_builtin_t type, uint16_t time, uint1
* Return with the actual screen * Return with the actual screen
* @return pointer to the actual screen object * @return pointer to the actual screen object
*/ */
lv_obj_t * lv_screen_act(void) lv_obj_t * lv_scr_act(void)
{ {
return act_scr; return act_scr;
} }
......
...@@ -223,7 +223,7 @@ void lv_obj_invalidate(lv_obj_t * obj); ...@@ -223,7 +223,7 @@ void lv_obj_invalidate(lv_obj_t * obj);
* Load a new screen * Load a new screen
* @param scr pointer to a screen * @param scr pointer to a screen
*/ */
void lv_screen_load(lv_obj_t * scr); void lv_scr_load(lv_obj_t * scr);
/** /**
* Set a new parent for an object. Its relative position will be the same. * Set a new parent for an object. Its relative position will be the same.
...@@ -457,7 +457,7 @@ void * lv_obj_allocate_ext_attr(lv_obj_t * obj, uint16_t ext_size); ...@@ -457,7 +457,7 @@ void * lv_obj_allocate_ext_attr(lv_obj_t * obj, uint16_t ext_size);
*/ */
void lv_obj_refresh_ext_size(lv_obj_t * obj); void lv_obj_refresh_ext_size(lv_obj_t * obj);
#if LV_OBJ_FREE_NUMBER != 0 #if LV_OBJ_FREE_NUM != 0
/** /**
* Set an application specific number for an object. * Set an application specific number for an object.
* It can help to identify objects in the application. * It can help to identify objects in the application.
...@@ -467,7 +467,7 @@ void lv_obj_refresh_ext_size(lv_obj_t * obj); ...@@ -467,7 +467,7 @@ void lv_obj_refresh_ext_size(lv_obj_t * obj);
void lv_obj_set_free_number(lv_obj_t * obj, uint8_t free_number); void lv_obj_set_free_number(lv_obj_t * obj, uint8_t free_number);
#endif #endif
#if LV_OBJ_FREE_POINTER != 0 #if LV_OBJ_FREE_PTR != 0
/** /**
* Set an application specific pointer for an object. * Set an application specific pointer for an object.
* It can help to identify objects in the application. * It can help to identify objects in the application.
...@@ -491,7 +491,7 @@ void lv_obj_animate(lv_obj_t * obj, lv_anim_builtin_t type, uint16_t time, uint1 ...@@ -491,7 +491,7 @@ void lv_obj_animate(lv_obj_t * obj, lv_anim_builtin_t type, uint16_t time, uint1
* Return with the actual screen * Return with the actual screen
* @return pointer to to the actual screen object * @return pointer to to the actual screen object
*/ */
lv_obj_t * lv_screen_act(void);lv_obj_t * lv_layer_top(void); lv_obj_t * lv_scr_act(void);lv_obj_t * lv_layer_top(void);
/** /**
* Return with the system layer. (Same on every screen and it is above the all other layers) * Return with the system layer. (Same on every screen and it is above the all other layers)
...@@ -667,7 +667,7 @@ void * lv_obj_get_ext_attr(lv_obj_t * obj); ...@@ -667,7 +667,7 @@ void * lv_obj_get_ext_attr(lv_obj_t * obj);
uint8_t lv_obj_get_free_num(lv_obj_t * obj); uint8_t lv_obj_get_free_num(lv_obj_t * obj);
#endif #endif
#if LV_OBJ_FREE_P != 0 #if LV_OBJ_FREE_PTR != 0
/** /**
* Get the free pointer * Get the free pointer
* @param obj pointer to an object * @param obj pointer to an object
...@@ -684,9 +684,11 @@ void * lv_obj_get_free_p(lv_obj_t * obj); ...@@ -684,9 +684,11 @@ void * lv_obj_get_free_p(lv_obj_t * obj);
*/ */
void * lv_obj_get_group(lv_obj_t * obj); void * lv_obj_get_group(lv_obj_t * obj);
#endif #endif
/********************** /**********************
* MACROS * MACROS
**********************/ **********************/
#define LV_SCALE(x) (x << LV_ANTIALIAS)
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -98,7 +98,7 @@ void lv_inv_area(const area_t * area_p) ...@@ -98,7 +98,7 @@ void lv_inv_area(const area_t * area_p)
/*The area is truncated to the screen*/ /*The area is truncated to the screen*/
if(suc != false) if(suc != false)
{ {
#if LV_DOWNSCALE == 2 #if LV_ANTIALIAS == 1
/*Rounding*/ /*Rounding*/
com_area.x1 = com_area.x1 & (~0x1); com_area.x1 = com_area.x1 & (~0x1);
com_area.y1 = com_area.y1 & (~0x1); com_area.y1 = com_area.y1 & (~0x1);
...@@ -242,7 +242,7 @@ static void lv_refr_area_no_vdb(const area_t * area_p) ...@@ -242,7 +242,7 @@ static void lv_refr_area_no_vdb(const area_t * area_p)
lv_obj_t * top_p; lv_obj_t * top_p;
/*Get top object which is not covered by others*/ /*Get top object which is not covered by others*/
top_p = lv_refr_get_top_obj(area_p, lv_screen_act()); top_p = lv_refr_get_top_obj(area_p, lv_scr_act());
/*Do the refreshing*/ /*Do the refreshing*/
lv_refr_make(top_p, area_p); lv_refr_make(top_p, area_p);
...@@ -261,7 +261,7 @@ static void lv_refr_area_with_vdb(const area_t * area_p) ...@@ -261,7 +261,7 @@ static void lv_refr_area_with_vdb(const area_t * area_p)
if(max_row > area_get_height(area_p)) max_row = area_get_height(area_p); if(max_row > area_get_height(area_p)) max_row = area_get_height(area_p);
/*Round the row number with downscale*/ /*Round the row number with downscale*/
#if LV_DOWNSCALE == 2 #if LV_ANTIALIAS == 1
max_row &= (~0x1); max_row &= (~0x1);
#endif #endif
...@@ -310,7 +310,7 @@ static void lv_refr_area_part_vdb(const area_t * area_p) ...@@ -310,7 +310,7 @@ static void lv_refr_area_part_vdb(const area_t * area_p)
area_union(&start_mask, area_p, &vdb_p->area); area_union(&start_mask, area_p, &vdb_p->area);
/*Get the most top object which is not covered by others*/ /*Get the most top object which is not covered by others*/
top_p = lv_refr_get_top_obj(&start_mask, lv_screen_act()); top_p = lv_refr_get_top_obj(&start_mask, lv_scr_act());
/*Do the refreshing from the top object*/ /*Do the refreshing from the top object*/
lv_refr_make(top_p, &start_mask); lv_refr_make(top_p, &start_mask);
...@@ -372,7 +372,7 @@ static void lv_refr_make(lv_obj_t * top_p, const area_t * mask_p) ...@@ -372,7 +372,7 @@ static void lv_refr_make(lv_obj_t * top_p, const area_t * mask_p)
/* Normally always will be a top_obj (at least the screen) /* Normally always will be a top_obj (at least the screen)
* but in special cases (e.g. if the screen has alpha) it won't. * but in special cases (e.g. if the screen has alpha) it won't.
* In this case use the screen directly */ * In this case use the screen directly */
if(top_p == NULL) top_p = lv_screen_act(); if(top_p == NULL) top_p = lv_scr_act();
/*Refresh the top object and its children*/ /*Refresh the top object and its children*/
lv_refr_obj(top_p, mask_p); lv_refr_obj(top_p, mask_p);
......
...@@ -64,7 +64,7 @@ lv_obj_t * lv_bar_create(lv_obj_t * par, lv_obj_t * copy) ...@@ -64,7 +64,7 @@ lv_obj_t * lv_bar_create(lv_obj_t * par, lv_obj_t * copy)
ext->min_value = 0; ext->min_value = 0;
ext->max_value = 100; ext->max_value = 100;
ext->act_value = 0; ext->act_value = 0;
ext->style_indic = lv_style_get(LV_STYLE_PRETTY_COLOR); ext->indicator_style = lv_style_get(LV_STYLE_PRETTY_COLOR);
/* Save the ancient design function. /* Save the ancient design function.
* It will be used in the bar design function*/ * It will be used in the bar design function*/
...@@ -84,7 +84,7 @@ lv_obj_t * lv_bar_create(lv_obj_t * par, lv_obj_t * copy) ...@@ -84,7 +84,7 @@ lv_obj_t * lv_bar_create(lv_obj_t * par, lv_obj_t * copy)
ext->min_value = ext_copy->min_value; ext->min_value = ext_copy->min_value;
ext->max_value = ext_copy->max_value; ext->max_value = ext_copy->max_value;
ext->act_value = ext_copy->act_value; ext->act_value = ext_copy->act_value;
ext->style_indic = ext_copy->style_indic; ext->indicator_style = ext_copy->indicator_style;
/*Refresh the style with new signal function*/ /*Refresh the style with new signal function*/
lv_obj_refresh_style(new_bar); lv_obj_refresh_style(new_bar);
...@@ -110,7 +110,7 @@ bool lv_bar_signal(lv_obj_t * bar, lv_signal_t sign, void * param) ...@@ -110,7 +110,7 @@ bool lv_bar_signal(lv_obj_t * bar, lv_signal_t sign, void * param)
* make the object specific signal handling */ * make the object specific signal handling */
if(valid != false) { if(valid != false) {
if(sign == LV_SIGNAL_REFR_EXT_SIZE) { if(sign == LV_SIGNAL_REFR_EXT_SIZE) {
lv_style_t * style_indic = lv_bar_get_style_indic(bar); lv_style_t * style_indic = lv_bar_get_indicator_style(bar);
if(style_indic->body.shadow.width > bar->ext_size) bar->ext_size = style_indic->body.shadow.width; if(style_indic->body.shadow.width > bar->ext_size) bar->ext_size = style_indic->body.shadow.width;
} }
...@@ -196,11 +196,11 @@ void lv_bar_set_range(lv_obj_t * bar, int16_t min, int16_t max) ...@@ -196,11 +196,11 @@ void lv_bar_set_range(lv_obj_t * bar, int16_t min, int16_t max)
* @param bar pointer to a bar object * @param bar pointer to a bar object
* @param style pointer to a style * @param style pointer to a style
*/ */
void lv_bar_set_style_indic(lv_obj_t * bar, lv_style_t * style) void lv_bar_set_indicator_style(lv_obj_t * bar, lv_style_t * style)
{ {
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
ext->style_indic = style; ext->indicator_style = style;
bar->signal_func(bar, LV_SIGNAL_REFR_EXT_SIZE, NULL); bar->signal_func(bar, LV_SIGNAL_REFR_EXT_SIZE, NULL);
...@@ -249,13 +249,13 @@ int16_t lv_bar_get_max_value(lv_obj_t * bar) ...@@ -249,13 +249,13 @@ int16_t lv_bar_get_max_value(lv_obj_t * bar)
* @param bar pointer to a bar object * @param bar pointer to a bar object
* @return pointer to the bar indicator style * @return pointer to the bar indicator style
*/ */
lv_style_t * lv_bar_get_style_indic(lv_obj_t * bar) lv_style_t * lv_bar_get_indicator_style(lv_obj_t * bar)
{ {
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
if(ext->style_indic == NULL) return lv_obj_get_style(bar); if(ext->indicator_style == NULL) return lv_obj_get_style(bar);
return ext->style_indic; return ext->indicator_style;
} }
/********************** /**********************
...@@ -282,7 +282,7 @@ static bool lv_bar_design(lv_obj_t * bar, const area_t * mask, lv_design_mode_t ...@@ -282,7 +282,7 @@ static bool lv_bar_design(lv_obj_t * bar, const area_t * mask, lv_design_mode_t
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
lv_style_t * style_indic = lv_bar_get_style_indic(bar); lv_style_t * style_indic = lv_bar_get_indicator_style(bar);
area_t indic_area; area_t indic_area;
area_cpy(&indic_area, &bar->coords); area_cpy(&indic_area, &bar->coords);
indic_area.x1 += style_indic->body.padding.horizontal; indic_area.x1 += style_indic->body.padding.horizontal;
......
...@@ -32,12 +32,12 @@ extern "C" { ...@@ -32,12 +32,12 @@ extern "C" {
/*Data of bar*/ /*Data of bar*/
typedef struct typedef struct
{ {
/*No inherited ext*/ /*Ext. of ancestor*/ /*No inherited ext*/ /*Ext. of ancestor*/
/*New data for this type */ /*New data for this type */
int16_t act_value; /*Current value of the bar*/ int16_t act_value; /*Current value of the bar*/
int16_t min_value; /*Minimum value of the bar*/ int16_t min_value; /*Minimum value of the bar*/
int16_t max_value; /*Maximum value of the bar*/ int16_t max_value; /*Maximum value of the bar*/
lv_style_t * style_indic; /*Style of the indicator*/ lv_style_t *indicator_style; /*Style of the indicator*/
}lv_bar_ext_t; }lv_bar_ext_t;
/********************** /**********************
...@@ -88,7 +88,7 @@ void lv_bar_set_range(lv_obj_t * bar, int16_t min, int16_t max); ...@@ -88,7 +88,7 @@ void lv_bar_set_range(lv_obj_t * bar, int16_t min, int16_t max);
* @param bar pointer to a bar object * @param bar pointer to a bar object
* @param style pointer to a style * @param style pointer to a style
*/ */
void lv_bar_set_style_indic(lv_obj_t * bar, lv_style_t * style); void lv_bar_set_indicator_style(lv_obj_t * bar, lv_style_t * style);
/** /**
* Get the value of a bar * Get the value of a bar
...@@ -116,7 +116,7 @@ int16_t lv_bar_get_max_value(lv_obj_t * bar); ...@@ -116,7 +116,7 @@ int16_t lv_bar_get_max_value(lv_obj_t * bar);
* @param bar pointer to a bar object * @param bar pointer to a bar object
* @return pointer to the bar indicator style * @return pointer to the bar indicator style
*/ */
lv_style_t * lv_bar_get_style_indic(lv_obj_t * bar); lv_style_t * lv_bar_get_indicator_style(lv_obj_t * bar);
/********************** /**********************
* MACROS * MACROS
......
...@@ -8,15 +8,14 @@ ...@@ -8,15 +8,14 @@
*********************/ *********************/
#include "lv_conf.h" #include "lv_conf.h"
#if USE_LV_BUTTON != 0 #if USE_LV_BTN != 0
#include <string.h>
#include "lv_btn.h" #include "lv_btn.h"
#include "../lv_obj/lv_group.h" #include "../lv_obj/lv_group.h"
#include "../lv_draw/lv_draw.h" #include "../lv_draw/lv_draw.h"
#include "misc/gfx/area.h" #include "misc/gfx/area.h"
#include "misc/gfx/color.h" #include "misc/gfx/color.h"
#include <stdbool.h>
#include <string.h>
/********************* /*********************
* DEFINES * DEFINES
...@@ -241,6 +240,22 @@ void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state) ...@@ -241,6 +240,22 @@ void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state)
} }
/** /**
* Toggle the state of the button (ON->OFF, OFF->ON)
* @param btn pointer to a button object
*/
void lv_btn_toggle(lv_obj_t * btn)
{
lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn);
switch(ext->state) {
case LV_BTN_STATE_OFF_RELEASED: lv_btn_set_state(btn, LV_BTN_STATE_ON_RELEASED); break;
case LV_BTN_STATE_OFF_PRESSED: lv_btn_set_state(btn, LV_BTN_STATE_ON_PRESSED); break;
case LV_BTN_STATE_ON_RELEASED: lv_btn_set_state(btn, LV_BTN_STATE_OFF_RELEASED); break;
case LV_BTN_STATE_ON_PRESSED: lv_btn_set_state(btn, LV_BTN_STATE_OFF_PRESSED); break;
default: break;
}
}
/**
* Set a function to call when the button is pressed * Set a function to call when the button is pressed
* @param btn pointer to a button object * @param btn pointer to a button object
* @param pr_action pointer to function * @param pr_action pointer to function
......
/** /**
* @file lv_button.h * @file lv_btn.h
* *
*/ */
#ifndef lv_btn_H #ifndef LV_BTN_H
#define lv_btn_H #define LV_BTN_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -14,7 +14,7 @@ extern "C" { ...@@ -14,7 +14,7 @@ extern "C" {
* INCLUDES * INCLUDES
*********************/ *********************/
#include "lv_conf.h" #include "lv_conf.h"
#if USE_LV_BUTTON != 0 #if USE_LV_BTN != 0
/*Testing of dependencies*/ /*Testing of dependencies*/
#if USE_LV_CONT == 0 #if USE_LV_CONT == 0
...@@ -22,7 +22,7 @@ extern "C" { ...@@ -22,7 +22,7 @@ extern "C" {
#endif #endif
#include "lv_cont.h" #include "lv_cont.h"
#include <lvgl/lv_obj/lv_indev.h> #include "../lv_obj/lv_indev.h"
/********************* /*********************
* DEFINES * DEFINES
...@@ -101,6 +101,12 @@ void lv_btn_set_toggle(lv_obj_t * btn, bool tgl); ...@@ -101,6 +101,12 @@ void lv_btn_set_toggle(lv_obj_t * btn, bool tgl);
void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state); void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state);
/** /**
* Toggle the state of the button (ON->OFF, OFF->ON)
* @param btn pointer to a button object
*/
void lv_btn_toggle(lv_obj_t * btn);
/**
* Set a function to call when the button is pressed * Set a function to call when the button is pressed
* @param btn pointer to a button object * @param btn pointer to a button object
* @param pr_action pointer to function * @param pr_action pointer to function
...@@ -108,7 +114,7 @@ void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state); ...@@ -108,7 +114,7 @@ void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state);
void lv_btn_set_action(lv_obj_t * btn, lv_btn_action_t type, lv_action_t action); void lv_btn_set_action(lv_obj_t * btn, lv_btn_action_t type, lv_action_t action);
/** /**
* Set styles of a button is each state * Set styles of a button is each state. Use NULL for any style which are not be changed.
* @param btn pointer to button object * @param btn pointer to button object
* @param rel pointer to a style for releases state * @param rel pointer to a style for releases state
* @param pr pointer to a style for pressed state * @param pr pointer to a style for pressed state
...@@ -118,7 +124,6 @@ void lv_btn_set_action(lv_obj_t * btn, lv_btn_action_t type, lv_action_t action) ...@@ -118,7 +124,6 @@ void lv_btn_set_action(lv_obj_t * btn, lv_btn_action_t type, lv_action_t action)
*/ */
void lv_btn_set_style(lv_obj_t * btn, lv_btn_state_t state, lv_style_t * style); void lv_btn_set_style(lv_obj_t * btn, lv_btn_state_t state, lv_style_t * style);
void lv_btn_set_style_all(lv_obj_t * btn, lv_style_t ** style_array);
/** /**
* Get the current state of the button * Get the current state of the button
* @param btn pointer to a button object * @param btn pointer to a button object
...@@ -141,12 +146,11 @@ bool lv_btn_get_toggle(lv_obj_t * btn); ...@@ -141,12 +146,11 @@ bool lv_btn_get_toggle(lv_obj_t * btn);
lv_action_t lv_btn_get_action(lv_obj_t * btn, lv_btn_action_t type); lv_action_t lv_btn_get_action(lv_obj_t * btn, lv_btn_action_t type);
/** /**
* Get the press action of a button * Get the style of a button in a given state
* @param btn pointer to a button object * @param btn pointer to a button object
* @return pointer to the press action function * @param state a state from 'lv_btn_state_t' in which style should be get
* @return pointer to the style in the given state
*/ */
lv_action_t lv_btn_get_pr_action(lv_obj_t * btn);
lv_style_t * lv_btn_get_style(lv_obj_t * btn, lv_btn_state_t state); lv_style_t * lv_btn_get_style(lv_obj_t * btn, lv_btn_state_t state);
/********************** /**********************
......
...@@ -28,10 +28,13 @@ ...@@ -28,10 +28,13 @@
* STATIC PROTOTYPES * STATIC PROTOTYPES
**********************/ **********************/
static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_t mode); static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_t mode);
static uint8_t lv_btnm_get_width_unit(const char * btn_str); static uint8_t get_button_width(const char * btn_str);
static uint16_t lv_btnm_get_btn_from_point(lv_obj_t * btnm, point_t * p); static bool button_is_hidden(const char * btn_str);
static uint16_t lv_btnm_get_btn_txt(lv_obj_t * btnm, uint16_t btn_id); static bool button_is_repeat_disabled(const char * btn_str);
static void lv_btnm_create_btns(lv_obj_t * btnm, const char ** map); const char * cut_ctrl_byte(const char * btn_str);
static uint16_t get_button_from_point(lv_obj_t * btnm, point_t * p);
static uint16_t get_button_text(lv_obj_t * btnm, uint16_t btn_id);
static void create_buttons(lv_obj_t * btnm, const char ** map);
/********************** /**********************
* STATIC VARIABLES * STATIC VARIABLES
...@@ -68,17 +71,18 @@ lv_obj_t * lv_btnm_create(lv_obj_t * par, lv_obj_t * copy) ...@@ -68,17 +71,18 @@ lv_obj_t * lv_btnm_create(lv_obj_t * par, lv_obj_t * copy)
/*Allocate the object type specific extended data*/ /*Allocate the object type specific extended data*/
lv_btnm_ext_t * ext = lv_obj_allocate_ext_attr(new_btnm, sizeof(lv_btnm_ext_t)); lv_btnm_ext_t * ext = lv_obj_allocate_ext_attr(new_btnm, sizeof(lv_btnm_ext_t));
dm_assert(ext); dm_assert(ext);
ext->btn_cnt = 0; ext->button_cnt = 0;
ext->btn_pr = LV_BTNM_PR_NONE; ext->button_id_pressed = LV_BTNM_PR_NONE;
ext->btn_tgl = LV_BTNM_PR_NONE; ext->button_id_toggled = LV_BTNM_PR_NONE;
ext->btn_areas = NULL; ext->button_areas = NULL;
ext->cb = NULL; ext->action = NULL;
ext->map_p = NULL; ext->map_p = NULL;
ext->style_btn_rel = lv_style_get(LV_STYLE_BUTTON_OFF_RELEASED); ext->toggle = 0;
ext->style_btn_pr = lv_style_get(LV_STYLE_BUTTON_OFF_PRESSED); ext->button_styles[LV_BTN_STATE_OFF_RELEASED] = lv_style_get(LV_STYLE_BUTTON_OFF_RELEASED);
ext->style_btn_trel = lv_style_get(LV_STYLE_BUTTON_ON_RELEASED); ext->button_styles[LV_BTN_STATE_OFF_PRESSED] = lv_style_get(LV_STYLE_BUTTON_OFF_PRESSED);
ext->style_btn_tpr = lv_style_get(LV_STYLE_BUTTON_ON_PRESSED); ext->button_styles[LV_BTN_STATE_ON_RELEASED] = lv_style_get(LV_STYLE_BUTTON_ON_RELEASED);
ext->tgl = 0; ext->button_styles[LV_BTN_STATE_ON_PRESSED] = lv_style_get(LV_STYLE_BUTTON_ON_PRESSED);
ext->button_styles[LV_BTN_STATE_INACTIVE] = lv_style_get(LV_STYLE_BUTTON_INACTIVE);
if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_func(new_btnm); if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_func(new_btnm);
...@@ -94,10 +98,9 @@ lv_obj_t * lv_btnm_create(lv_obj_t * par, lv_obj_t * copy) ...@@ -94,10 +98,9 @@ lv_obj_t * lv_btnm_create(lv_obj_t * par, lv_obj_t * copy)
/*Copy an existing object*/ /*Copy an existing object*/
else { else {
lv_btnm_ext_t * copy_ext = lv_obj_get_ext_attr(copy); lv_btnm_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
ext->style_btn_rel = copy_ext->style_btn_rel; memcpy(ext->button_styles, copy_ext->button_styles, sizeof(ext->button_styles));
ext->style_btn_pr = copy_ext->style_btn_pr; ext->action = copy_ext->action;
lv_btnm_set_map(new_btnm, lv_btnm_get_map(copy)); lv_btnm_set_map(new_btnm, lv_btnm_get_map(copy));
ext->cb = copy_ext->cb;
} }
return new_btnm; return new_btnm;
...@@ -125,7 +128,7 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param) ...@@ -125,7 +128,7 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param)
area_t btn_area; area_t btn_area;
point_t p; point_t p;
if(sign == LV_SIGNAL_CLEANUP) { if(sign == LV_SIGNAL_CLEANUP) {
dm_free(ext->btn_areas); dm_free(ext->button_areas);
} }
else if(sign == LV_SIGNAL_STYLE_CHG || sign == LV_SIGNAL_CORD_CHG) { else if(sign == LV_SIGNAL_STYLE_CHG || sign == LV_SIGNAL_CORD_CHG) {
lv_btnm_set_map(btnm, ext->map_p); lv_btnm_set_map(btnm, ext->map_p);
...@@ -134,13 +137,13 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param) ...@@ -134,13 +137,13 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param)
uint16_t btn_pr; uint16_t btn_pr;
/*Search the pressed area*/ /*Search the pressed area*/
lv_indev_get_point(param, &p); lv_indev_get_point(param, &p);
btn_pr = lv_btnm_get_btn_from_point(btnm, &p); btn_pr = get_button_from_point(btnm, &p);
/*Invalidate to old and the new areas*/; /*Invalidate to old and the new areas*/;
lv_obj_get_coords(btnm, &btnm_area); lv_obj_get_coords(btnm, &btnm_area);
if(btn_pr != ext->btn_pr) { if(btn_pr != ext->button_id_pressed) {
lv_indev_reset_lpr(param); lv_indev_reset_lpr(param);
if(ext->btn_pr != LV_BTNM_PR_NONE) { if(ext->button_id_pressed != LV_BTNM_PR_NONE) {
area_cpy(&btn_area, &ext->btn_areas[ext->btn_pr]); area_cpy(&btn_area, &ext->button_areas[ext->button_id_pressed]);
btn_area.x1 += btnm_area.x1; btn_area.x1 += btnm_area.x1;
btn_area.y1 += btnm_area.y1; btn_area.y1 += btnm_area.y1;
btn_area.x2 += btnm_area.x1; btn_area.x2 += btnm_area.x1;
...@@ -148,7 +151,7 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param) ...@@ -148,7 +151,7 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param)
lv_inv_area(&btn_area); lv_inv_area(&btn_area);
} }
if(btn_pr != LV_BTNM_PR_NONE) { if(btn_pr != LV_BTNM_PR_NONE) {
area_cpy(&btn_area, &ext->btn_areas[btn_pr]); area_cpy(&btn_area, &ext->button_areas[btn_pr]);
btn_area.x1 += btnm_area.x1; btn_area.x1 += btnm_area.x1;
btn_area.y1 += btnm_area.y1; btn_area.y1 += btnm_area.y1;
btn_area.x2 += btnm_area.x1; btn_area.x2 += btnm_area.x1;
...@@ -157,75 +160,75 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param) ...@@ -157,75 +160,75 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param)
} }
} }
ext->btn_pr = btn_pr; ext->button_id_pressed = btn_pr;
} }
else if(sign == LV_SIGNAL_LONG_PRESS_REP) { else if(sign == LV_SIGNAL_LONG_PRESS_REP) {
if(ext->cb != NULL && ext->btn_pr != LV_BTNM_PR_NONE) { if(ext->action && ext->button_id_pressed != LV_BTNM_PR_NONE) {
uint16_t txt_i = lv_btnm_get_btn_txt(btnm, ext->btn_pr); uint16_t txt_i = get_button_text(btnm, ext->button_id_pressed);
if(txt_i != LV_BTNM_PR_NONE) { if(txt_i != LV_BTNM_PR_NONE) {
if((ext->map_p[txt_i][0] & LV_BTNM_CTRL_MASK) == LV_BTNM_CTRL_CODE) { /*If there is control byte check for "no long press"*/ if(button_is_repeat_disabled(ext->map_p[txt_i]) == false) {
if((ext->map_p[txt_i][0] & LV_BTNM_NO_LPR_MASK) == 0) ext->cb(btnm, txt_i); ext->action(btnm, cut_ctrl_byte(ext->map_p[txt_i]));
} else { /*If no control byte then call the action unconditionally*/
ext->cb(btnm, txt_i);
} }
} }
} }
} }
else if(sign == LV_SIGNAL_RELEASED) { else if(sign == LV_SIGNAL_RELEASED) {
if(ext->btn_pr != LV_BTNM_PR_NONE) { if(ext->button_id_pressed != LV_BTNM_PR_NONE) {
if(ext->cb) { if(ext->action) {
uint16_t txt_i = lv_btnm_get_btn_txt(btnm, ext->btn_pr); uint16_t txt_i = get_button_text(btnm, ext->button_id_pressed);
if(txt_i != LV_BTNM_PR_NONE) { if(txt_i != LV_BTNM_PR_NONE) {
ext->cb(btnm, txt_i); ext->action(btnm, cut_ctrl_byte(ext->map_p[txt_i]));
} }
} }
/*Invalidate to old pressed area*/; /*Invalidate to old pressed area*/;
lv_obj_get_coords(btnm, &btnm_area); lv_obj_get_coords(btnm, &btnm_area);
area_cpy(&btn_area, &ext->btn_areas[ext->btn_pr]); area_cpy(&btn_area, &ext->button_areas[ext->button_id_pressed]);
btn_area.x1 += btnm_area.x1; btn_area.x1 += btnm_area.x1;
btn_area.y1 += btnm_area.y1; btn_area.y1 += btnm_area.y1;
btn_area.x2 += btnm_area.x1; btn_area.x2 += btnm_area.x1;
btn_area.y2 += btnm_area.y1; btn_area.y2 += btnm_area.y1;
lv_inv_area(&btn_area); lv_inv_area(&btn_area);
if(ext->tgl != 0) { if(ext->toggle != 0) {
/*Invalidate to old toggled area*/; /*Invalidate to old toggled area*/;
area_cpy(&btn_area, &ext->btn_areas[ext->btn_tgl]); area_cpy(&btn_area, &ext->button_areas[ext->button_id_toggled]);
btn_area.x1 += btnm_area.x1; btn_area.x1 += btnm_area.x1;
btn_area.y1 += btnm_area.y1; btn_area.y1 += btnm_area.y1;
btn_area.x2 += btnm_area.x1; btn_area.x2 += btnm_area.x1;
btn_area.y2 += btnm_area.y1; btn_area.y2 += btnm_area.y1;
lv_inv_area(&btn_area); lv_inv_area(&btn_area);
ext->btn_tgl = ext->btn_pr; ext->button_id_toggled = ext->button_id_pressed;
} }
ext->btn_pr = LV_BTNM_PR_NONE; ext->button_id_pressed = LV_BTNM_PR_NONE;
} }
} else if(sign == LV_SIGNAL_PRESS_LOST || sign == LV_SIGNAL_DEFOCUS) { } else if(sign == LV_SIGNAL_PRESS_LOST || sign == LV_SIGNAL_DEFOCUS) {
ext->btn_pr = LV_BTNM_PR_NONE; ext->button_id_pressed = LV_BTNM_PR_NONE;
lv_obj_invalidate(btnm); lv_obj_invalidate(btnm);
} else if(sign == LV_SIGNAL_FOCUS) { } else if(sign == LV_SIGNAL_FOCUS) {
ext->btn_pr = 0; ext->button_id_pressed = 0;
lv_obj_invalidate(btnm); lv_obj_invalidate(btnm);
} else if(sign == LV_SIGNAL_CONTROLL) { } else if(sign == LV_SIGNAL_CONTROLL) {
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
char c = *((char*)param); char c = *((char*)param);
if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_UP) { if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_UP) {
if(ext->btn_pr == LV_BTNM_PR_NONE) ext->btn_pr = 0; if(ext->button_id_pressed == LV_BTNM_PR_NONE) ext->button_id_pressed = 0;
else ext->btn_pr++; else ext->button_id_pressed++;
if(ext->btn_pr >= ext->btn_cnt - 1) ext->btn_pr = ext->btn_cnt - 1; if(ext->button_id_pressed >= ext->button_cnt - 1) ext->button_id_pressed = ext->button_cnt - 1;
lv_obj_invalidate(btnm); lv_obj_invalidate(btnm);
} else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_DOWN) { } else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_DOWN) {
if(ext->btn_pr == LV_BTNM_PR_NONE) ext->btn_pr = 0; if(ext->button_id_pressed == LV_BTNM_PR_NONE) ext->button_id_pressed = 0;
if(ext->btn_pr > 0) ext->btn_pr--; if(ext->button_id_pressed > 0) ext->button_id_pressed--;
lv_obj_invalidate(btnm); lv_obj_invalidate(btnm);
} else if(c == LV_GROUP_KEY_ENTER) { } else if(c == LV_GROUP_KEY_ENTER) {
if(ext->cb != NULL) { if(ext->action != NULL) {
uint16_t txt_i = lv_btnm_get_btn_txt(btnm, ext->btn_pr); uint16_t txt_i = get_button_text(btnm, ext->button_id_pressed);
if(txt_i != LV_BTNM_PR_NONE) ext->cb(btnm, txt_i); if(txt_i != LV_BTNM_PR_NONE) {
ext->action(btnm, cut_ctrl_byte(ext->map_p[txt_i]));
}
} }
} }
} }
...@@ -247,7 +250,7 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param) ...@@ -247,7 +250,7 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param)
* - bit 7: always 1 * - bit 7: always 1
* - bit 6: always 0 * - bit 6: always 0
* - bit 5: reserved * - bit 5: reserved
* - bit 4: no long press * - bit 4: no repeat (on long press)
* - bit 3: hidden * - bit 3: hidden
* - bit 2..0: button relative width * - bit 2..0: button relative width
* Example (practically use octal numbers): "\224abc": "abc" text with 4 width and no long press * Example (practically use octal numbers): "\224abc": "abc" text with 4 width and no long press
...@@ -260,7 +263,7 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map) ...@@ -260,7 +263,7 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map)
ext->map_p = map; ext->map_p = map;
/*Analyze the map and create the required number of buttons*/ /*Analyze the map and create the required number of buttons*/
lv_btnm_create_btns(btnm, map); create_buttons(btnm, map);
/*Set size and positions of the buttons*/ /*Set size and positions of the buttons*/
lv_style_t * btnms = lv_obj_get_style(btnm); lv_style_t * btnms = lv_obj_get_style(btnm);
...@@ -294,7 +297,7 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map) ...@@ -294,7 +297,7 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map)
/*Count the buttons in a line*/ /*Count the buttons in a line*/
while(strcmp(map_p_tmp[btn_cnt], "\n") != 0 && while(strcmp(map_p_tmp[btn_cnt], "\n") != 0 &&
strlen(map_p_tmp[btn_cnt]) != 0) { /*Check a line*/ strlen(map_p_tmp[btn_cnt]) != 0) { /*Check a line*/
unit_cnt += lv_btnm_get_width_unit(map_p_tmp[btn_cnt]); unit_cnt += get_button_width(map_p_tmp[btn_cnt]);
btn_cnt ++; btn_cnt ++;
} }
...@@ -312,17 +315,17 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map) ...@@ -312,17 +315,17 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map)
/* one_unit_w = all_unit_w / unit_cnt /* one_unit_w = all_unit_w / unit_cnt
* act_unit_w = one_unit_w * button_width * act_unit_w = one_unit_w * button_width
* do this two operation but the multiply first to divide a greater number */ * do this two operation but the multiply first to divide a greater number */
act_unit_w = (all_unit_w * lv_btnm_get_width_unit(map_p_tmp[i])) / unit_cnt; act_unit_w = (all_unit_w * get_button_width(map_p_tmp[i])) / unit_cnt;
/*Always recalculate act_x because of rounding errors */ /*Always recalculate act_x because of rounding errors */
act_x = (unit_act_cnt * all_unit_w) / unit_cnt + i * btnms->body.padding.inner + btnms->body.padding.horizontal; act_x = (unit_act_cnt * all_unit_w) / unit_cnt + i * btnms->body.padding.inner + btnms->body.padding.horizontal;
area_set(&ext->btn_areas[btn_i], act_x, area_set(&ext->button_areas[btn_i], act_x,
act_y, act_y,
act_x + act_unit_w, act_x + act_unit_w,
act_y + btn_h); act_y + btn_h);
unit_act_cnt += lv_btnm_get_width_unit(map_p_tmp[i]); unit_act_cnt += get_button_width(map_p_tmp[i]);
i_tot ++; i_tot ++;
btn_i ++; btn_i ++;
...@@ -342,10 +345,10 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map) ...@@ -342,10 +345,10 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map)
* @param btnm: pointer to button matrix object * @param btnm: pointer to button matrix object
* @param cb pointer to a callback function * @param cb pointer to a callback function
*/ */
void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_callback_t cb) void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_action_t cb)
{ {
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
ext->cb = cb; ext->action = cb;
} }
/** /**
...@@ -354,16 +357,16 @@ void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_callback_t cb) ...@@ -354,16 +357,16 @@ void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_callback_t cb)
* @param en true: enable toggling; false: disable toggling * @param en true: enable toggling; false: disable toggling
* @param id index of the currently toggled button (ignored if 'en' == false) * @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) void lv_btnm_set_toggle(lv_obj_t * btnm, bool en, uint16_t id)
{ {
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
ext->tgl = en == false ? 0 : 1; ext->toggle = en == false ? 0 : 1;
if(ext->tgl != 0) { if(ext->toggle != 0) {
if(id > ext->btn_cnt) id = LV_BTNM_PR_NONE; if(id > ext->button_cnt) id = LV_BTNM_PR_NONE;
ext->btn_tgl = id; ext->button_id_toggled = id;
} else { } else {
ext->btn_tgl = LV_BTNM_PR_NONE; ext->button_id_toggled = LV_BTNM_PR_NONE;
} }
lv_obj_invalidate(btnm); lv_obj_invalidate(btnm);
...@@ -378,15 +381,12 @@ void lv_btnm_set_tgl(lv_obj_t * btnm, bool en, uint16_t id) ...@@ -378,15 +381,12 @@ void lv_btnm_set_tgl(lv_obj_t * btnm, bool en, uint16_t id)
* @param tpr pointer to a style for toggled pressed state (NULL to leave it unchanged) * @param tpr pointer to a style for toggled pressed state (NULL to leave it unchanged)
* @param ina pointer to a style for inactive state (NULL to leave it unchanged) * @param ina pointer to a style for inactive state (NULL to leave it unchanged)
*/ */
void lv_btnm_set_styles_btn(lv_obj_t *btnm, lv_style_t *rel, lv_style_t *pr, void lv_btnm_set_button_style(lv_obj_t *btnm, lv_btn_state_t state, lv_style_t *style)
lv_style_t *trel, lv_style_t *tpr, lv_style_t *ina)
{ {
if(state >= LV_BTN_STATE_NUM) return;
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
if(rel != NULL) ext->style_btn_rel = rel; ext->button_styles[state] = style;
if(pr != NULL) ext->style_btn_pr = pr;
if(trel != NULL) ext->style_btn_trel = trel;
if(tpr != NULL) ext->style_btn_tpr = tpr;
if(ina != NULL) ext->style_btn_ina = ina;
lv_obj_invalidate(btnm); lv_obj_invalidate(btnm);
} }
...@@ -411,10 +411,10 @@ const char ** lv_btnm_get_map(lv_obj_t * btnm) ...@@ -411,10 +411,10 @@ const char ** lv_btnm_get_map(lv_obj_t * btnm)
* @param btnm: pointer to button matrix object * @param btnm: pointer to button matrix object
* @return pointer to the callback function * @return pointer to the callback function
*/ */
lv_btnm_callback_t lv_btnm_get_action(lv_obj_t * btnm) lv_btnm_action_t lv_btnm_get_action(lv_obj_t * btnm)
{ {
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
return ext->cb; return ext->action;
} }
/** /**
...@@ -423,27 +423,12 @@ lv_btnm_callback_t lv_btnm_get_action(lv_obj_t * btnm) ...@@ -423,27 +423,12 @@ lv_btnm_callback_t lv_btnm_get_action(lv_obj_t * btnm)
* @param state style in this state (LV_BTN_STATE_PR or LV_BTN_STATE_REL) * @param state style in this state (LV_BTN_STATE_PR or LV_BTN_STATE_REL)
* @return pointer the button style in the given state * @return pointer the button style in the given state
*/ */
lv_style_t * lv_btnm_get_style_btn(lv_obj_t * btnm, lv_btn_state_t state) lv_style_t * lv_btnm_get_button_style(lv_obj_t * btnm, lv_btn_state_t state)
{ {
lv_style_t * style; if(state >= LV_BTN_STATE_NUM) return lv_obj_get_style(btnm);
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
switch(state) { lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
case LV_BTN_STATE_OFF_PRESSED: lv_style_t * style = ext->button_styles[state];
style = ext->style_btn_pr;
break;
case LV_BTN_STATE_OFF_RELEASED:
style = ext->style_btn_rel;
break;
case LV_BTN_STATE_ON_PRESSED:
style = ext->style_btn_tpr;
break;
case LV_BTN_STATE_ON_RELEASED:
style = ext->style_btn_trel;
break;
default:
style = NULL;
}
if(style == NULL) style = lv_obj_get_style(btnm); if(style == NULL) style = lv_obj_get_style(btnm);
...@@ -484,20 +469,16 @@ static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_ ...@@ -484,20 +469,16 @@ static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_
uint16_t btn_i = 0; uint16_t btn_i = 0;
uint16_t txt_i = 0; uint16_t txt_i = 0;
for(btn_i = 0; btn_i < ext->btn_cnt; btn_i ++, txt_i ++) { for(btn_i = 0; btn_i < ext->button_cnt; btn_i ++, txt_i ++) {
/*Search the next valid text in the map*/ /*Search the next valid text in the map*/
while(strcmp(ext->map_p[txt_i], "\n") == 0) txt_i ++; while(strcmp(ext->map_p[txt_i], "\n") == 0) txt_i ++;
/*Skip hidden buttons*/ /*Skip hidden buttons*/
if((ext->map_p[txt_i][0] & LV_BTNM_CTRL_MASK) == LV_BTNM_CTRL_CODE && if(button_is_hidden(ext->map_p[txt_i])) continue;
(ext->map_p[txt_i][0] & LV_BTNM_HIDDEN_MASK))
{
continue;
}
lv_obj_get_coords(btnm, &area_btnm); lv_obj_get_coords(btnm, &area_btnm);
area_cpy(&area_tmp, &ext->btn_areas[btn_i]); area_cpy(&area_tmp, &ext->button_areas[btn_i]);
area_tmp.x1 += area_btnm.x1; area_tmp.x1 += area_btnm.x1;
area_tmp.y1 += area_btnm.y1; area_tmp.y1 += area_btnm.y1;
area_tmp.x2 += area_btnm.x1; area_tmp.x2 += area_btnm.x1;
...@@ -507,10 +488,10 @@ static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_ ...@@ -507,10 +488,10 @@ static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_
btn_h = area_get_height(&area_tmp); btn_h = area_get_height(&area_tmp);
/*Load the style*/ /*Load the style*/
if(btn_i != ext->btn_pr && btn_i != ext->btn_tgl) btn_style = lv_btnm_get_style_btn(btnm, LV_BTN_STATE_OFF_RELEASED); if(btn_i != ext->button_id_pressed && btn_i != ext->button_id_toggled) btn_style = lv_btnm_get_button_style(btnm, LV_BTN_STATE_OFF_RELEASED);
else if(btn_i == ext->btn_pr && btn_i != ext->btn_tgl) btn_style = lv_btnm_get_style_btn(btnm, LV_BTN_STATE_OFF_PRESSED); else if(btn_i == ext->button_id_pressed && btn_i != ext->button_id_toggled) btn_style = lv_btnm_get_button_style(btnm, LV_BTN_STATE_OFF_PRESSED);
else if(btn_i != ext->btn_pr && btn_i == ext->btn_tgl) btn_style = lv_btnm_get_style_btn(btnm, LV_BTN_STATE_ON_RELEASED); else if(btn_i != ext->button_id_pressed && btn_i == ext->button_id_toggled) btn_style = lv_btnm_get_button_style(btnm, LV_BTN_STATE_ON_RELEASED);
else if(btn_i == ext->btn_pr && btn_i == ext->btn_tgl) btn_style = lv_btnm_get_style_btn(btnm, LV_BTN_STATE_ON_PRESSED); else if(btn_i == ext->button_id_pressed && btn_i == ext->button_id_toggled) btn_style = lv_btnm_get_button_style(btnm, LV_BTN_STATE_ON_PRESSED);
lv_draw_rect(&area_tmp, mask, btn_style); lv_draw_rect(&area_tmp, mask, btn_style);
...@@ -537,7 +518,7 @@ static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_ ...@@ -537,7 +518,7 @@ static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_
* @param btnm pointer to button matrix object * @param btnm pointer to button matrix object
* @param map_p pointer to a string array * @param map_p pointer to a string array
*/ */
static void lv_btnm_create_btns(lv_obj_t * btnm, const char ** map) static void create_buttons(lv_obj_t * btnm, const char ** map)
{ {
/*Count the buttons in the map*/ /*Count the buttons in the map*/
uint16_t btn_cnt = 0; uint16_t btn_cnt = 0;
...@@ -551,13 +532,13 @@ static void lv_btnm_create_btns(lv_obj_t * btnm, const char ** map) ...@@ -551,13 +532,13 @@ static void lv_btnm_create_btns(lv_obj_t * btnm, const char ** map)
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
if(ext->btn_areas != NULL) { if(ext->button_areas != NULL) {
dm_free(ext->btn_areas); dm_free(ext->button_areas);
ext->btn_areas = NULL; ext->button_areas = NULL;
} }
ext->btn_areas = dm_alloc(sizeof(area_t) * btn_cnt); ext->button_areas = dm_alloc(sizeof(area_t) * btn_cnt);
ext->btn_cnt = btn_cnt; ext->button_cnt = btn_cnt;
} }
/** /**
...@@ -565,7 +546,7 @@ static void lv_btnm_create_btns(lv_obj_t * btnm, const char ** map) ...@@ -565,7 +546,7 @@ static void lv_btnm_create_btns(lv_obj_t * btnm, const char ** map)
* @param btn_str The descriptor string of a button. E.g. "apple" or "\004banana" * @param btn_str The descriptor string of a button. E.g. "apple" or "\004banana"
* @return the width of the button in units * @return the width of the button in units
*/ */
static uint8_t lv_btnm_get_width_unit(const char * btn_str) static uint8_t get_button_width(const char * btn_str)
{ {
if((btn_str[0] & LV_BTNM_CTRL_MASK) == LV_BTNM_CTRL_CODE){ if((btn_str[0] & LV_BTNM_CTRL_MASK) == LV_BTNM_CTRL_CODE){
return btn_str[0] & LV_BTNM_WIDTH_MASK; return btn_str[0] & LV_BTNM_WIDTH_MASK;
...@@ -574,13 +555,42 @@ static uint8_t lv_btnm_get_width_unit(const char * btn_str) ...@@ -574,13 +555,42 @@ static uint8_t lv_btnm_get_width_unit(const char * btn_str)
return 1; /*Default width is 1*/ return 1; /*Default width is 1*/
} }
static bool button_is_hidden(const char * btn_str)
{
/*If control byte presents and hidden bit is '1' then the button is hidden*/
if(((btn_str[0] & LV_BTNM_CTRL_MASK) == LV_BTNM_CTRL_CODE) &&
(btn_str[0] & LV_BTNM_HIDE_MASK)) {
return true;
}
return false;
}
static bool button_is_repeat_disabled(const char * btn_str)
{
/*If control byte presents and hidden bit is '1' then the button is hidden*/
if(((btn_str[0] & LV_BTNM_CTRL_MASK) == LV_BTNM_CTRL_CODE) &&
(btn_str[0] & LV_BTNM_REPEAT_DISABLE_MASK)) {
return true;
}
return false;
}
const char * cut_ctrl_byte(const char * btn_str)
{
/*Cut the control byte if present*/
if((btn_str[0] & LV_BTNM_CTRL_MASK) == LV_BTNM_CTRL_CODE) return &btn_str[1];
else return btn_str;
}
/** /**
* Gives the button id of a button under a given point * Gives the button id of a button under a given point
* @param btnm pointer to a button matrix object * @param btnm pointer to a button matrix object
* @param p a point with absolute coordinates * @param p a point with absolute coordinates
* @return the id of the button or LV_BTNM_PR_NONE. * @return the id of the button or LV_BTNM_PR_NONE.
*/ */
static uint16_t lv_btnm_get_btn_from_point(lv_obj_t * btnm, point_t * p) static uint16_t get_button_from_point(lv_obj_t * btnm, point_t * p)
{ {
area_t btnm_cords; area_t btnm_cords;
area_t btn_area; area_t btn_area;
...@@ -588,8 +598,8 @@ static uint16_t lv_btnm_get_btn_from_point(lv_obj_t * btnm, point_t * p) ...@@ -588,8 +598,8 @@ static uint16_t lv_btnm_get_btn_from_point(lv_obj_t * btnm, point_t * p)
uint16_t i; uint16_t i;
lv_obj_get_coords(btnm, &btnm_cords); lv_obj_get_coords(btnm, &btnm_cords);
for(i = 0; i < ext->btn_cnt; i++) { for(i = 0; i < ext->button_cnt; i++) {
area_cpy(&btn_area, &ext->btn_areas[i]); area_cpy(&btn_area, &ext->button_areas[i]);
btn_area.x1 += btnm_cords.x1; btn_area.x1 += btnm_cords.x1;
btn_area.y1 += btnm_cords.y1; btn_area.y1 += btnm_cords.y1;
btn_area.x2 += btnm_cords.x1; btn_area.x2 += btnm_cords.x1;
...@@ -599,7 +609,7 @@ static uint16_t lv_btnm_get_btn_from_point(lv_obj_t * btnm, point_t * p) ...@@ -599,7 +609,7 @@ static uint16_t lv_btnm_get_btn_from_point(lv_obj_t * btnm, point_t * p)
} }
} }
if(i == ext->btn_cnt) i = LV_BTNM_PR_NONE; if(i == ext->button_cnt) i = LV_BTNM_PR_NONE;
return i; return i;
} }
...@@ -610,10 +620,10 @@ static uint16_t lv_btnm_get_btn_from_point(lv_obj_t * btnm, point_t * p) ...@@ -610,10 +620,10 @@ static uint16_t lv_btnm_get_btn_from_point(lv_obj_t * btnm, point_t * p)
* @param btn_id button id * @param btn_id button id
* @return text id in ext->map_p or LV_BTNM_PR_NONE if 'btn_id' was invalid * @return text id in ext->map_p or LV_BTNM_PR_NONE if 'btn_id' was invalid
*/ */
static uint16_t lv_btnm_get_btn_txt(lv_obj_t * btnm, uint16_t btn_id) static uint16_t get_button_text(lv_obj_t * btnm, uint16_t btn_id)
{ {
lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm);
if(btn_id > ext->btn_cnt) return LV_BTNM_PR_NONE; if(btn_id > ext->button_cnt) return LV_BTNM_PR_NONE;
uint16_t txt_i = 0; uint16_t txt_i = 0;
uint16_t btn_i = 0; uint16_t btn_i = 0;
...@@ -626,7 +636,7 @@ static uint16_t lv_btnm_get_btn_txt(lv_obj_t * btnm, uint16_t btn_id) ...@@ -626,7 +636,7 @@ static uint16_t lv_btnm_get_btn_txt(lv_obj_t * btnm, uint16_t btn_id)
if(strcmp(ext->map_p[txt_i], "\n") == 0) txt_i ++; if(strcmp(ext->map_p[txt_i], "\n") == 0) txt_i ++;
} }
if(btn_i == ext->btn_cnt) return LV_BTNM_PR_NONE; if(btn_i == ext->button_cnt) return LV_BTNM_PR_NONE;
return txt_i; return txt_i;
} }
......
...@@ -29,42 +29,39 @@ extern "C" { ...@@ -29,42 +29,39 @@ extern "C" {
#define LV_BTNM_CTRL_CODE 0x80 /*The control byte has to begin (if present) with 0b10xxxxxx*/ #define LV_BTNM_CTRL_CODE 0x80 /*The control byte has to begin (if present) with 0b10xxxxxx*/
#define LV_BTNM_CTRL_MASK 0xC0 #define LV_BTNM_CTRL_MASK 0xC0
#define LV_BTNM_WIDTH_MASK 0x07 #define LV_BTNM_WIDTH_MASK 0x07
#define LV_BTNM_HIDDEN_MASK 0x08 #define LV_BTNM_HIDE_MASK 0x08
#define LV_BTNM_NO_LPR_MASK 0x10 #define LV_BTNM_REPEAT_DISABLE_MASK 0x10
#define LV_BTNM_RESERVED_MASK 0x20 #define LV_BTNM_RESERVED_MASK 0x20
/********************** /**********************
* TYPEDEFS * TYPEDEFS
**********************/ **********************/
/* Type of callback function which is called when a button is released on the button matrix /* Type of callback function which is called when a button is released or long pressed on the button matrix
* Parameters: button matrix, released button index in the map string * Parameters: button matrix, text of the released button
* return LV_ACTION_RES_INV: the button matrix is deleted else LV_ACTION_RES_OK*/ * return LV_ACTION_RES_INV if the button matrix is deleted else LV_ACTION_RES_OK*/
typedef lv_action_res_t (*lv_btnm_callback_t) (lv_obj_t *, uint16_t); typedef lv_action_res_t (*lv_btnm_action_t) (lv_obj_t *, const char *txt);
/*Data of button matrix*/ /*Data of button matrix*/
typedef struct typedef struct
{ {
lv_cont_ext_t bg; /*Ext. of ancestor*/ lv_cont_ext_t bg; /*Ext. of ancestor*/
/*New data for this type */ /*New data for this type */
const char ** map_p; /*Pointer to the current map*/ const char ** map_p; /*Pointer to the current map*/
area_t * btn_areas; /*Array of areas for the buttons (Handled by the library)*/ area_t * button_areas; /*Array of areas of buttons*/
uint16_t btn_cnt; /*Number of button in 'map_p'(Handled by the library)*/ lv_btnm_action_t action; /*A function to call when a button is releases*/
uint16_t btn_pr; /*Index of the currently pressed button or LV_BTNM_PR_NONE (Handled by the library)*/ lv_style_t * button_styles[LV_BTN_STATE_NUM]; /*Styles of buttons in each state*/
uint16_t btn_tgl; /*Index of the currently toggled button or LV_BTNM_PR_NONE (Handled by the library)*/ uint16_t button_cnt; /*Number of button in 'map_p'(Handled by the library)*/
lv_btnm_callback_t cb; /*A function to call when a button is releases*/ uint16_t button_id_pressed; /*Index of the currently pressed button or LV_BTNM_PR_NONE*/
lv_style_t * style_btn_rel; /*Style of the released buttons*/ uint16_t button_id_toggled; /*Index of the currently toggled button or LV_BTNM_PR_NONE */
lv_style_t * style_btn_pr; /*Style of the pressed buttons*/ uint8_t toggle :1; /*Enable toggling*/
lv_style_t * style_btn_trel; /*Style of the toggled released buttons*/
lv_style_t * style_btn_tpr; /*Style of the toggled pressed buttons*/
lv_style_t * style_btn_ina; /*Style of the inactive buttons*/
uint8_t tgl :1; /*Enable toggling*/
}lv_btnm_ext_t; }lv_btnm_ext_t;
/********************** /**********************
* GLOBAL PROTOTYPES * GLOBAL PROTOTYPES
**********************/ **********************/
/** /**
* Create a button matrix objects * Create a button matrix objects
* @param par pointer to an object, it will be the parent of the new button matrix * @param par pointer to an object, it will be the parent of the new button matrix
...@@ -87,10 +84,14 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param); ...@@ -87,10 +84,14 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param);
* @param btnm pointer to a button matrix object * @param btnm pointer to a button matrix object
* @param map pointer a string array. The last string has to be: "". * @param map pointer a string array. The last string has to be: "".
* Use "\n" to begin a new line. * Use "\n" to begin a new line.
* Use octal numbers (e.g. "\003") to set the relative * The first byte can be a control data:
* width of a button. (max. 9 -> \011) * - bit 7: always 1
* (e.g. const char * str[] = {"a", "b", "\n", "\004c", "d", ""}). * - bit 6: always 0
* The button do not copy the array so it can not be a local variable. * - bit 5: reserved
* - bit 4: no repeat (on long press)
* - bit 3: hidden
* - bit 2..0: button relative width
* Example (practically use octal numbers): "\224abc": "abc" text with 4 width and no long press
*/ */
void lv_btnm_set_map(lv_obj_t * btnm, const char ** map); void lv_btnm_set_map(lv_obj_t * btnm, const char ** map);
...@@ -99,7 +100,7 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map); ...@@ -99,7 +100,7 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map);
* @param btnm: pointer to button matrix object * @param btnm: pointer to button matrix object
* @param cb pointer to a callback function * @param cb pointer to a callback function
*/ */
void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_callback_t cb); void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_action_t cb);
/** /**
* Enable or disable button toggling * Enable or disable button toggling
...@@ -107,20 +108,18 @@ void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_callback_t cb); ...@@ -107,20 +108,18 @@ void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_callback_t cb);
* @param en true: enable toggling; false: disable toggling * @param en true: enable toggling; false: disable toggling
* @param id index of the currently toggled button (ignored if 'en' == false) * @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); void lv_btnm_set_toggle(lv_obj_t * btnm, bool en, uint16_t id);
/** /**
* Set the styles of the buttons of the button matrix * Set the styles of the buttons of the button matrix
* @param btnm pointer to a button matrix object * @param btnm pointer to a button matrix object
* @param rel pointer to a style for releases state * @param rel pointer to a style for releases state (NULL to leave it unchanged)
* @param pr pointer to a style for pressed state * @param pr pointer to a style for pressed state (NULL to leave it unchanged)
* @param trel pointer to a style for toggled releases state * @param trel pointer to a style for toggled releases state (NULL to leave it unchanged)
* @param tpr pointer to a style for toggled pressed state * @param tpr pointer to a style for toggled pressed state (NULL to leave it unchanged)
* @param ina pointer to a style for inactive state * @param ina pointer to a style for inactive state (NULL to leave it unchanged)
*/ */
void lv_btnm_set_styles_btn(lv_obj_t * btnm, lv_style_t * rel, lv_style_t * pr, void lv_btnm_set_button_style(lv_obj_t *btnm, lv_btn_state_t state, lv_style_t *style);
lv_style_t * trel, lv_style_t * tpr, lv_style_t * ina);
/** /**
* Get the current map of a button matrix * Get the current map of a button matrix
...@@ -134,7 +133,7 @@ const char ** lv_btnm_get_map(lv_obj_t * btnm); ...@@ -134,7 +133,7 @@ const char ** lv_btnm_get_map(lv_obj_t * btnm);
* @param btnm: pointer to button matrix object * @param btnm: pointer to button matrix object
* @return pointer to the callback function * @return pointer to the callback function
*/ */
lv_btnm_callback_t lv_btnm_get_action(lv_obj_t * btnm); lv_btnm_action_t lv_btnm_get_action(lv_obj_t * btnm);
/** /**
* Get the style of buttons in button matrix * Get the style of buttons in button matrix
...@@ -142,7 +141,7 @@ lv_btnm_callback_t lv_btnm_get_action(lv_obj_t * btnm); ...@@ -142,7 +141,7 @@ lv_btnm_callback_t lv_btnm_get_action(lv_obj_t * btnm);
* @param state style in this state (LV_BTN_STATE_PR or LV_BTN_STATE_REL) * @param state style in this state (LV_BTN_STATE_PR or LV_BTN_STATE_REL)
* @return pointer the button style in the given state * @return pointer the button style in the given state
*/ */
lv_style_t * lv_btnm_get_style_btn(lv_obj_t * btnm, lv_btn_state_t state); lv_style_t * lv_btnm_get_button_style(lv_obj_t * btnm, lv_btn_state_t state);
/********************** /**********************
* MACROS * MACROS
......
...@@ -17,7 +17,7 @@ extern "C" { ...@@ -17,7 +17,7 @@ extern "C" {
#if USE_LV_CB != 0 #if USE_LV_CB != 0
/*Testing of dependencies*/ /*Testing of dependencies*/
#if USE_LV_BUTTON == 0 #if USE_LV_BTN == 0
#error "lv_cb: lv_btn is required. Enable it in lv_conf.h (USE_LV_BTN 1) " #error "lv_cb: lv_btn is required. Enable it in lv_conf.h (USE_LV_BTN 1) "
#endif #endif
......
...@@ -238,7 +238,7 @@ void lv_img_set_auto_size(lv_obj_t * img, bool en) ...@@ -238,7 +238,7 @@ void lv_img_set_auto_size(lv_obj_t * img, bool en)
/** /**
* Enable the upscaling with LV_DOWNSCALE. * Enable the upscaling if LV_ANTIALIAS is enabled.
* If enabled the object size will be same as the picture size. * If enabled the object size will be same as the picture size.
* @param img pointer to an image * @param img pointer to an image
* @param en true: upscale enable, false: upscale disable * @param en true: upscale enable, false: upscale disable
...@@ -250,9 +250,9 @@ void lv_img_set_upscale(lv_obj_t * img, bool en) ...@@ -250,9 +250,9 @@ void lv_img_set_upscale(lv_obj_t * img, bool en)
/*Upscale works only if antialiassing is enabled*/ /*Upscale works only if antialiassing is enabled*/
#if LV_ANTIALIAS == 0 #if LV_ANTIALIAS == 0
en = false; en = false;
#endif #else
ext->upscale = (en == false ? 0 : 1); ext->upscale = (en == false ? 0 : 1);
#endif
/*Refresh the image with the new size*/ /*Refresh the image with the new size*/
lv_img_set_file(img, ext->fn); lv_img_set_file(img, ext->fn);
} }
......
...@@ -180,7 +180,7 @@ void lv_line_set_y_inv(lv_obj_t * line, bool yinv) ...@@ -180,7 +180,7 @@ void lv_line_set_y_inv(lv_obj_t * line, bool yinv)
} }
/** /**
* Enable (or disable) the point coordinate upscaling (compensate LV_DOWNSCALE). * Enable (or disable) the points' coordinate upscaling (if LV_ANTIALIAS is enabled).
* @param line pointer to a line object * @param line pointer to a line object
* @param unscale true: enable the point coordinate upscaling * @param unscale true: enable the point coordinate upscaling
*/ */
......
...@@ -21,7 +21,7 @@ extern "C" { ...@@ -21,7 +21,7 @@ extern "C" {
#error "lv_list: lv_page is required. Enable it in lv_conf.h (USE_LV_PAGE 1) " #error "lv_list: lv_page is required. Enable it in lv_conf.h (USE_LV_PAGE 1) "
#endif #endif
#if USE_LV_BUTTON == 0 #if USE_LV_BTN == 0
#error "lv_list: lv_btn is required. Enable it in lv_conf.h (USE_LV_BTN 1) " #error "lv_list: lv_btn is required. Enable it in lv_conf.h (USE_LV_BTN 1) "
#endif #endif
......
...@@ -21,7 +21,7 @@ extern "C" { ...@@ -21,7 +21,7 @@ extern "C" {
#error "lv_mbox: lv_cont is required. Enable it in lv_conf.h (USE_LV_CONT 1) " #error "lv_mbox: lv_cont is required. Enable it in lv_conf.h (USE_LV_CONT 1) "
#endif #endif
#if USE_LV_BUTTON == 0 #if USE_LV_BTN == 0
#error "lv_mbox: lv_btn is required. Enable it in lv_conf.h (USE_LV_BTN 1) " #error "lv_mbox: lv_btn is required. Enable it in lv_conf.h (USE_LV_BTN 1) "
#endif #endif
......
...@@ -284,7 +284,7 @@ static bool lv_slider_design(lv_obj_t * slider, const area_t * mask, lv_design_m ...@@ -284,7 +284,7 @@ static bool lv_slider_design(lv_obj_t * slider, const area_t * mask, lv_design_m
lv_style_t * style_slider = lv_obj_get_style(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_knob = lv_slider_get_style_knob(slider);
lv_style_t * style_indic = lv_bar_get_style_indic(slider); lv_style_t * style_indic = lv_bar_get_indicator_style(slider);
/*Draw the bar*/ /*Draw the bar*/
area_t area_bar; area_t area_bar;
......
...@@ -93,7 +93,7 @@ lv_obj_t * lv_tabview_create(lv_obj_t * par, lv_obj_t * copy) ...@@ -93,7 +93,7 @@ lv_obj_t * lv_tabview_create(lv_obj_t * par, lv_obj_t * copy)
lv_btnm_set_map(ext->tabs, tab_def); lv_btnm_set_map(ext->tabs, tab_def);
lv_obj_set_height(ext->tabs, 3 * LV_DPI / 4); lv_obj_set_height(ext->tabs, 3 * LV_DPI / 4);
lv_btnm_set_action(ext->tabs, tab_btnm_action); lv_btnm_set_action(ext->tabs, tab_btnm_action);
lv_btnm_set_tgl(ext->tabs, true, 0); lv_btnm_set_toggle(ext->tabs, true, 0);
ext->indic = lv_obj_create(ext->tabs, NULL); ext->indic = lv_obj_create(ext->tabs, NULL);
lv_style_t * style_indic = lv_obj_get_style(ext->indic); lv_style_t * style_indic = lv_obj_get_style(ext->indic);
...@@ -279,7 +279,7 @@ void lv_tabview_set_act(lv_obj_t * tabview, uint16_t id, bool anim_en) ...@@ -279,7 +279,7 @@ void lv_tabview_set_act(lv_obj_t * tabview, uint16_t id, bool anim_en)
anim_create(&a); anim_create(&a);
} }
lv_btnm_set_tgl(ext->tabs, true, ext->tab_act); lv_btnm_set_toggle(ext->tabs, true, ext->tab_act);
} }
/*===================== /*=====================
......
...@@ -17,7 +17,7 @@ extern "C" { ...@@ -17,7 +17,7 @@ extern "C" {
#if USE_LV_WIN != 0 #if USE_LV_WIN != 0
/*Testing of dependencies*/ /*Testing of dependencies*/
#if USE_LV_BUTTON == 0 #if USE_LV_BTN == 0
#error "lv_win: lv_btn is required. Enable it in lv_conf.h (USE_LV_BTN 1) " #error "lv_win: lv_btn is required. Enable it in lv_conf.h (USE_LV_BTN 1) "
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment