mirror of
https://github.com/lvgl/lvgl.git
synced 2026-06-01 08:54:52 +08:00
feat(tabview): add property interface support
Add property interface for tabview widget: - TAB_ACTIVE, TAB_BAR_POSITION - Add public getter lv_tabview_get_tab_bar_position - Add property test function
This commit is contained in:
@@ -114,6 +114,7 @@ enum _lv_prop_id_range_boundary_t {
|
|||||||
LV_PROPERTY_SPINBOX_START = 0x1100, /* lv_spinbox.c */
|
LV_PROPERTY_SPINBOX_START = 0x1100, /* lv_spinbox.c */
|
||||||
LV_PROPERTY_SPINNER_START = 0x1200, /* lv_spinner.c */
|
LV_PROPERTY_SPINNER_START = 0x1200, /* lv_spinner.c */
|
||||||
LV_PROPERTY_TABLE_START = 0x1300, /* lv_table.c */
|
LV_PROPERTY_TABLE_START = 0x1300, /* lv_table.c */
|
||||||
|
LV_PROPERTY_TABVIEW_START = 0x1400, /* lv_tabview.c */
|
||||||
|
|
||||||
/*Special ID, use it to extend ID and make sure it's unique and compile time determinant*/
|
/*Special ID, use it to extend ID and make sure it's unique and compile time determinant*/
|
||||||
LV_PROPERTY_ID_BUILTIN_LAST = 0xffff, /*ID of 0x10000 ~ 0xfffffff is reserved for user*/
|
LV_PROPERTY_ID_BUILTIN_LAST = 0xffff, /*ID of 0x10000 ~ 0xfffffff is reserved for user*/
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
extern const lv_property_name_t lv_style_property_names[123];
|
extern const lv_property_name_t lv_style_property_names[123];
|
||||||
extern const lv_property_name_t lv_switch_property_names[1];
|
extern const lv_property_name_t lv_switch_property_names[1];
|
||||||
extern const lv_property_name_t lv_table_property_names[2];
|
extern const lv_property_name_t lv_table_property_names[2];
|
||||||
|
extern const lv_property_name_t lv_tabview_property_names[2];
|
||||||
extern const lv_property_name_t lv_textarea_property_names[15];
|
extern const lv_property_name_t lv_textarea_property_names[15];
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
* GENERATED FILE, DO NOT EDIT IT!
|
||||||
|
* @file lv_tabview_properties.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../tabview/lv_tabview.h"
|
||||||
|
|
||||||
|
#if LV_USE_OBJ_PROPERTY && LV_USE_OBJ_PROPERTY_NAME
|
||||||
|
|
||||||
|
#if LV_USE_TABVIEW
|
||||||
|
/**
|
||||||
|
* Tabview widget property names, name must be in order.
|
||||||
|
* Generated code from properties.py
|
||||||
|
*/
|
||||||
|
/* *INDENT-OFF* */
|
||||||
|
const lv_property_name_t lv_tabview_property_names[2] = {
|
||||||
|
{"tab_active", LV_PROPERTY_TABVIEW_TAB_ACTIVE,},
|
||||||
|
{"tab_bar_position", LV_PROPERTY_TABVIEW_TAB_BAR_POSITION,},
|
||||||
|
};
|
||||||
|
#endif /*LV_USE_TABVIEW*/
|
||||||
|
|
||||||
|
/* *INDENT-ON* */
|
||||||
|
#endif
|
||||||
@@ -32,9 +32,32 @@ static void lv_tabview_event(const lv_obj_class_t * class_p, lv_event_t * e);
|
|||||||
static void button_clicked_event_cb(lv_event_t * e);
|
static void button_clicked_event_cb(lv_event_t * e);
|
||||||
static void cont_scroll_end_event_cb(lv_event_t * e);
|
static void cont_scroll_end_event_cb(lv_event_t * e);
|
||||||
|
|
||||||
|
#if LV_USE_OBJ_PROPERTY
|
||||||
|
static void lv_tabview_set_tab_active_property(lv_obj_t * obj, uint32_t idx)
|
||||||
|
{
|
||||||
|
lv_tabview_set_active(obj, idx, LV_ANIM_OFF);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC VARIABLES
|
* STATIC VARIABLES
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
|
#if LV_USE_OBJ_PROPERTY
|
||||||
|
static const lv_property_ops_t lv_tabview_properties[] = {
|
||||||
|
{
|
||||||
|
.id = LV_PROPERTY_TABVIEW_TAB_ACTIVE,
|
||||||
|
.setter = lv_tabview_set_tab_active_property,
|
||||||
|
.getter = lv_tabview_get_tab_active,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.id = LV_PROPERTY_TABVIEW_TAB_BAR_POSITION,
|
||||||
|
.setter = lv_tabview_set_tab_bar_position,
|
||||||
|
.getter = lv_tabview_get_tab_bar_position,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
const lv_obj_class_t lv_tabview_class = {
|
const lv_obj_class_t lv_tabview_class = {
|
||||||
.constructor_cb = lv_tabview_constructor,
|
.constructor_cb = lv_tabview_constructor,
|
||||||
.event_cb = lv_tabview_event,
|
.event_cb = lv_tabview_event,
|
||||||
@@ -43,6 +66,7 @@ const lv_obj_class_t lv_tabview_class = {
|
|||||||
.base_class = &lv_obj_class,
|
.base_class = &lv_obj_class,
|
||||||
.instance_size = sizeof(lv_tabview_t),
|
.instance_size = sizeof(lv_tabview_t),
|
||||||
.name = "lv_tabview",
|
.name = "lv_tabview",
|
||||||
|
LV_PROPERTY_CLASS_FIELDS(tabview, TABVIEW)
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -285,6 +309,13 @@ lv_obj_t * lv_tabview_get_tab_bar(lv_obj_t * tv)
|
|||||||
return lv_obj_get_child(tv, 0);
|
return lv_obj_get_child(tv, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lv_dir_t lv_tabview_get_tab_bar_position(lv_obj_t * obj)
|
||||||
|
{
|
||||||
|
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||||
|
lv_tabview_t * tabview = (lv_tabview_t *)obj;
|
||||||
|
return tabview->tab_pos;
|
||||||
|
}
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC FUNCTIONS
|
* STATIC FUNCTIONS
|
||||||
**********************/
|
**********************/
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ extern "C" {
|
|||||||
*********************/
|
*********************/
|
||||||
#include "../../lv_conf_internal.h"
|
#include "../../lv_conf_internal.h"
|
||||||
#include "../../core/lv_obj.h"
|
#include "../../core/lv_obj.h"
|
||||||
|
#include "../../core/lv_obj_property.h"
|
||||||
|
|
||||||
#if LV_USE_TABVIEW
|
#if LV_USE_TABVIEW
|
||||||
|
|
||||||
@@ -24,6 +25,14 @@ extern "C" {
|
|||||||
|
|
||||||
LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_tabview_class;
|
LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_tabview_class;
|
||||||
|
|
||||||
|
#if LV_USE_OBJ_PROPERTY
|
||||||
|
enum _lv_property_tabview_id_t {
|
||||||
|
LV_PROPERTY_ID(TABVIEW, TAB_ACTIVE, LV_PROPERTY_TYPE_INT, 0),
|
||||||
|
LV_PROPERTY_ID(TABVIEW, TAB_BAR_POSITION, LV_PROPERTY_TYPE_INT, 1),
|
||||||
|
LV_PROPERTY_TABVIEW_END,
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* GLOBAL PROTOTYPES
|
* GLOBAL PROTOTYPES
|
||||||
**********************/
|
**********************/
|
||||||
@@ -123,6 +132,13 @@ lv_obj_t * lv_tabview_get_content(lv_obj_t * obj);
|
|||||||
*/
|
*/
|
||||||
lv_obj_t * lv_tabview_get_tab_bar(lv_obj_t * obj);
|
lv_obj_t * lv_tabview_get_tab_bar(lv_obj_t * obj);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the position of the tab bar
|
||||||
|
* @param obj pointer to a tabview widget
|
||||||
|
* @return LV_DIR_TOP/BOTTOM/LEFT/RIGHT
|
||||||
|
*/
|
||||||
|
lv_dir_t lv_tabview_get_tab_bar_position(lv_obj_t * obj);
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* MACROS
|
* MACROS
|
||||||
**********************/
|
**********************/
|
||||||
|
|||||||
@@ -332,4 +332,38 @@ void test_tabview_setting_tab_bar_position_after_size_should_result_in_the_same_
|
|||||||
TEST_ASSERT_EQUAL_SCREENSHOT("widgets/tabview_11.png");
|
TEST_ASSERT_EQUAL_SCREENSHOT("widgets/tabview_11.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_tabview_properties(void)
|
||||||
|
{
|
||||||
|
#if LV_USE_OBJ_PROPERTY
|
||||||
|
lv_obj_t * tv = lv_tabview_create(lv_screen_active());
|
||||||
|
lv_tabview_add_tab(tv, "Tab 1");
|
||||||
|
lv_tabview_add_tab(tv, "Tab 2");
|
||||||
|
lv_tabview_add_tab(tv, "Tab 3");
|
||||||
|
|
||||||
|
lv_property_t prop = { };
|
||||||
|
|
||||||
|
/* Test TAB_ACTIVE property */
|
||||||
|
prop.id = LV_PROPERTY_TABVIEW_TAB_ACTIVE;
|
||||||
|
prop.num = 1;
|
||||||
|
TEST_ASSERT_TRUE(lv_obj_set_property(tv, &prop) == LV_RESULT_OK);
|
||||||
|
TEST_ASSERT_EQUAL_INT(1, lv_obj_get_property(tv, LV_PROPERTY_TABVIEW_TAB_ACTIVE).num);
|
||||||
|
|
||||||
|
prop.num = 2;
|
||||||
|
TEST_ASSERT_TRUE(lv_obj_set_property(tv, &prop) == LV_RESULT_OK);
|
||||||
|
TEST_ASSERT_EQUAL_INT(2, lv_obj_get_property(tv, LV_PROPERTY_TABVIEW_TAB_ACTIVE).num);
|
||||||
|
|
||||||
|
/* Test TAB_BAR_POSITION property */
|
||||||
|
prop.id = LV_PROPERTY_TABVIEW_TAB_BAR_POSITION;
|
||||||
|
prop.num = LV_DIR_BOTTOM;
|
||||||
|
TEST_ASSERT_TRUE(lv_obj_set_property(tv, &prop) == LV_RESULT_OK);
|
||||||
|
TEST_ASSERT_EQUAL_INT(LV_DIR_BOTTOM, lv_obj_get_property(tv, LV_PROPERTY_TABVIEW_TAB_BAR_POSITION).num);
|
||||||
|
|
||||||
|
prop.num = LV_DIR_LEFT;
|
||||||
|
TEST_ASSERT_TRUE(lv_obj_set_property(tv, &prop) == LV_RESULT_OK);
|
||||||
|
TEST_ASSERT_EQUAL_INT(LV_DIR_LEFT, lv_obj_get_property(tv, LV_PROPERTY_TABVIEW_TAB_BAR_POSITION).num);
|
||||||
|
|
||||||
|
lv_obj_delete(tv);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user