Merge branch 'spinbox' of github.com:AloyseTech/lvgl into spinbox

This commit is contained in:
AloyseTech
2018-11-05 14:02:13 +01:00
2 changed files with 424 additions and 404 deletions

View File

@@ -21,7 +21,6 @@
/********************** /**********************
* STATIC PROTOTYPES * STATIC PROTOTYPES
**********************/ **********************/
static bool lv_spinbox_design(lv_obj_t * spinbox, const lv_area_t * mask, lv_design_mode_t mode);
static lv_res_t lv_spinbox_signal(lv_obj_t * spinbox, lv_signal_t sign, void * param); static lv_res_t lv_spinbox_signal(lv_obj_t * spinbox, lv_signal_t sign, void * param);
static void lv_spinbox_updatevalue(lv_obj_t * spinbox); static void lv_spinbox_updatevalue(lv_obj_t * spinbox);
@@ -47,287 +46,275 @@ static lv_design_func_t ancestor_design;
*/ */
lv_obj_t * lv_spinbox_create(lv_obj_t * par, const lv_obj_t * copy) lv_obj_t * lv_spinbox_create(lv_obj_t * par, const lv_obj_t * copy)
{ {
LV_LOG_TRACE("spinbox create started"); LV_LOG_TRACE("spinbox create started");
/*Create the ancestor of spinbox*/ /*Create the ancestor of spinbox*/
lv_obj_t * new_spinbox = lv_ta_create(par, copy); lv_obj_t * new_spinbox = lv_ta_create(par, copy);
lv_mem_assert(new_spinbox); lv_mem_assert(new_spinbox);
if(new_spinbox == NULL) return NULL; if(new_spinbox == NULL) return NULL;
/*Allocate the spinbox type specific extended data*/ /*Allocate the spinbox type specific extended data*/
lv_spinbox_ext_t * ext = lv_obj_allocate_ext_attr(new_spinbox, sizeof(lv_spinbox_ext_t)); lv_spinbox_ext_t * ext = lv_obj_allocate_ext_attr(new_spinbox, sizeof(lv_spinbox_ext_t));
lv_mem_assert(ext); lv_mem_assert(ext);
if(ext == NULL) return NULL; if(ext == NULL) return NULL;
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_spinbox); if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_spinbox);
if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_spinbox); if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_spinbox);
/*Initialize the allocated 'ext'*/ /*Initialize the allocated 'ext'*/
ext->ta.one_line = 1; ext->ta.one_line = 1;
ext->ta.pwd_mode = 0; ext->ta.pwd_mode = 0;
ext->ta.accapted_chars = "1234567890+-."; ext->ta.accapted_chars = "1234567890+-.";
ext->value = 0; ext->value = 0;
ext->decPointPos = 2; ext->dec_point_pos = 2;
ext->digitCount = 5; ext->digit_count = 5;
ext->step = 100; ext->step = 100;
ext->rangeMax = 99999; ext->range_max = 99999;
ext->rangeMin = -99999; ext->range_min = -99999;
ext->value_changed_cb = NULL;
lv_ta_set_cursor_type(new_spinbox, LV_CURSOR_BLOCK | LV_CURSOR_HIDDEN); /*hidden by default*/ lv_ta_set_cursor_type(new_spinbox, LV_CURSOR_BLOCK | LV_CURSOR_HIDDEN); /*hidden by default*/
lv_ta_set_cursor_pos(new_spinbox, 4); lv_ta_set_cursor_pos(new_spinbox, 4);
/*The signal and design functions are not copied so set them here*/ /*The signal and design functions are not copied so set them here*/
lv_obj_set_signal_func(new_spinbox, lv_spinbox_signal); lv_obj_set_signal_func(new_spinbox, lv_spinbox_signal);
lv_obj_set_design_func(new_spinbox, lv_spinbox_design); lv_obj_set_design_func(new_spinbox, ancestor_design); /*Leave the Text area's design function*/
/*Init the new spinbox spinbox*/ /*Init the new spinbox spinbox*/
if(copy == NULL) { if(copy == NULL) {
/*Already inited above*/
}
/*Copy an existing spinbox*/
else {
lv_spinbox_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
} lv_spinbox_set_value(new_spinbox, copy_ext->value);
/*Copy an existing spinbox*/ lv_spinbox_set_digit_format(new_spinbox, copy_ext->digit_count, copy_ext->dec_point_pos);
else { lv_spinbox_set_range(new_spinbox, copy_ext->range_min, copy_ext->range_max);
lv_spinbox_ext_t * copy_ext = lv_obj_get_ext_attr(copy); lv_spinbox_set_step(new_spinbox, copy_ext->step);
/*Refresh the style with new signal function*/ /*Refresh the style with new signal function*/
lv_obj_refresh_style(new_spinbox); lv_obj_refresh_style(new_spinbox);
} }
lv_spinbox_updatevalue(new_spinbox); lv_spinbox_updatevalue(new_spinbox);
LV_LOG_INFO("spinbox created"); LV_LOG_INFO("spinbox created");
return new_spinbox; return new_spinbox;
} }
void lv_spinbox_step_next(lv_obj_t * spinbox)
{
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
if((ext->step / 10) < ext->rangeMax && (ext->step / 10) > ext->rangeMin && (ext->step / 10) > 0)
{
ext->step /= 10;
}
lv_spinbox_updatevalue(spinbox);
}
void lv_spinbox_step_previous(lv_obj_t * spinbox)
{
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
if((ext->step * 10) <= ext->rangeMax && (ext->step * 10) > ext->rangeMin && (ext->step * 10) > 0)
{
ext->step *= 10;
}
lv_spinbox_updatevalue(spinbox);
}
void lv_spinbox_increment(lv_obj_t * spinbox)
{
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
if(ext->value + ext->step <= ext->rangeMax)
{
/*Special mode when zero crossing*/
if((ext->value + ext->step) > 0 && ext->value < 0)
{
ext->value = -ext->value;
}/*end special mode*/
ext->value += ext->step;
}
lv_spinbox_updatevalue(spinbox);
}
void lv_spinbox_decrement(lv_obj_t * spinbox)
{
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
if(ext->value - ext->step >= ext->rangeMin)
{
/*Special mode when zero crossing*/
if((ext->value - ext->step) < 0 && ext->value > 0)
{
ext->value = -ext->value;
}/*end special mode*/
ext->value -= ext->step;
}
lv_spinbox_updatevalue(spinbox);
}
/*======================
* Add/remove functions
*=====================*/
/*
* New object specific "add" or "remove" functions come here
*/
/*===================== /*=====================
* Setter functions * Setter functions
*====================*/ *====================*/
/**
* Set spinbox value
* @param spinbox pointer to spinbox
* @param i value to be set
*/
void lv_spinbox_set_value(const lv_obj_t * spinbox, int32_t i) void lv_spinbox_set_value(const lv_obj_t * spinbox, int32_t i)
{ {
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
if(ext == NULL) if(ext == NULL)
return; return;
if(i > ext->rangeMax) if(i > ext->range_max)
i = ext->rangeMax; i = ext->range_max;
if(i < ext->rangeMin) if(i < ext->range_min)
i = ext->rangeMin; i = ext->range_min;
ext->value = i; ext->value = i;
lv_spinbox_updatevalue(spinbox); lv_spinbox_updatevalue(spinbox);
} }
void lv_spinbox_set_digit_format(const lv_obj_t * spinbox, uint8_t digit_count, uint8_t separator_position)
{
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
if(ext == NULL)
return;
if(digit_count > LV_SPINBOX_MAX_DIGIT_COUNT)
digit_count = LV_SPINBOX_MAX_DIGIT_COUNT;
if(separator_position < LV_SPINBOX_MAX_DIGIT_COUNT)
separator_position = LV_SPINBOX_MAX_DIGIT_COUNT;
ext->digitCount = digit_count;
ext->decPointPos = separator_position;
lv_spinbox_updatevalue(spinbox);
}
void lv_spinbox_set_range(const lv_obj_t * spinbox, int32_t rangeMin, int32_t rangeMax)
{
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
if(ext == NULL)
return;
ext->rangeMax = rangeMax;
ext->rangeMin = rangeMin;
if(ext->value > ext->rangeMax)
{
ext->value = ext->rangeMax;
lv_obj_invalidate(spinbox);
}
if(ext->value < ext->rangeMin)
{
ext->value = ext->rangeMin;
lv_obj_invalidate(spinbox);
}
}
/** /**
* Set a style of a spinbox. * Set spinbox digit format (digit count and decimal format)
* @param spinbox pointer to spinbox object * @param spinbox pointer to spinbox
* @param type which style should be set * @param digit_count number of digit excluding the decimal separator and the sign
* @param style pointer to a style * @param separator_position number of digit before the decimal point. If 0, decimal point is not shown
*/ */
void lv_spinbox_set_style(lv_obj_t * spinbox, lv_spinbox_style_t type, lv_style_t * style) void lv_spinbox_set_digit_format(const lv_obj_t * spinbox, uint8_t digit_count, uint8_t separator_position)
{ {
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
if(ext == NULL)
return;
switch(type) { if(digit_count > LV_SPINBOX_MAX_DIGIT_COUNT)
case LV_SPINBOX_STYLE_BG: digit_count = LV_SPINBOX_MAX_DIGIT_COUNT;
lv_page_set_style(spinbox, LV_PAGE_STYLE_BG, style);
break; if(separator_position < LV_SPINBOX_MAX_DIGIT_COUNT)
case LV_SPINBOX_STYLE_SB: separator_position = LV_SPINBOX_MAX_DIGIT_COUNT;
lv_page_set_style(spinbox, LV_PAGE_STYLE_SB, style);
break; ext->digit_count = digit_count;
case LV_SPINBOX_STYLE_CURSOR: ext->dec_point_pos = separator_position;
ext->ta.cursor.style = style;
lv_obj_refresh_ext_size(lv_page_get_scrl(spinbox)); /*Refresh ext. size because of cursor drawing*/ lv_spinbox_updatevalue(spinbox);
break; }
}
/**
* Set spinbox step
* @param spinbox pointer to spinbox
* @param step steps on increment/decrement
*/
void lv_spinbox_set_step(const lv_obj_t * spinbox, uint32_t step)
{
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
if(ext == NULL) return;
ext->step = step;
}
/**
* Set spinbox value range
* @param spinbox pointer to spinbox
* @param range_min maximum value, inclusive
* @param range_max minimum value, inclusive
*/
void lv_spinbox_set_range(const lv_obj_t * spinbox, int32_t range_min, int32_t range_max)
{
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
if(ext == NULL) return;
ext->range_max = range_max;
ext->range_min = range_min;
if(ext->value > ext->range_max)
{
ext->value = ext->range_max;
lv_obj_invalidate(spinbox);
}
if(ext->value < ext->range_min)
{
ext->value = ext->range_min;
lv_obj_invalidate(spinbox);
}
}
/**
* Set spinbox callback on calue change
* @param spinbox pointer to spinbox
* @param cb Callback function called on value change event
*/
void lv_spinbox_set_value_changed_cb(const lv_obj_t * spinbox, lv_spinbox_value_changed_cb_t cb)
{
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
ext->value_changed_cb = cb;
} }
/*===================== /*=====================
* Getter functions * Getter functions
*====================*/ *====================*/
/*
* New object specific "get" functions come here
*/
/** /**
* Get style of a spinbox. * Get the spinbox numeral value (user has to convert to float according to its digit format)
* @param spinbox pointer to spinbox object * @param spinbox pointer to spinbox
* @param type which style should be get * @return value integer value of the spinbox
* @return style pointer to the style
*/ */
lv_style_t * lv_spinbox_get_style(const lv_obj_t * spinbox, lv_spinbox_style_t type)
{
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
switch(type) {
default:
return NULL;
}
/*To avoid warning*/
return NULL;
}
int32_t lv_spinbox_get_value(const lv_obj_t * spinbox) int32_t lv_spinbox_get_value(const lv_obj_t * spinbox)
{ {
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
return ext->value; return ext->value;
} }
/*===================== /*=====================
* Other functions * Other functions
*====================*/ *====================*/
/* /**
* New object specific "other" functions come here * Select next lower digit for edition by dividing the step by 10
* @param spinbox pointer to spinbox
*/ */
void lv_spinbox_step_next(lv_obj_t * spinbox)
{
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
if((ext->step / 10) < ext->range_max && (ext->step / 10) > ext->range_min && (ext->step / 10) > 0)
{
ext->step /= 10;
}
lv_spinbox_updatevalue(spinbox);
}
/**
* Select next higher digit for edition by multiplying the step by 10
* @param spinbox pointer to spinbox
*/
void lv_spinbox_step_previous(lv_obj_t * spinbox)
{
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
if((ext->step * 10) <= ext->range_max && (ext->step * 10) > ext->range_min && (ext->step * 10) > 0)
{
ext->step *= 10;
}
lv_spinbox_updatevalue(spinbox);
}
/**
* Increment spinbox value by one step
* @param spinbox pointer to spinbox
*/
void lv_spinbox_increment(lv_obj_t * spinbox)
{
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
if(ext->value + ext->step <= ext->range_max)
{
/*Special mode when zero crossing*/
if((ext->value + ext->step) > 0 && ext->value < 0)
{
ext->value = -ext->value;
}/*end special mode*/
ext->value += ext->step;
if(ext->value_changed_cb != NULL)
{
ext->value_changed_cb(spinbox, ext->value);
}
}
lv_spinbox_updatevalue(spinbox);
}
/**
* Decrement spinbox value by one step
* @param spinbox pointer to spinbox
*/
void lv_spinbox_decrement(lv_obj_t * spinbox)
{
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
if(ext->value - ext->step >= ext->range_min)
{
/*Special mode when zero crossing*/
if((ext->value - ext->step) < 0 && ext->value > 0)
{
ext->value = -ext->value;
}/*end special mode*/
ext->value -= ext->step;
if(ext->value_changed_cb != NULL)
{
ext->value_changed_cb(spinbox, ext->value);
}
}
lv_spinbox_updatevalue(spinbox);
}
/********************** /**********************
* STATIC FUNCTIONS * STATIC FUNCTIONS
**********************/ **********************/
/**
* Handle the drawing related tasks of the spinboxs
* @param spinbox 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_spinbox_design(lv_obj_t * spinbox, const lv_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;
}
/** /**
* Signal function of the spinbox * Signal function of the spinbox
* @param spinbox pointer to a spinbox object * @param spinbox pointer to a spinbox object
@@ -338,132 +325,146 @@ static bool lv_spinbox_design(lv_obj_t * spinbox, const lv_area_t * mask, lv_des
static lv_res_t lv_spinbox_signal(lv_obj_t * spinbox, lv_signal_t sign, void * param) static lv_res_t lv_spinbox_signal(lv_obj_t * spinbox, lv_signal_t sign, void * param)
{ {
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
lv_res_t res; lv_res_t res;
/* Include the ancient signal function */ /* Include the ancient signal function */
if(sign != LV_SIGNAL_CONTROLL) if(sign != LV_SIGNAL_CONTROLL)
{ {
res = ancestor_signal(spinbox, sign, param); res = ancestor_signal(spinbox, sign, param);
if(res != LV_RES_OK) return res; if(res != LV_RES_OK) return res;
} }
if(sign == LV_SIGNAL_CLEANUP) {
/*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
} else if(sign == LV_SIGNAL_GET_TYPE)
{
lv_obj_type_t * buf = param;
uint8_t i;
for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++)
{ /*Find the last set data*/
if(buf->type[i] == NULL) break;
}
buf->type[i] = "lv_spinbox";
}else if(sign == LV_SIGNAL_CONTROLL)
{
lv_hal_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act());
uint32_t c = *((uint32_t *)param); /*uint32_t because can be UTF-8*/
if(c == LV_GROUP_KEY_RIGHT)
{
if(indev_type == LV_INDEV_TYPE_ENCODER)
{
lv_spinbox_decrement(spinbox);
}
else
{
lv_spinbox_step_next(spinbox);
}
}
else if(c == LV_GROUP_KEY_LEFT)
{
if(indev_type == LV_INDEV_TYPE_ENCODER)
{
lv_spinbox_increment(spinbox);
}
else
{
lv_spinbox_step_previous(spinbox);
}
}
else if(c == LV_GROUP_KEY_UP)
{
lv_spinbox_increment(spinbox);
}
else if(c == LV_GROUP_KEY_DOWN)
{
lv_spinbox_decrement(spinbox);
}
else
{
if(c == LV_GROUP_KEY_ENTER)
{
int p = lv_ta_get_cursor_pos(spinbox);
if(p == ext->digit_count + 1)
{
for(int i = 0; i < ext->digit_count; i++)
lv_spinbox_step_previous(spinbox);
} else
{
lv_spinbox_step_next(spinbox);
}
if(sign == LV_SIGNAL_CLEANUP) { lv_spinbox_updatevalue(spinbox);
/*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/ }
} else if(sign == LV_SIGNAL_GET_TYPE) else
{ {
lv_obj_type_t * buf = param; lv_ta_add_char(spinbox, c);
uint8_t i; }
for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) }
{ /*Find the last set data*/ }
if(buf->type[i] == NULL) break;
}
buf->type[i] = "lv_spinbox";
}else if(sign == LV_SIGNAL_CONTROLL)
{
uint32_t c = *((uint32_t *)param); /*uint32_t because can be UTF-8*/
if(c == LV_GROUP_KEY_RIGHT)
{
lv_spinbox_decrement(spinbox);
}
else if(c == LV_GROUP_KEY_LEFT)
{
lv_spinbox_increment(spinbox);
}
else if(c == LV_GROUP_KEY_UP)
{
lv_ta_cursor_up(spinbox);
}
else if(c == LV_GROUP_KEY_DOWN)
{
lv_ta_cursor_down(spinbox);
}
else
{
if(c == LV_GROUP_KEY_ENTER)
{
int p = lv_ta_get_cursor_pos(spinbox);
if(p == ext->digitCount + 1)
{
for(int i = 0; i < ext->digitCount; i++)
lv_spinbox_step_previous(spinbox);
} else
{
lv_spinbox_step_next(spinbox);
}
lv_spinbox_updatevalue(spinbox); return res;
lv_label_set_text(ext->ta.label, (char*)ext->digits);
}
else
{
lv_ta_add_char(spinbox, c);
}
}
}
return res;
} }
static void lv_spinbox_updatevalue(lv_obj_t * spinbox) static void lv_spinbox_updatevalue(lv_obj_t * spinbox)
{ {
lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox);
int32_t v = ext->value; int32_t v = ext->value;
int32_t intDigits, decDigits; int32_t intDigits, decDigits;
uint8_t dc = ext->digitCount; uint8_t dc = ext->digit_count;
intDigits = (ext->decPointPos==0)?ext->digitCount:ext->decPointPos; intDigits = (ext->dec_point_pos==0) ? ext->digit_count : ext->dec_point_pos;
decDigits = ext->digitCount - intDigits; decDigits = ext->digit_count - intDigits;
ext->digits[0] = v>=0?'+':'-'; ext->digits[0] = v>=0 ? '+' : '-';
int i = 0; int i = 0;
uint8_t digits[16]; uint8_t digits[16];
if(v < 0) if(v < 0)
v = -v; v = -v;
for(i = 0; i < dc; i++) for(i = 0; i < dc; i++)
{ {
digits[i] = v%10; digits[i] = v%10;
v = v/10; v = v/10;
} }
int k; int k;
for(k = 0; k < intDigits; k++) for(k = 0; k < intDigits; k++)
{ {
ext->digits[1 + k] = '0' + digits[--i]; ext->digits[1 + k] = '0' + digits[--i];
} }
ext->digits[1 + intDigits] = '.'; ext->digits[1 + intDigits] = '.';
int d; int d;
for(d = 0; d < decDigits; d++) for(d = 0; d < decDigits; d++)
{ {
ext->digits[1 + intDigits + 1 + d] = '0' + digits[--i]; ext->digits[1 + intDigits + 1 + d] = '0' + digits[--i];
} }
ext->digits[1 + intDigits + 1 + decDigits] = '\0'; ext->digits[1 + intDigits + 1 + decDigits] = '\0';
lv_label_set_text(ext->ta.label, (char*)ext->digits); lv_label_set_text(ext->ta.label, (char*)ext->digits);
int32_t step = ext->step; int32_t step = ext->step;
uint8_t cPos = ext->digitCount; uint8_t cPos = ext->digit_count;
while(step >= 10) while(step >= 10)
{ {
step /= 10; step /= 10;
cPos--; cPos--;
} }
if(cPos > intDigits) if(cPos > intDigits)
{ {
cPos ++; cPos ++;
} }
lv_ta_set_cursor_pos(spinbox, cPos); lv_ta_set_cursor_pos(spinbox, cPos);
} }
#endif #endif

