mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
feat(bar): add bar orientation (#6212)
Co-authored-by: Gabor Kiss-Vamosi <kisvegabor@gmail.com>
This commit is contained in:
parent
1601ab9eb4
commit
fd9e901625
@ -164,6 +164,15 @@ void lv_bar_set_mode(lv_obj_t * obj, lv_bar_mode_t mode)
|
||||
lv_obj_invalidate(obj);
|
||||
}
|
||||
|
||||
void lv_bar_set_orientation(lv_obj_t * obj, lv_bar_orientation_t orientation)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
lv_bar_t * bar = (lv_bar_t *)obj;
|
||||
|
||||
bar->orientation = orientation;
|
||||
lv_obj_invalidate(obj);
|
||||
}
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
*====================*/
|
||||
@ -209,6 +218,14 @@ lv_bar_mode_t lv_bar_get_mode(lv_obj_t * obj)
|
||||
return bar->mode;
|
||||
}
|
||||
|
||||
lv_bar_orientation_t lv_bar_get_orientation(lv_obj_t * obj)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
lv_bar_t * bar = (lv_bar_t *)obj;
|
||||
|
||||
return bar->orientation;
|
||||
}
|
||||
|
||||
bool lv_bar_is_symmetrical(lv_obj_t * obj)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
@ -237,6 +254,7 @@ static void lv_bar_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
|
||||
bar->indic_area.y1 = 0;
|
||||
bar->indic_area.y2 = 0;
|
||||
bar->mode = LV_BAR_MODE_NORMAL;
|
||||
bar->orientation = LV_BAR_ORIENTATION_AUTO;
|
||||
bar->val_reversed = false;
|
||||
|
||||
lv_bar_init_anim(obj, &bar->cur_value_anim);
|
||||
@ -280,7 +298,20 @@ static void draw_indic(lv_event_t * e)
|
||||
range = 1;
|
||||
}
|
||||
|
||||
bool hor = barw >= barh;
|
||||
bool hor = false;
|
||||
switch(bar->orientation) {
|
||||
case LV_BAR_ORIENTATION_HORIZONTAL:
|
||||
hor = true;
|
||||
break;
|
||||
case LV_BAR_ORIENTATION_VERTICAL:
|
||||
hor = false;
|
||||
break;
|
||||
case LV_BAR_ORIENTATION_AUTO:
|
||||
default:
|
||||
hor = (barw >= barh);
|
||||
break;
|
||||
}
|
||||
|
||||
bool sym = lv_bar_is_symmetrical(obj);
|
||||
|
||||
/*Calculate the indicator area*/
|
||||
@ -304,7 +335,6 @@ static void draw_indic(lv_event_t * e)
|
||||
bar->indic_area.x1 = obj->coords.x1 + (barw / 2) - (LV_BAR_SIZE_MIN / 2);
|
||||
bar->indic_area.x2 = bar->indic_area.x1 + LV_BAR_SIZE_MIN;
|
||||
}
|
||||
|
||||
int32_t indic_max_w = lv_area_get_width(&bar->indic_area);
|
||||
int32_t indic_max_h = lv_area_get_height(&bar->indic_area);
|
||||
|
||||
|
@ -33,13 +33,23 @@ enum _lv_bar_mode_t {
|
||||
LV_BAR_MODE_SYMMETRICAL,
|
||||
LV_BAR_MODE_RANGE
|
||||
};
|
||||
|
||||
#ifdef DOXYGEN
|
||||
typedef _lv_bar_mode_t lv_bar_mode_t;
|
||||
#else
|
||||
typedef uint8_t lv_bar_mode_t;
|
||||
#endif /*DOXYGEN*/
|
||||
|
||||
enum _lv_bar_orientation_t {
|
||||
LV_BAR_ORIENTATION_AUTO,
|
||||
LV_BAR_ORIENTATION_HORIZONTAL,
|
||||
LV_BAR_ORIENTATION_VERTICAL
|
||||
};
|
||||
#ifdef DOXYGEN
|
||||
typedef _lv_bar_orientation_t lv_bar_orientation_t;
|
||||
#else
|
||||
typedef uint8_t lv_bar_orientation_t;
|
||||
#endif /*DOXYGEN*/
|
||||
|
||||
typedef struct {
|
||||
lv_obj_t * bar;
|
||||
int32_t anim_start;
|
||||
@ -58,6 +68,7 @@ typedef struct {
|
||||
_lv_bar_anim_t cur_value_anim;
|
||||
_lv_bar_anim_t start_value_anim;
|
||||
lv_bar_mode_t mode : 2; /**< Type of bar*/
|
||||
lv_bar_orientation_t orientation : 2; /**< Orientation of bar*/
|
||||
} lv_bar_t;
|
||||
|
||||
LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_bar_class;
|
||||
@ -109,6 +120,13 @@ void lv_bar_set_range(lv_obj_t * obj, int32_t min, int32_t max);
|
||||
*/
|
||||
void lv_bar_set_mode(lv_obj_t * obj, lv_bar_mode_t mode);
|
||||
|
||||
/**
|
||||
* Set the orientation of bar.
|
||||
* @param obj pointer to bar object
|
||||
* @param orientation bar orientation from `lv_bar_orientation_t`
|
||||
*/
|
||||
void lv_bar_set_orientation(lv_obj_t * obj, lv_bar_orientation_t orientation);
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
*====================*/
|
||||
@ -148,6 +166,13 @@ int32_t lv_bar_get_max_value(const lv_obj_t * obj);
|
||||
*/
|
||||
lv_bar_mode_t lv_bar_get_mode(lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Get the orientation of bar.
|
||||
* @param obj pointer to bar object
|
||||
* @return bar orientation from ::lv_bar_orientation_t
|
||||
*/
|
||||
lv_bar_orientation_t lv_bar_get_orientation(lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Give the bar is in symmetrical mode or not
|
||||
* @param obj pointer to bar object
|
||||
|
BIN
tests/ref_imgs/widgets/bar_2.png
Normal file
BIN
tests/ref_imgs/widgets/bar_2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
@ -16,6 +16,7 @@ void setUp(void)
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
lv_obj_clean(g_active_screen);
|
||||
}
|
||||
|
||||
void test_bar_should_have_valid_default_attributes(void)
|
||||
@ -399,4 +400,51 @@ void test_bar_render_corner(void)
|
||||
render_test_screen_create(true, LV_GRAD_DIR_VER, "widgets/bar_corner_6.png");
|
||||
}
|
||||
|
||||
|
||||
static lv_obj_t * bar_create_orientation(lv_bar_orientation_t orientation, int32_t w, int32_t h)
|
||||
{
|
||||
lv_obj_t * bar = lv_bar_create(g_active_screen);
|
||||
lv_bar_set_orientation(bar, orientation);
|
||||
lv_obj_set_size(bar, w, h);
|
||||
lv_bar_set_value(bar, 30, LV_ANIM_OFF);
|
||||
|
||||
return bar;
|
||||
|
||||
}
|
||||
|
||||
void test_bar_orientation(void)
|
||||
{
|
||||
lv_obj_clean(g_active_screen);
|
||||
|
||||
lv_obj_set_flex_flow(g_active_screen, LV_FLEX_FLOW_ROW_WRAP);
|
||||
|
||||
lv_obj_t * label;
|
||||
|
||||
label = lv_label_create(g_active_screen);
|
||||
lv_label_set_text(label, "Auto");
|
||||
lv_obj_set_width(label, lv_pct(100));
|
||||
|
||||
bar_create_orientation(LV_BAR_ORIENTATION_AUTO, 100, 20);
|
||||
bar_create_orientation(LV_BAR_ORIENTATION_AUTO, 20, 100);
|
||||
bar_create_orientation(LV_BAR_ORIENTATION_AUTO, 100, 100);
|
||||
|
||||
label = lv_label_create(g_active_screen);
|
||||
lv_label_set_text(label, "Vertical");
|
||||
lv_obj_set_width(label, lv_pct(100));
|
||||
|
||||
bar_create_orientation(LV_BAR_ORIENTATION_VERTICAL, 100, 20);
|
||||
bar_create_orientation(LV_BAR_ORIENTATION_VERTICAL, 20, 100);
|
||||
bar_create_orientation(LV_BAR_ORIENTATION_VERTICAL, 100, 100);
|
||||
|
||||
label = lv_label_create(g_active_screen);
|
||||
lv_label_set_text(label, "Horizontal");
|
||||
lv_obj_set_width(label, lv_pct(100));
|
||||
|
||||
bar_create_orientation(LV_BAR_ORIENTATION_HORIZONTAL, 100, 20);
|
||||
bar_create_orientation(LV_BAR_ORIENTATION_HORIZONTAL, 20, 100);
|
||||
bar_create_orientation(LV_BAR_ORIENTATION_HORIZONTAL, 100, 100);
|
||||
|
||||
TEST_ASSERT_EQUAL_SCREENSHOT("widgets/bar_2.png");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user