feat(spinbox ) add function to set cursor to specific position (#2314)

* Spinbox set cursor to specific position (funct.)

* changed exp10 to lv_pow(10

* Update lv_spinbox.c

resolved indentation

* Update spinbox.md

Added lv_spinbox_set_pos description

Co-authored-by: Sebastian Dyker <sebastian.dyker@walther-systemtechnik.com>
This commit is contained in:
dyktronix
2021-06-17 13:43:19 +02:00
committed by GitHub
parent 428db9494d
commit 7066c8fbbb
3 changed files with 25 additions and 0 deletions

View File

@@ -145,6 +145,23 @@ void lv_spinbox_set_range(lv_obj_t * obj, int32_t range_min, int32_t range_max)
lv_spinbox_updatevalue(obj);
}
/**
* Set cursor position to a specific digit for edition
* @param spinbox pointer to spinbox
* @param pos selected position in spinbox
*/
void lv_spinbox_set_pos(lv_obj_t * obj, uint8_t pos)
{
lv_spinbox_t * spinbox = (lv_spinbox_t *)obj;
int32_t step_limit;
step_limit = LV_MAX(spinbox->range_max, (spinbox->range_min < 0 ? (-spinbox->range_min) : spinbox->range_min));
int32_t new_step = spinbox->step * lv_pow(10, pos);
if(pos <= 0) spinbox->step = 1;
else if(new_step <= step_limit) spinbox->step = new_step;
lv_spinbox_updatevalue(obj);
}
/*=====================
* Getter functions
*====================*/