diff --git a/docs/widgets/extra/spinbox.md b/docs/widgets/extra/spinbox.md index 920c1be1c..717a53d5d 100644 --- a/docs/widgets/extra/spinbox.md +++ b/docs/widgets/extra/spinbox.md @@ -20,6 +20,8 @@ The parts of the Spinbox are identical to the [Text area](/widgets/core/textarea `lv_spinbox_set_step(spinbox, 100)` sets which digits to change on increment/decrement. Only multiples of ten can be set, and not for example 3. +`lv_spinbox_set_pos(spinbox, 1)` sets the cursor to a specific digit to change on increment/decrement. For example position '0' sets the cursor to the least significant digit. + ### Format `lv_spinbox_set_digit_format(spinbox, digit_count, separator_position)` sets the number format. `digit_count` is the number of digits excluding the decimal separator and the sign. diff --git a/src/extra/widgets/spinbox/lv_spinbox.c b/src/extra/widgets/spinbox/lv_spinbox.c index 66bfdd0e6..5d972d5a8 100644 --- a/src/extra/widgets/spinbox/lv_spinbox.c +++ b/src/extra/widgets/spinbox/lv_spinbox.c @@ -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 *====================*/ diff --git a/src/extra/widgets/spinbox/lv_spinbox.h b/src/extra/widgets/spinbox/lv_spinbox.h index 92000a042..ce3bce27c 100644 --- a/src/extra/widgets/spinbox/lv_spinbox.h +++ b/src/extra/widgets/spinbox/lv_spinbox.h @@ -99,6 +99,12 @@ void lv_spinbox_set_step(lv_obj_t * obj, uint32_t step); */ void lv_spinbox_set_range(lv_obj_t * obj, int32_t range_min, int32_t range_max); +/** + * 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); /*===================== * Getter functions *====================*/