Skip to content

Commit

Permalink
feat(spinbox ) add function to set cursor to specific position (#2314)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
dyktronix and Sebastian Dyker committed Jun 17, 2021
1 parent 428db94 commit 7066c8f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/widgets/extra/spinbox.md
Expand Up @@ -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.
Expand Down
17 changes: 17 additions & 0 deletions src/extra/widgets/spinbox/lv_spinbox.c
Expand Up @@ -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
*====================*/
Expand Down
6 changes: 6 additions & 0 deletions src/extra/widgets/spinbox/lv_spinbox.h
Expand Up @@ -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
*====================*/
Expand Down

0 comments on commit 7066c8f

Please sign in to comment.