Skip to content

Commit

Permalink
update button style
Browse files Browse the repository at this point in the history
  • Loading branch information
sharandac committed Sep 8, 2020
1 parent 92f9819 commit 78fab62
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 124 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,12 @@ Special thanks to the following people for their help:
[bwagstaff](https://github.com/bwagstaff)<br>
[chrismcna](https://github.com/chrismcna)<br>
[datacute](https://github.com/datacute)<br>
[jakub-vesely](https://github.com/jakub-vesely)<br>
[joshvito](https://github.com/joshvito)<br>
[JoanMCD](https://github.com/JoanMCD)<br>
[NorthernDIY](https://github.com/NorthernDIY)<br>
[rnisthal](https://github.com/rnisthal)<br>
[paulstueber](https://github.com/paulstueber)<br>

and the following projects:

Expand All @@ -92,6 +95,7 @@ and the following projects:
[LVGL](https://github.com/lvgl)<br>
[TFT_eSPI](https://github.com/Bodmer/TFT_eSPI)<br>
[TTGO_TWatch_Library](https://github.com/Xinyuan-LilyGO/TTGO_TWatch_Library)<br>
[ESP8266Audio](https://github.com/earlephilhower/ESP8266Audio)<br>

Every Contribution to this repository is highly welcome! Don't fear to create pull requests which enhance or fix the project, you are going to help everybody.
<p>
Expand Down
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ lib_deps =
ESP32SSPD@>=1.1.0
IRremoteESP8266@>=2.7.10
; this specific commit of ESP8266Audio is required to work. See: https://github.com/Xinyuan-LilyGO/TTGO_TWatch_Library/issues/17
https://github.com/earlephilhower/ESP8266Audio#22b52e0ed5aa86a5e5704c5c86d435c8e3e233a0
https://github.com/earlephilhower/ESP8266Audio#22b52e0ed5aa86a5e5704c5c86d435c8e3e233a0
75 changes: 40 additions & 35 deletions src/app/IRController/IRController_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ void IRController_main_setup( uint32_t tile_num ) {
lv_style_copy( &IRController_main_style, mainbar_get_style() );

lv_obj_t * exit_btn = lv_imgbtn_create( IRController_main_tile, NULL);
lv_imgbtn_set_src(exit_btn, LV_BTN_STATE_RELEASED, &exit_32px);
lv_imgbtn_set_src(exit_btn, LV_BTN_STATE_PRESSED, &exit_32px);
lv_imgbtn_set_src(exit_btn, LV_BTN_STATE_CHECKED_RELEASED, &exit_32px);
lv_imgbtn_set_src(exit_btn, LV_BTN_STATE_CHECKED_PRESSED, &exit_32px);
lv_obj_add_style(exit_btn, LV_IMGBTN_PART_MAIN, &IRController_main_style );
lv_obj_align(exit_btn, IRController_main_tile, LV_ALIGN_IN_BOTTOM_LEFT, 10, -10 );
lv_imgbtn_set_src( exit_btn, LV_BTN_STATE_RELEASED, &exit_32px );
lv_imgbtn_set_src( exit_btn, LV_BTN_STATE_PRESSED, &exit_32px );
lv_imgbtn_set_src( exit_btn, LV_BTN_STATE_CHECKED_RELEASED, &exit_32px );
lv_imgbtn_set_src( exit_btn, LV_BTN_STATE_CHECKED_PRESSED, &exit_32px );
lv_obj_add_style( exit_btn, LV_IMGBTN_PART_MAIN, &IRController_main_style );
lv_obj_align( exit_btn, IRController_main_tile, LV_ALIGN_IN_BOTTOM_LEFT, 10, -10 );
lv_obj_set_event_cb( exit_btn, exit_IRController_main_event_cb );

/*//No use for this just yet
Expand All @@ -109,62 +109,67 @@ void IRController_main_setup( uint32_t tile_num ) {

//Top Left, power button
lv_obj_t *IRController_main_pwr_btn = NULL;
IRController_main_pwr_btn = lv_btn_create(IRController_main_tile, NULL);
lv_obj_set_size(IRController_main_pwr_btn, 70, 40);
IRController_main_pwr_btn = lv_btn_create( IRController_main_tile, NULL);
lv_obj_set_size( IRController_main_pwr_btn, 70, 40);
lv_obj_set_event_cb( IRController_main_pwr_btn, pwr_IRController_main_event_cb );
lv_obj_align(IRController_main_pwr_btn, NULL, LV_ALIGN_CENTER, -80, -90 );
lv_obj_t *IRController_main_pwr_label = lv_label_create(IRController_main_pwr_btn, NULL);
lv_label_set_text(IRController_main_pwr_label, "Power");
lv_obj_add_style( IRController_main_pwr_btn, LV_BTN_PART_MAIN, mainbar_get_button_style() );
lv_obj_align( IRController_main_pwr_btn, NULL, LV_ALIGN_CENTER, -80, -90 );
lv_obj_t *IRController_main_pwr_label = lv_label_create( IRController_main_pwr_btn, NULL);
lv_label_set_text( IRController_main_pwr_label, "Power");

//Middle Left, mute button
lv_obj_t *IRController_main_mute_btn = NULL;
IRController_main_mute_btn = lv_btn_create(IRController_main_tile, NULL);
IRController_main_mute_btn = lv_btn_create( IRController_main_tile, NULL);
lv_obj_set_event_cb( IRController_main_mute_btn, mute_IRController_main_event_cb );
lv_obj_set_size(IRController_main_mute_btn, 70, 40);
lv_obj_align(IRController_main_mute_btn, NULL, LV_ALIGN_CENTER, -80, -30 );
lv_obj_t *IRController_main_mute_label = lv_label_create(IRController_main_mute_btn, NULL);
lv_label_set_text(IRController_main_mute_label, "Mute");
lv_obj_set_size( IRController_main_mute_btn, 70, 40);
lv_obj_add_style( IRController_main_mute_btn, LV_BTN_PART_MAIN, mainbar_get_button_style() );
lv_obj_align( IRController_main_mute_btn, NULL, LV_ALIGN_CENTER, -80, -30 );
lv_obj_t *IRController_main_mute_label = lv_label_create( IRController_main_mute_btn, NULL);
lv_label_set_text( IRController_main_mute_label, "Mute");

//Bottom Left, Source button
lv_obj_t *IRController_main_source_btn = NULL;
IRController_main_source_btn = lv_btn_create(IRController_main_tile, NULL);
IRController_main_source_btn = lv_btn_create( IRController_main_tile, NULL);
lv_obj_set_event_cb( IRController_main_source_btn, source_IRController_main_event_cb );
lv_obj_set_size(IRController_main_source_btn, 70, 40);
lv_obj_align(IRController_main_source_btn, NULL, LV_ALIGN_CENTER, -80, 30 );
lv_obj_t *IRController_main_source_label = lv_label_create(IRController_main_source_btn, NULL);
lv_label_set_text(IRController_main_source_label, "Source");
lv_obj_set_size( IRController_main_source_btn, 70, 40);
lv_obj_add_style( IRController_main_source_btn, LV_BTN_PART_MAIN, mainbar_get_button_style() );
lv_obj_align( IRController_main_source_btn, NULL, LV_ALIGN_CENTER, -80, 30 );
lv_obj_t *IRController_main_source_label = lv_label_create( IRController_main_source_btn, NULL);
lv_label_set_text( IRController_main_source_label, "Source");

//Top Right, Volume + button
lv_obj_t *IRController_main_volup_btn = NULL;
IRController_main_volup_btn = lv_btn_create(IRController_main_tile, NULL);
IRController_main_volup_btn = lv_btn_create( IRController_main_tile, NULL);
lv_obj_set_event_cb( IRController_main_volup_btn, volup_IRController_main_event_cb );
lv_obj_set_size(IRController_main_volup_btn, 70, 40);
lv_obj_align(IRController_main_volup_btn, NULL, LV_ALIGN_CENTER, 10, -90 );
lv_obj_set_size( IRController_main_volup_btn, 70, 40);
lv_obj_add_style( IRController_main_volup_btn, LV_BTN_PART_MAIN, mainbar_get_button_style() );
lv_obj_align( IRController_main_volup_btn, NULL, LV_ALIGN_CENTER, 10, -90 );
lv_obj_t *IRController_main_volup_label = lv_label_create(IRController_main_volup_btn, NULL);
lv_label_set_text(IRController_main_volup_label, "Vol +");
lv_label_set_text( IRController_main_volup_label, "Vol +");

//Middle Right, Volume - button
lv_obj_t *IRController_main_voldn_btn = NULL;
IRController_main_voldn_btn = lv_btn_create(IRController_main_tile, NULL);
IRController_main_voldn_btn = lv_btn_create( IRController_main_tile, NULL);
lv_obj_set_event_cb( IRController_main_voldn_btn, voldn_IRController_main_event_cb );
lv_obj_set_size(IRController_main_voldn_btn, 70, 40);
lv_obj_align(IRController_main_voldn_btn, NULL, LV_ALIGN_CENTER, 10, -30 );
lv_obj_t *IRController_main_voldn_label = lv_label_create(IRController_main_voldn_btn, NULL);
lv_label_set_text(IRController_main_voldn_label, "Vol -");
lv_obj_set_size( IRController_main_voldn_btn, 70, 40);
lv_obj_add_style( IRController_main_voldn_btn, LV_BTN_PART_MAIN, mainbar_get_button_style() );
lv_obj_align( IRController_main_voldn_btn, NULL, LV_ALIGN_CENTER, 10, -30 );
lv_obj_t *IRController_main_voldn_label = lv_label_create( IRController_main_voldn_btn, NULL);
lv_label_set_text( IRController_main_voldn_label, "Vol -");

//Bottom Right, Exit menu button (This is exit for the TV, not the app)
lv_obj_t *IRController_main_rExit_btn = NULL;
IRController_main_rExit_btn = lv_btn_create(IRController_main_tile, NULL);
IRController_main_rExit_btn = lv_btn_create( IRController_main_tile, NULL);
lv_obj_set_event_cb( IRController_main_rExit_btn, rExit_IRController_main_event_cb );
lv_obj_set_size(IRController_main_rExit_btn, 70, 40);
lv_obj_set_size( IRController_main_rExit_btn, 70, 40);
lv_obj_add_style( IRController_main_rExit_btn, LV_BTN_PART_MAIN, mainbar_get_button_style() );
lv_obj_align(IRController_main_rExit_btn, NULL, LV_ALIGN_CENTER, 10, 30 );
lv_obj_t *IRController_main_rExit_label = lv_label_create(IRController_main_rExit_btn, NULL);
lv_label_set_text(IRController_main_rExit_label, "Exit");
lv_obj_t *IRController_main_rExit_label = lv_label_create( IRController_main_rExit_btn, NULL);
lv_label_set_text( IRController_main_rExit_label, "Exit");

pinMode(13, OUTPUT);
digitalWrite(13, LOW); //No Current Limiting so keep it off


lv_style_set_text_opa( &IRController_main_style, LV_OBJ_PART_MAIN, LV_OPA_70);
lv_style_set_text_font( &IRController_main_style, LV_STATE_DEFAULT, &Ubuntu_32px);
lv_obj_t *app_label = lv_label_create( IRController_main_tile, NULL);
Expand Down
2 changes: 1 addition & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
/*
* firmeware version string
*/
#define __FIRMWARE__ "2020090801"
#define __FIRMWARE__ "2020090803"

#endif // _CONFIG_H
33 changes: 22 additions & 11 deletions src/gui/mainbar/mainbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

static lv_style_t mainbar_style;
static lv_style_t mainbar_switch_style;
static lv_style_t mainbar_button_style;
static lv_style_t mainbar_slider_style;

static lv_obj_t *mainbar = NULL;
Expand All @@ -51,24 +52,30 @@ static uint32_t app_tile_pos = MAINBAR_APP_TILE_X_START;

void mainbar_setup( void ) {
lv_style_init( &mainbar_style );
lv_style_set_radius(&mainbar_style, LV_OBJ_PART_MAIN, 0);
lv_style_set_bg_color(&mainbar_style, LV_OBJ_PART_MAIN, LV_COLOR_GRAY);
lv_style_set_bg_opa(&mainbar_style, LV_OBJ_PART_MAIN, LV_OPA_0);
lv_style_set_border_width(&mainbar_style, LV_OBJ_PART_MAIN, 0);
lv_style_set_text_color(&mainbar_style, LV_OBJ_PART_MAIN, LV_COLOR_WHITE);
lv_style_set_image_recolor(&mainbar_style, LV_OBJ_PART_MAIN, LV_COLOR_WHITE);

lv_style_init( &mainbar_switch_style );
lv_style_set_radius( &mainbar_style, LV_OBJ_PART_MAIN, 0 );
lv_style_set_bg_color( &mainbar_style, LV_OBJ_PART_MAIN, LV_COLOR_GRAY );
lv_style_set_bg_opa( &mainbar_style, LV_OBJ_PART_MAIN, LV_OPA_0 );
lv_style_set_border_width( &mainbar_style, LV_OBJ_PART_MAIN, 0 );
lv_style_set_text_color( &mainbar_style, LV_OBJ_PART_MAIN, LV_COLOR_WHITE );
lv_style_set_image_recolor( &mainbar_style, LV_OBJ_PART_MAIN, LV_COLOR_WHITE );

lv_style_init( &mainbar_switch_style );
lv_style_set_bg_color( &mainbar_switch_style, LV_STATE_CHECKED, LV_COLOR_GREEN );

lv_style_init( &mainbar_slider_style );
lv_style_init( &mainbar_slider_style );
lv_style_set_bg_color( &mainbar_slider_style, LV_STATE_DEFAULT, LV_COLOR_GREEN );

lv_style_init( &mainbar_button_style );
lv_style_set_radius( &mainbar_button_style, LV_STATE_DEFAULT, 3 );
lv_style_set_border_color( &mainbar_button_style, LV_STATE_DEFAULT, LV_COLOR_WHITE );
lv_style_set_border_opa( &mainbar_button_style, LV_STATE_DEFAULT, LV_OPA_70 );
lv_style_set_border_width( &mainbar_button_style, LV_STATE_DEFAULT, 2 );

mainbar = lv_tileview_create( lv_scr_act(), NULL);
lv_tileview_set_valid_positions(mainbar, tile_pos_table, tile_entrys );
lv_tileview_set_valid_positions( mainbar, tile_pos_table, tile_entrys );
lv_tileview_set_edge_flash( mainbar, false);
lv_obj_add_style( mainbar, LV_OBJ_PART_MAIN, &mainbar_style );
lv_page_set_scrlbar_mode(mainbar, LV_SCRLBAR_MODE_OFF);
lv_page_set_scrlbar_mode( mainbar, LV_SCRLBAR_MODE_OFF);
}

uint32_t mainbar_add_tile( uint16_t x, uint16_t y ) {
Expand Down Expand Up @@ -132,6 +139,10 @@ lv_style_t *mainbar_get_switch_style( void ) {
return( &mainbar_switch_style );
}

lv_style_t *mainbar_get_button_style( void ) {
return( &mainbar_button_style );
}

lv_style_t *mainbar_get_slider_style( void ) {
return( &mainbar_slider_style );
}
Expand Down
10 changes: 8 additions & 2 deletions src/gui/mainbar/mainbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,19 @@
* @return pointer to the v_style_t object
*/
lv_style_t *mainbar_get_slider_style( void );
/*
* @brief get main tile button style
*
* @return pointer to the v_style_t object
*/
lv_style_t *mainbar_get_button_style( void );
/*
* @brief
*/
lv_obj_t *mainbar_obj_create(lv_obj_t *parent);
lv_obj_t *mainbar_obj_create( lv_obj_t *parent );
/*
* @brief
*/
void mainbar_add_slide_element(lv_obj_t *element);
void mainbar_add_slide_element( lv_obj_t *element );

#endif // _MAINBAR_H
1 change: 1 addition & 0 deletions src/gui/mainbar/setup_tile/update/update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ void update_tile_setup( void ) {

update_btn = lv_btn_create( update_settings_tile, NULL);
lv_obj_set_event_cb( update_btn, update_event_handler );
lv_obj_add_style( update_btn, LV_BTN_PART_MAIN, mainbar_get_button_style() );
lv_obj_align( update_btn, NULL, LV_ALIGN_CENTER, 0, 40);
lv_obj_t *update_btn_label = lv_label_create( update_btn, NULL );
lv_label_set_text( update_btn_label, "update");
Expand Down
52 changes: 27 additions & 25 deletions src/gui/mainbar/setup_tile/utilities/utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
* Copyright 2020 David Stewart
* Email: [email protected]
*
*
* Based on the work of Dirk Brosswick, sharandac / My-TTGO-Watch
/*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
Expand Down Expand Up @@ -99,17 +97,18 @@ void utilities_tile_setup( void ) {
//Add button for SPIFFS format
format_spiffs_btn = lv_btn_create( utilities_tile, NULL);
lv_obj_set_event_cb( format_spiffs_btn, format_SPIFFS_utilities_event_cb );
lv_obj_set_size(format_spiffs_btn, 80, 60);
lv_obj_align( format_spiffs_btn, NULL, LV_ALIGN_CENTER, 80, -25);
lv_obj_set_size( format_spiffs_btn, 80, 60);
lv_obj_add_style( format_spiffs_btn, LV_BTN_PART_MAIN, mainbar_get_button_style() );
lv_obj_align( format_spiffs_btn, utilities_tile, LV_ALIGN_CENTER, 0, -15);
lv_obj_t *format_spiffs_btn_label = lv_label_create( format_spiffs_btn, NULL );
lv_label_set_text( format_spiffs_btn_label, "Format\nSPIFFS");


//Add button for reboot
reboot_btn = lv_btn_create( utilities_tile, NULL);
lv_obj_set_size(reboot_btn, 70, 40);
lv_obj_set_event_cb( reboot_btn, reboot_utilities_event_cb );
lv_obj_align( reboot_btn, NULL, LV_ALIGN_CENTER, -85, 100);
lv_obj_add_style( reboot_btn, LV_BTN_PART_MAIN, mainbar_get_button_style() );
lv_obj_align( reboot_btn, utilities_tile, LV_ALIGN_IN_BOTTOM_LEFT, 5, -5 );
lv_obj_t *reboot_btn_label = lv_label_create( reboot_btn, NULL );
lv_label_set_text( reboot_btn_label, "Reboot");

Expand All @@ -118,19 +117,19 @@ void utilities_tile_setup( void ) {
poweroff_btn = lv_btn_create( utilities_tile, NULL);
lv_obj_set_size(poweroff_btn, 80, 40);
lv_obj_set_event_cb( poweroff_btn, poweroff_utilities_event_cb );
lv_obj_align( poweroff_btn, NULL, LV_ALIGN_CENTER, 80, 100);
lv_obj_add_style( poweroff_btn, LV_BTN_PART_MAIN, mainbar_get_button_style() );
lv_obj_align( poweroff_btn, utilities_tile, LV_ALIGN_IN_BOTTOM_RIGHT, -5, -5 );
lv_obj_t *poweroff_btn_label = lv_label_create( poweroff_btn, NULL );
lv_label_set_text( poweroff_btn_label, "Poweroff");

lv_obj_t *last_reboot_label = lv_label_create( utilities_tile, NULL);
lv_obj_add_style( last_reboot_label, LV_OBJ_PART_MAIN, &utilities_style );
lv_label_set_text( last_reboot_label, "Last Reboot Reason:");
lv_obj_align( last_reboot_label, NULL, LV_ALIGN_CENTER, 0, 70 );
lv_obj_align( last_reboot_label, format_spiffs_btn, LV_ALIGN_OUT_BOTTOM_MID, 0, 5 );

lv_obj_t *last_reason_label = lv_label_create( utilities_tile, NULL);
lv_obj_add_style( last_reason_label, LV_OBJ_PART_MAIN, &utilities_style );
lv_label_set_text( last_reason_label, "");

lv_label_set_text( last_reason_label, "");

//Get the reason for the last reset, this could be moved into a dedicated function....
esp_reset_reason_t why = esp_reset_reason();
Expand Down Expand Up @@ -172,7 +171,8 @@ void utilities_tile_setup( void ) {
lv_label_set_text( last_reason_label, "No Reason\nReturned");
break;
}
lv_obj_align( last_reason_label, NULL, LV_ALIGN_CENTER, -5, 90 );//Now that the text has changed, align it.
lv_label_set_align( last_reason_label, LV_LABEL_ALIGN_CENTER );
lv_obj_align( last_reason_label, last_reboot_label, LV_ALIGN_OUT_BOTTOM_MID, 0, 5 );//Now that the text has changed, align it.
}

static void enter_utilities_event_cb( lv_obj_t * obj, lv_event_t event ) {
Expand All @@ -192,32 +192,34 @@ static void exit_utilities_event_cb( lv_obj_t * obj, lv_event_t event ) {
//********************************SPIFFS stuff

static void SpiffsWarningBox_event_handler( lv_obj_t * obj, lv_event_t event ){
if(event == LV_EVENT_DELETE && obj == SpiffsWarningBox) {
if( event == LV_EVENT_DELETE && obj == SpiffsWarningBox ) {
/* Delete the parent modal background */
lv_obj_del_async(lv_obj_get_parent(SpiffsWarningBox));
lv_obj_del_async( lv_obj_get_parent( SpiffsWarningBox ) );
SpiffsWarningBox = NULL; /* happens before object is actually deleted! */
} else if(event == LV_EVENT_VALUE_CHANGED) {
if (lv_msgbox_get_active_btn_text(obj) == "Apply") format_SPIFFS();
lv_msgbox_start_auto_close(SpiffsWarningBox, 0);
}

else if( event == LV_EVENT_VALUE_CHANGED ) {
if ( !strcmp( lv_msgbox_get_active_btn_text(obj), "Apply" ) ){
format_SPIFFS();
}
lv_msgbox_start_auto_close( SpiffsWarningBox, 0 );
}
}

static void format_SPIFFS_utilities_event_cb( lv_obj_t * obj, lv_event_t event ) {
switch( event ) {
case( LV_EVENT_CLICKED ):
static const char * btns[] ={"Apply", "Cancel", ""};
static const char * btns[] = {"Apply", "Cancel", ""};

//Setup shading of background
lv_style_set_bg_color(&style_modal, LV_STATE_DEFAULT, LV_COLOR_MAKE(0x20,0x20,0x20));
lv_style_set_bg_opa(&style_modal, LV_STATE_DEFAULT, LV_OPA_80);
lv_style_set_bg_color( &style_modal, LV_STATE_DEFAULT, LV_COLOR_MAKE(0x20,0x20,0x20));
lv_style_set_bg_opa( &style_modal, LV_STATE_DEFAULT, LV_OPA_80);

//The click absorbing screen behind the msgbox
lv_obj_t *obj = lv_obj_create(lv_scr_act(), NULL);
lv_obj_reset_style_list(obj, LV_OBJ_PART_MAIN);
lv_obj_add_style(obj, LV_OBJ_PART_MAIN, &style_modal);
lv_obj_set_pos(obj, 0, 0);
lv_obj_set_size(obj, LV_HOR_RES, LV_VER_RES);
lv_obj_reset_style_list( obj, LV_OBJ_PART_MAIN);
lv_obj_add_style( obj, LV_OBJ_PART_MAIN, &style_modal );
lv_obj_set_pos( obj, 0, 0);
lv_obj_set_size( obj, LV_HOR_RES, LV_VER_RES);


//If you change the message below you need to recalculate the character buffer size!
Expand Down
Loading

0 comments on commit 78fab62

Please sign in to comment.