Skip to content

Commit

Permalink
scale: Use positive values for properties where reasonable
Browse files Browse the repository at this point in the history
total_tick_count and major_tick_every properties are positive numbers only, adjust API accordingly. Same for major and minor tick length
  • Loading branch information
C47D committed Dec 25, 2023
1 parent 547cb3d commit e994209
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
8 changes: 4 additions & 4 deletions src/widgets/scale/lv_scale.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void lv_scale_set_mode(lv_obj_t * obj, lv_scale_mode_t mode)
lv_obj_invalidate(obj);
}

void lv_scale_set_total_tick_count(lv_obj_t * obj, int32_t total_tick_count)
void lv_scale_set_total_tick_count(lv_obj_t * obj, uint32_t total_tick_count)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_scale_t * scale = (lv_scale_t *)obj;
Expand All @@ -120,7 +120,7 @@ void lv_scale_set_total_tick_count(lv_obj_t * obj, int32_t total_tick_count)
lv_obj_invalidate(obj);
}

void lv_scale_set_major_tick_every(lv_obj_t * obj, int32_t major_tick_every)
void lv_scale_set_major_tick_every(lv_obj_t * obj, uint32_t major_tick_every)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_scale_t * scale = (lv_scale_t *)obj;
Expand All @@ -130,7 +130,7 @@ void lv_scale_set_major_tick_every(lv_obj_t * obj, int32_t major_tick_every)
lv_obj_invalidate(obj);
}

void lv_scale_set_major_tick_length(lv_obj_t * obj, int32_t major_len)
void lv_scale_set_major_tick_length(lv_obj_t * obj, uint32_t major_len)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_scale_t * scale = (lv_scale_t *)obj;
Expand All @@ -140,7 +140,7 @@ void lv_scale_set_major_tick_length(lv_obj_t * obj, int32_t major_len)
lv_obj_invalidate(obj);
}

void lv_scale_set_minor_tick_length(lv_obj_t * obj, int32_t minor_len)
void lv_scale_set_minor_tick_length(lv_obj_t * obj, uint32_t minor_len)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_scale_t * scale = (lv_scale_t *)obj;
Expand Down
23 changes: 12 additions & 11 deletions src/widgets/scale/lv_scale.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,22 @@ typedef struct {
lv_obj_t obj;
lv_ll_t section_ll; /**< Linked list for the sections (stores lv_scale_section_t)*/
const char ** txt_src;
int32_t custom_label_cnt;
int32_t major_len;
int32_t minor_len;
lv_scale_mode_t mode;
uint32_t major_len;
uint32_t minor_len;
int32_t range_min;
int32_t range_max;
uint32_t total_tick_count : 15;
uint32_t major_tick_every : 15;
lv_scale_mode_t mode;
uint32_t label_enabled : 1;
uint32_t post_draw : 1;
int32_t last_tick_width;
int32_t first_tick_width;
uint32_t post_draw : 1;
/* Round scale */
uint32_t angle_range;
int32_t rotation;
/* Private properties */
int32_t custom_label_cnt;
int32_t last_tick_width;
int32_t first_tick_width;
} lv_scale_t;

LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_scale_class;
Expand Down Expand Up @@ -125,14 +126,14 @@ void lv_scale_set_mode(lv_obj_t * obj, lv_scale_mode_t mode);
* @param obj pointer the scale object
* @param total_tick_count New total tick count
*/
void lv_scale_set_total_tick_count(lv_obj_t * obj, int32_t total_tick_count);
void lv_scale_set_total_tick_count(lv_obj_t * obj, uint32_t total_tick_count);

/**
* Sets how often the major tick will be drawn
* @param obj pointer the scale object
* @param major_tick_every the new count for major tick drawing
*/
void lv_scale_set_major_tick_every(lv_obj_t * obj, int32_t major_tick_every);
void lv_scale_set_major_tick_every(lv_obj_t * obj, uint32_t major_tick_every);

/**
* Sets label visibility
Expand All @@ -146,14 +147,14 @@ void lv_scale_set_label_show(lv_obj_t * obj, bool show_label);
* @param obj pointer the scale object
* @param major_len major tick length
*/
void lv_scale_set_major_tick_length(lv_obj_t * obj, int32_t major_len);
void lv_scale_set_major_tick_length(lv_obj_t * obj, uint32_t major_len);

/**
* Sets major tick length
* @param obj pointer the scale object
* @param minor_len minor tick length
*/
void lv_scale_set_minor_tick_length(lv_obj_t * obj, int32_t minor_len);
void lv_scale_set_minor_tick_length(lv_obj_t * obj, uint32_t minor_len);

/**
* Set the minimal and maximal values on a scale
Expand Down
4 changes: 2 additions & 2 deletions tests/src/test_cases/widgets/test_scale.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ void test_scale_total_tick_count(void)
{
lv_obj_t * scale = lv_scale_create(lv_screen_active());

int32_t total_tick_count = 42;
uint32_t total_tick_count = 42;
lv_scale_set_total_tick_count(scale, total_tick_count);

TEST_ASSERT_EQUAL(total_tick_count, lv_scale_get_total_tick_count(scale));
Expand All @@ -321,7 +321,7 @@ void test_scale_major_tick_every(void)
{
lv_obj_t * scale = lv_scale_create(lv_screen_active());

int32_t major_tick_every = 6;
uint32_t major_tick_every = 6;
lv_scale_set_major_tick_every(scale, major_tick_every);

TEST_ASSERT_EQUAL(major_tick_every, lv_scale_get_major_tick_every(scale));
Expand Down

0 comments on commit e994209

Please sign in to comment.