1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

Adjusting min and max values to the number format

This commit is contained in:
Wielebny666 2020-04-29 13:24:07 +02:00
parent 5e9dd93e76
commit c2404c307c
4 changed files with 36 additions and 1 deletions

View File

@ -198,6 +198,26 @@ uint32_t lv_sqrt(uint32_t num)
return root; return root;
} }
/**
* Calculate the integer exponents.
* @param base
* @param power
* @return base raised to the power exponent
*/
int64_t lv_pow(int64_t base, int8_t exp)
{
int64_t result = 1;
while (exp)
{
if (exp & 1)
result *= base;
exp >>= 1;
base *= base;
}
return result;
}
/********************** /**********************
* STATIC FUNCTIONS * STATIC FUNCTIONS
**********************/ **********************/

View File

@ -74,6 +74,14 @@ uint16_t lv_atan2(int x, int y);
*/ */
uint32_t lv_sqrt(uint32_t num); uint32_t lv_sqrt(uint32_t num);
/**
* Calculate the integer exponents.
* @param base
* @param power
* @return base raised to the power exponent
*/
int64_t lv_pow(int64_t base, int8_t exp);
/********************** /**********************
* MACROS * MACROS
**********************/ **********************/

View File

@ -154,6 +154,13 @@ void lv_spinbox_set_digit_format(lv_obj_t * spinbox, uint8_t digit_count, uint8_
if(separator_position > LV_SPINBOX_MAX_DIGIT_COUNT) separator_position = LV_SPINBOX_MAX_DIGIT_COUNT; if(separator_position > LV_SPINBOX_MAX_DIGIT_COUNT) separator_position = LV_SPINBOX_MAX_DIGIT_COUNT;
if(digit_count < LV_SPINBOX_MAX_DIGIT_COUNT)
{
uint64_t max_val = lv_pow(10, digit_count);
if(ext->range_max > max_val - 1) ext->range_max = max_val - 1;
if(ext->range_min < - max_val + 1) ext->range_min = - max_val + 1;
}
ext->digit_count = digit_count; ext->digit_count = digit_count;
ext->dec_point_pos = separator_position; ext->dec_point_pos = separator_position;

View File

@ -32,7 +32,7 @@ extern "C" {
/********************* /*********************
* DEFINES * DEFINES
*********************/ *********************/
#define LV_SPINBOX_MAX_DIGIT_COUNT 16 #define LV_SPINBOX_MAX_DIGIT_COUNT 10
/********************** /**********************
* TYPEDEFS * TYPEDEFS