View File

@@ -33,20 +33,24 @@ extern "C" {
/********************** /**********************
* TYPEDEFS * TYPEDEFS
**********************/ **********************/
/*callback on value change*/
typedef void (*lv_spinbox_value_changed_cb_t)(lv_obj_t * spinbox, int32_t new_value);
/*Data of spinbox*/ /*Data of spinbox*/
typedef struct { typedef struct {
lv_ta_ext_t ta; /*Ext. of ancestor*/ lv_ta_ext_t ta; /*Ext. of ancestor*/
/*New data for this type */ /*New data for this type */
int32_t value; int32_t value;
int32_t rangeMax; int32_t range_max;
int32_t rangeMin; int32_t range_min;
int32_t step; int32_t step;
uint8_t digitCount:4; uint8_t digit_count:4;
uint8_t decPointPos:4; /*if 0, there is no separator and the number is an integer*/ uint8_t dec_point_pos:4; /*if 0, there is no separator and the number is an integer*/
uint8_t digitPaddingLeft:4; uint8_t digit_padding_left:4;
uint8_t digitPaddingRight:4; uint8_t digit_padding_right:4;
uint8_t digits[1+1+LV_SPINBOX_MAX_DIGIT_COUNT]; /*1 sign, 1 point, 16 num digits*/ uint8_t digits[1+1+LV_SPINBOX_MAX_DIGIT_COUNT]; /*1 sign, 1 point, 16 num digits*/
lv_spinbox_value_changed_cb_t value_changed_cb;
} lv_spinbox_ext_t; } lv_spinbox_ext_t;
@@ -71,6 +75,85 @@ typedef uint8_t lv_spinbox_style_t;
*/ */
lv_obj_t * lv_spinbox_create(lv_obj_t * par, const lv_obj_t * copy); lv_obj_t * lv_spinbox_create(lv_obj_t * par, const lv_obj_t * copy);
/*=====================
* Setter functions
*====================*/
/**
* Set a style of a spinbox.
* @param templ pointer to template object
* @param type which style should be set
* @param style pointer to a style
*/
static inline void lv_spinbox_set_style(lv_obj_t * spinbox, lv_spinbox_style_t type, lv_style_t *style)
{
lv_ta_set_style(spinbox, type, style);
}
/**
* Set spinbox value
* @param spinbox pointer to spinbox
* @param i value to be set
*/
void lv_spinbox_set_value(const lv_obj_t * spinbox, int32_t i);
/**
* Set spinbox digit format (digit count and decimal format)
* @param spinbox pointer to spinbox
* @param digit_count number of digit excluding the decimal separator and the sign
* @param separator_position number of digit before the decimal point. If 0, decimal point is not shown
*/
void lv_spinbox_set_digit_format(const lv_obj_t * spinbox, uint8_t digit_count, uint8_t separator_position);
/**
* Set spinbox step
* @param spinbox pointer to spinbox
* @param step steps on increment/decrement
*/
void lv_spinbox_set_step(const lv_obj_t * spinbox, uint32_t step);
/**
* Set spinbox value range
* @param spinbox pointer to spinbox
* @param range_min maximum value, inclusive
* @param range_max minimum value, inclusive
*/
void lv_spinbox_set_range(const lv_obj_t * spinbox, int32_t range_min, int32_t range_max);
/**
* Set spinbox callback on calue change
* @param spinbox pointer to spinbox
* @param cb Callback function called on value change event
*/
void lv_spinbox_set_value_changed_cb(const lv_obj_t * spinbox, lv_spinbox_value_changed_cb_t cb);
/*=====================
* Getter functions
*====================*/
/**
* Get style of a spinbox.
* @param templ pointer to template object
* @param type which style should be get
* @return style pointer to the style
*/
static inline lv_style_t * lv_spinbox_get_style(const lv_obj_t * spinbox, lv_spinbox_style_t type)
{
return lv_ta_get_style(spinbox, type);
}
/**
* Get the spinbox numeral value (user has to convert to float according to its digit format)
* @param spinbox pointer to spinbox
* @return value integer value of the spinbox
*/
int32_t lv_spinbox_get_value(const lv_obj_t * spinbox);
/*=====================
* Other functions
*====================*/
/** /**
* Select next lower digit for edition by dividing the step by 10 * Select next lower digit for edition by dividing the step by 10
* @param spinbox pointer to spinbox * @param spinbox pointer to spinbox
@@ -96,70 +179,6 @@ void lv_spinbox_increment(lv_obj_t * spinbox);
void lv_spinbox_decrement(lv_obj_t * spinbox); void lv_spinbox_decrement(lv_obj_t * spinbox);
/*======================
* Add/remove functions
*=====================*/
/*=====================
* Setter functions
*====================*/
/**
* Set a style of a spinbox.
* @param templ pointer to template object
* @param type which style should be set
* @param style pointer to a style
*/
void lv_spinbox_set_style(lv_obj_t * spinbox, lv_spinbox_style_t type, lv_style_t *style);
/**
* Set spinbox value
* @param spinbox pointer to spinbox
* @param i value to be set
*/
void lv_spinbox_set_value(const lv_obj_t * spinbox, int32_t i);
/**
* Set spinbox digit format (digit count and decimal format)
* @param spinbox pointer to spinbox
* @param digit_count number of digit excluding the decimal separator and the sign
* @param separator_position number of digit before the decimal point. If 0, decimal point is not shown
*/
void lv_spinbox_set_digit_format(const lv_obj_t * spinbox, uint8_t digit_count, uint8_t separator_position);
/**
* Set spinbox value range
* @param spinbox pointer to spinbox
* @param i rangeMin maximum value, inclusive
* @param i rangeMax minimum value, inclusive
*/
void lv_spinbox_set_range(const lv_obj_t * spinbox, int32_t rangeMin, int32_t rangeMax);
/*=====================
* Getter functions
*====================*/
/**
* Get style of a spinbox.
* @param templ pointer to template object
* @param type which style should be get
* @return style pointer to the style
*/
lv_style_t * lv_spinbox_get_style(const lv_obj_t * spinbox, lv_spinbox_style_t type);
/**
* Get the spinbox numeral value (user has to convert to float according to its digit format)
* @param spinbox pointer to spinbox
* @return value integer value of the spinbox
*/
int32_t lv_spinbox_get_value(const lv_obj_t * spinbox);
/*=====================
* Other functions
*====================*/
/********************** /**********************
* MACROS * MACROS
**********************/ **********************/