add first widget impression
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
#include "../mainbar.h"
|
||||
#include "main_tile.h"
|
||||
|
||||
static lv_obj_t *main_cont = NULL;
|
||||
static lv_obj_t *widget_cont = NULL;
|
||||
static lv_obj_t *clock_cont = NULL;
|
||||
static lv_obj_t *timelabel = NULL;
|
||||
static lv_obj_t *datelabel = NULL;
|
||||
@@ -12,6 +14,8 @@ static lv_obj_t *datelabel = NULL;
|
||||
static lv_style_t timestyle;
|
||||
static lv_style_t datestyle;
|
||||
|
||||
lv_widget_entry_t widget_entry[ MAX_WIDGET_NUM ];
|
||||
|
||||
lv_task_t * task;
|
||||
|
||||
LV_FONT_DECLARE(Ubuntu_72px);
|
||||
@@ -19,6 +23,8 @@ LV_FONT_DECLARE(Ubuntu_16px);
|
||||
|
||||
void main_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres ) {
|
||||
|
||||
main_cont = tile;
|
||||
|
||||
lv_style_copy( ×tyle, style);
|
||||
lv_style_set_text_font( ×tyle, LV_STATE_DEFAULT, &Ubuntu_72px);
|
||||
|
||||
@@ -55,9 +61,34 @@ void main_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coo
|
||||
lv_label_set_text( datelabel, buf );
|
||||
lv_obj_align( datelabel, timelabel, LV_ALIGN_OUT_BOTTOM_MID, 0, 0 );
|
||||
|
||||
for ( int widget = 0 ; widget < MAX_WIDGET_NUM ; widget++ ) {
|
||||
widget_entry[ widget ].widget = lv_obj_create( main_cont, NULL );
|
||||
widget_entry[ widget ].active = false;
|
||||
widget_entry[ widget ].x = 0;
|
||||
widget_entry[ widget ].y = 0;
|
||||
lv_obj_reset_style_list( widget_entry[ widget ].widget, LV_OBJ_PART_MAIN );
|
||||
lv_obj_add_style( widget_entry[ widget ].widget, LV_OBJ_PART_MAIN, style );
|
||||
lv_obj_set_size( widget_entry[ widget ].widget, 64, 64 );
|
||||
lv_obj_set_hidden( widget_entry[ widget ].widget, true );
|
||||
}
|
||||
|
||||
task = lv_task_create( main_tile_task, 1000, LV_TASK_PRIO_MID, NULL );
|
||||
}
|
||||
|
||||
lv_obj_t *main_tile_register_widget( void ) {
|
||||
for( int widget = 0 ; widget < MAX_WIDGET_NUM ; widget++ ) {
|
||||
if ( widget_entry[ widget ].active == false ) {
|
||||
widget_entry[ widget ].active = true;
|
||||
lv_obj_align( clock_cont, main_cont, LV_ALIGN_IN_TOP_MID, 0, 0 );
|
||||
lv_obj_align( widget_entry[ widget ].widget , main_cont, LV_ALIGN_IN_BOTTOM_MID, 0, -32 );
|
||||
lv_obj_set_hidden( widget_entry[ widget ].widget, false );
|
||||
Serial.printf("register widget on main tile\r\n" );
|
||||
return( widget_entry[ widget ].widget );
|
||||
}
|
||||
}
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -3,7 +3,17 @@
|
||||
|
||||
#include <TTGO.h>
|
||||
|
||||
#define MAX_WIDGET_NUM 3
|
||||
|
||||
typedef struct {
|
||||
lv_obj_t *widget;
|
||||
lv_coord_t x;
|
||||
lv_coord_t y;
|
||||
bool active;
|
||||
} lv_widget_entry_t;
|
||||
|
||||
void main_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres );
|
||||
void main_tile_task( lv_task_t * task );
|
||||
lv_obj_t *main_tile_register_widget( void );
|
||||
|
||||
#endif // _MAIL_TILE_H
|
||||
@@ -20,17 +20,21 @@ static lv_obj_t *mainbar = NULL;
|
||||
static lv_point_t valid_pos[ TILE_NUM ];
|
||||
|
||||
lv_tile_entry_t tile_entry[ TILE_NUM ] {
|
||||
{ NULL, MAIN_TILE, main_tile_setup, { 0 , 0 } },
|
||||
{ NULL, APP_TILE, app_tile_setup, { 1 , 0 } },
|
||||
{ NULL, NOTE_TILE, note_tile_setup, { 0 , 1 } },
|
||||
{ NULL, SETUP_TILE, setup_tile_setup, { 1 , 1 } },
|
||||
{ NULL, WLAN_SETTINGS_TILE, wlan_settings_tile_setup, { 0,4 } },
|
||||
{ NULL, WLAN_PASSWORD_TILE, wlan_password_tile_setup, { 0,5 } },
|
||||
{ NULL, MOVE_SETTINGS_TILE, move_settings_tile_setup, { 2,4 } },
|
||||
{ NULL, DISPLAY_SETTINGS_TILE, display_settings_tile_setup, { 4,4 } },
|
||||
{ NULL, BATTERY_SETTINGS_TILE, battery_settings_tile_setup, { 6,4 } },
|
||||
{ NULL, TIME_SETTINGS_TILE, time_settings_tile_setup, { 8,4 } },
|
||||
{ NULL, UPDATE_SETTINGS_TILE, update_tile_setup, { 10,4 } }
|
||||
{ NULL, TILE_TYPE_MAIN_TILE, MAIN_TILE, main_tile_setup, { 0 , 0 } },
|
||||
{ NULL, TILE_TYPE_APP_TILE, APP_TILE, app_tile_setup, { 1 , 0 } },
|
||||
{ NULL, TILE_TYPE_NOTE_TILE, NOTE_TILE, note_tile_setup, { 0 , 1 } },
|
||||
{ NULL, TILE_TYPE_SETUP_TILE, SETUP_TILE, setup_tile_setup, { 1 , 1 } },
|
||||
{ NULL, TILE_TYPE_SETUP, WLAN_SETTINGS_TILE, wlan_settings_tile_setup, { 0,3 } },
|
||||
{ NULL, TILE_TYPE_SETUP, WLAN_PASSWORD_TILE, wlan_password_tile_setup, { 0,4 } },
|
||||
{ NULL, TILE_TYPE_SETUP, MOVE_SETTINGS_TILE, move_settings_tile_setup, { 2,3 } },
|
||||
{ NULL, TILE_TYPE_SETUP, DISPLAY_SETTINGS_TILE, display_settings_tile_setup, { 4,3 } },
|
||||
{ NULL, TILE_TYPE_SETUP, BATTERY_SETTINGS_TILE, battery_settings_tile_setup, { 6,3 } },
|
||||
{ NULL, TILE_TYPE_SETUP, TIME_SETTINGS_TILE, time_settings_tile_setup, { 8,3 } },
|
||||
{ NULL, TILE_TYPE_SETUP, UPDATE_SETTINGS_TILE, update_tile_setup, { 10,3 } },
|
||||
{ NULL, TILE_TYPE_WIDGET_TILE, WIDGET1_1_TILE, NULL, { 12,3 } },
|
||||
{ NULL, TILE_TYPE_WIDGET_SETUP, WIDGET1_2_TILE, NULL, { 12,4 } },
|
||||
{ NULL, TILE_TYPE_WIDGET_TILE, WIDGET2_1_TILE, NULL, { 14,3 } },
|
||||
{ NULL, TILE_TYPE_WIDGET_SETUP, WIDGET2_2_TILE, NULL, { 14,4 } }
|
||||
};
|
||||
|
||||
void mainbar_setup( void ) {
|
||||
@@ -64,14 +68,42 @@ void mainbar_setup( void ) {
|
||||
mainbar_jump_to_maintile( LV_ANIM_OFF );
|
||||
}
|
||||
|
||||
lv_obj_t * mainbar_get_tile_obj( lv_tile_number tile_number ) {
|
||||
if ( tile_number < TILE_NUM ) {
|
||||
for ( int tile = 0 ; tile < TILE_NUM; tile++ ) {
|
||||
if ( tile_entry[ tile ].tile_number == tile_number ) {
|
||||
return( tile_entry[ tile ].tile );
|
||||
}
|
||||
}
|
||||
}
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
lv_tile_number mainbar_get_next_free_tile( lv_tile_type tile_type ) {
|
||||
for ( int tile = 0 ; tile < TILE_NUM; tile++ ) {
|
||||
if ( tile_entry[ tile ].tile_type == tile_type && tile_entry[ tile ].tilecallback == NULL ) {
|
||||
return( tile_entry[ tile ].tile_number );
|
||||
}
|
||||
}
|
||||
return( NO_TILE );
|
||||
}
|
||||
|
||||
void mainbar_set_tile_setup_cb( lv_tile_number tile_number, TILE_CALLBACK_FUNC callback ) {
|
||||
if ( tile_number < TILE_NUM ) {
|
||||
tile_entry[ tile_number ].tilecallback = callback;
|
||||
tile_entry[ tile_number ].tilecallback( tile_entry[ tile_number ].tile, &mainbarstyle, LV_HOR_RES , LV_VER_RES );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void mainbar_jump_to_tile( lv_coord_t x, lv_coord_t y, lv_anim_enable_t anim ) {
|
||||
lv_tileview_set_tile_act(mainbar, x, y, anim );
|
||||
lv_tileview_set_tile_act( mainbar, x, y, anim );
|
||||
}
|
||||
|
||||
void mainbar_jump_to_tilenumber( lv_tile_number tile_number, lv_anim_enable_t anim ) {
|
||||
for ( int tile = 0 ; tile < TILE_NUM; tile++ ) {
|
||||
if ( tile_entry[ tile ].tile_number == tile_number ) {
|
||||
lv_tileview_set_tile_act(mainbar, tile_entry[ tile ].pos.x, tile_entry[ tile ].pos.y, anim );
|
||||
lv_tileview_set_tile_act( mainbar, tile_entry[ tile ].pos.x, tile_entry[ tile ].pos.y, anim );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,18 @@
|
||||
typedef void ( * TILE_CALLBACK_FUNC ) ( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres );
|
||||
|
||||
typedef enum {
|
||||
TILE_TYPE_MAIN_TILE,
|
||||
TILE_TYPE_APP_TILE,
|
||||
TILE_TYPE_NOTE_TILE,
|
||||
TILE_TYPE_SETUP_TILE,
|
||||
TILE_TYPE_SETUP,
|
||||
TILE_TYPE_WIDGET_TILE,
|
||||
TILE_TYPE_WIDGET_SETUP,
|
||||
TILE_TYPE_NUM
|
||||
} lv_tile_type;
|
||||
|
||||
typedef enum {
|
||||
NO_TILE = -1,
|
||||
MAIN_TILE,
|
||||
SETUP_TILE,
|
||||
NOTE_TILE,
|
||||
@@ -17,11 +29,16 @@
|
||||
BATTERY_SETTINGS_TILE,
|
||||
TIME_SETTINGS_TILE,
|
||||
UPDATE_SETTINGS_TILE,
|
||||
WIDGET1_1_TILE,
|
||||
WIDGET1_2_TILE,
|
||||
WIDGET2_1_TILE,
|
||||
WIDGET2_2_TILE,
|
||||
TILE_NUM
|
||||
} lv_tile_number;
|
||||
|
||||
typedef struct {
|
||||
lv_obj_t *tile;
|
||||
lv_tile_type tile_type;
|
||||
lv_tile_number tile_number;
|
||||
TILE_CALLBACK_FUNC tilecallback;
|
||||
lv_point_t pos;
|
||||
@@ -50,5 +67,9 @@
|
||||
*/
|
||||
void mainbar_jump_to_maintile( lv_anim_enable_t anim );
|
||||
|
||||
lv_obj_t * mainbar_get_tile_obj( lv_tile_number tile_number );
|
||||
lv_tile_number mainbar_get_next_free_tile( lv_tile_type tile_type );
|
||||
void mainbar_set_tile_setup_cb( lv_tile_number tile_number, TILE_CALLBACK_FUNC callback );
|
||||
|
||||
|
||||
#endif // _MAINBAR_H
|
||||
Reference in New Issue
Block a user