Add tab and tabview

This commit is contained in:
fvanroie 2021-04-27 02:52:41 +02:00
parent 4a4f410303
commit ba7528d7e6
4 changed files with 29 additions and 10 deletions

View File

@ -1310,8 +1310,6 @@ static void hasp_process_obj_attribute_txt(lv_obj_t* obj, const char* attr, cons
bool hasp_process_obj_attribute_val(lv_obj_t* obj, const char* attr, int16_t intval, bool boolval, bool update)
{
// int16_t intval = atoi(payload);
if(check_obj_type(obj, LV_HASP_BUTTON)) {
if(lv_btn_get_checkable(obj)) {
if(update) {
@ -1348,6 +1346,8 @@ bool hasp_process_obj_attribute_val(lv_obj_t* obj, const char* attr, int16_t int
lv_roller_set_selected(obj, (uint16_t)intval, LV_ANIM_ON);
} else if(check_obj_type(obj, LV_HASP_BAR)) {
update ? lv_bar_set_value(obj, intval, LV_ANIM_ON) : attr_out_int(obj, attr, lv_bar_get_value(obj));
} else if(check_obj_type(obj, LV_HASP_TABVIEW)) {
update ? lv_tabview_set_tab_act(obj, intval, LV_ANIM_ON) : attr_out_int(obj, attr, lv_tabview_get_tab_act(obj));
} else {
return false;
}

View File

@ -25,6 +25,8 @@
#include "hasp_conf.h"
#include "hasplib.h"
#include "lv_core/lv_obj.h" // for tabview ext
static lv_style_int_t last_value_sent;
static lv_color_t last_color_sent;
@ -420,6 +422,15 @@ void selector_event_handler(lv_obj_t* obj, lv_event_t event)
lv_roller_get_selected_str(obj, buffer, sizeof(buffer));
break;
case LV_HASP_TABVIEW: {
val = lv_tabview_get_tab_act(obj);
max = lv_tabview_get_tab_count(obj) - 1;
lv_tabview_ext_t* ext = (lv_tabview_ext_t*)lv_obj_get_ext_attr(obj);
strcpy(buffer, ext->tab_name_ptr[val]);
break;
}
case LV_HASP_TABLE: {
uint16_t row;
uint16_t col;

View File

@ -560,18 +560,25 @@ void hasp_new_object(const JsonObject& config, uint8_t& saved_page_id)
obj = lv_tabview_create(parent_obj, NULL);
// No event handler for tabs
if(obj) {
lv_obj_t* tab;
tab = lv_tabview_add_tab(obj, "tab 1");
// lv_obj_set_user_data(tab, id + 1);
tab = lv_tabview_add_tab(obj, "tab 2");
// lv_obj_set_user_data(tab, id + 2);
tab = lv_tabview_add_tab(obj, "tab 3");
// lv_obj_set_user_data(tab, id + 3);
lv_obj_set_event_cb(obj, selector_event_handler);
obj->user_data.objid = LV_HASP_TABVIEW;
}
break;
case LV_HASP_TAB:
case HASP_OBJ_TAB:
if(parent_obj && parent_obj->user_data.objid == LV_HASP_TABVIEW) {
obj = lv_tabview_add_tab(parent_obj, "Tab");
if(obj) {
lv_obj_set_event_cb(obj, generic_event_handler);
obj->user_data.objid = LV_HASP_TAB;
}
} else {
LOG_WARNING(TAG_HASP, F("Parent of a tab must be a tabview object"));
return;
}
break;
#endif
/* ----- Color Objects ------ */
case LV_HASP_CPICKER:

View File

@ -110,6 +110,7 @@ void object_set_normalized_group_value(uint8_t groupid, lv_obj_t* src_obj, int16
#define HASP_OBJ_OBJMASK 55395
#define HASP_OBJ_LMETER 62749
#define HASP_OBJ_TABVIEW 63226
#define HASP_OBJ_TAB 7861
#define HASP_OBJ_ARC 64594
#endif