fix(examples): update the get started examples

This commit is contained in:
Gabor Kiss-Vamosi
2021-02-16 20:41:11 +01:00
parent 4c1b18527b
commit f04dc72c4a
3 changed files with 103 additions and 116 deletions

View File

@@ -10,11 +10,12 @@ static void btn_event_cb(lv_obj_t * btn, lv_event_t event)
/*Get the first child of the button which is the label and change its text*/ /*Get the first child of the button which is the label and change its text*/
lv_obj_t * label = lv_obj_get_child(btn, 0); lv_obj_t * label = lv_obj_get_child(btn, 0);
lv_label_set_text_fmt(label, "Button: %d", cnt); lv_label_set_text_fmt(label, "Button: %d", cnt);
lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
} }
} }
/** /**
* Create a button with a label and react on Click event. * Create a button with a label and react on click event.
*/ */
void lv_example_get_started_1(void) void lv_example_get_started_1(void)
{ {
@@ -25,6 +26,7 @@ void lv_example_get_started_1(void)
lv_obj_t * label = lv_label_create(btn, NULL); /*Add a label to the button*/ lv_obj_t * label = lv_label_create(btn, NULL); /*Add a label to the button*/
lv_label_set_text(label, "Button"); /*Set the labels text*/ lv_label_set_text(label, "Button"); /*Set the labels text*/
lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
} }
#endif #endif

View File

@@ -1,83 +1,66 @@
//#include "../../lv_examples.h" #include "../../lvgl.h"
// #if LV_USE_BTN && LV_BUILD_EXAMPLES
//
///** /**
// * Create styles from scratch for buttons. * Create styles from scratch for buttons.
// */ */
//void lv_example_get_started_2(void) void lv_example_get_started_2(void)
//{ {
// static lv_style_t style_btn; static lv_style_t style_btn;
// static lv_style_t style_btn_red; static lv_style_t style_btn_red;
// static lv_style_t style_btn_pressed;
// /*Create a simple button style*/
// lv_style_init(&style_btn); /*Create a simple button style*/
// lv_style_set_radius(&style_btn, LV_STATE_DEFAULT, 10); lv_style_init(&style_btn);
// lv_style_set_bg_opa(&style_btn, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_radius(&style_btn, 10);
// lv_style_set_bg_color(&style_btn, LV_STATE_DEFAULT, LV_COLOR_SILVER); lv_style_set_bg_opa(&style_btn, LV_OPA_COVER);
// lv_style_set_bg_grad_color(&style_btn, LV_STATE_DEFAULT, LV_COLOR_GRAY); lv_style_set_bg_color(&style_btn, LV_COLOR_SILVER);
// lv_style_set_bg_grad_dir(&style_btn, LV_STATE_DEFAULT, LV_GRAD_DIR_VER); lv_style_set_bg_grad_color(&style_btn, LV_COLOR_GRAY);
// lv_style_set_bg_grad_dir(&style_btn, LV_GRAD_DIR_VER);
// /*Swap the colors in pressed state*/
// lv_style_set_bg_color(&style_btn, LV_STATE_PRESSED, LV_COLOR_GRAY); /*Add a border*/
// lv_style_set_bg_grad_color(&style_btn, LV_STATE_PRESSED, LV_COLOR_SILVER); lv_style_set_border_color(&style_btn, LV_COLOR_WHITE);
// lv_style_set_border_opa(&style_btn, LV_OPA_70);
// /*Add a border*/ lv_style_set_border_width(&style_btn, 2);
// lv_style_set_border_color(&style_btn, LV_STATE_DEFAULT, LV_COLOR_WHITE);
// lv_style_set_border_opa(&style_btn, LV_STATE_DEFAULT, LV_OPA_70); /*Set the text style*/
// lv_style_set_border_width(&style_btn, LV_STATE_DEFAULT, 2); lv_style_set_text_color(&style_btn, LV_COLOR_WHITE);
//
// /*Different border color in focused state*/ /*Create a red style. Change only some colors.*/
// lv_style_set_border_color(&style_btn, LV_STATE_FOCUSED, LV_COLOR_BLUE); lv_style_init(&style_btn_red);
// lv_style_set_border_color(&style_btn, LV_STATE_FOCUSED | LV_STATE_PRESSED, LV_COLOR_NAVY); lv_style_set_bg_color(&style_btn_red, LV_COLOR_RED);
// lv_style_set_bg_grad_color(&style_btn_red, LV_COLOR_MAROON);
// /*Set the text style*/
// lv_style_set_text_color(&style_btn, LV_STATE_DEFAULT, LV_COLOR_WHITE); /*Create a style for the pressed state. Add color filter to make every color darker*/
// lv_style_init(&style_btn_pressed);
// /*Make the button smaller when pressed*/ lv_style_set_color_filter_cb(&style_btn_pressed, lv_color_darken);
// lv_style_set_transform_height(&style_btn, LV_STATE_PRESSED, -5); lv_style_set_color_filter_opa(&style_btn_pressed, LV_OPA_30);
// lv_style_set_transform_width(&style_btn, LV_STATE_PRESSED, -10);
//#if LV_USE_ANIMATION /*Create a button and use the new styles*/
// /*Add a transition to the size change*/ lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL); /*Add a button the current screen*/
// static lv_anim_path_t path; lv_obj_set_pos(btn, 10, 10); /*Set its position*/
// lv_anim_path_init(&path); lv_obj_set_size(btn, 120, 50); /*Set its size*/
// lv_anim_path_set_cb(&path, lv_anim_path_overshoot); lv_obj_remove_style(btn, LV_PART_ANY, LV_STATE_ANY, NULL); /*Remove the styles coming from the theme*/
// lv_obj_add_style(btn, LV_PART_MAIN, LV_STATE_DEFAULT, &style_btn);
// lv_style_set_transition_prop_1(&style_btn, LV_STATE_DEFAULT, LV_STYLE_TRANSFORM_HEIGHT); lv_obj_add_style(btn, LV_PART_MAIN, LV_STATE_PRESSED, &style_btn_pressed);
// lv_style_set_transition_prop_2(&style_btn, LV_STATE_DEFAULT, LV_STYLE_TRANSFORM_WIDTH);
// lv_style_set_transition_time(&style_btn, LV_STATE_DEFAULT, 300); lv_obj_t * label = lv_label_create(btn, NULL); /*Add a label to the button*/
// lv_style_set_transition_path(&style_btn, LV_STATE_DEFAULT, &path); lv_label_set_text(label, "Button"); /*Set the labels text*/
//#endif lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
//
// /*Create a red style. Change only some colors.*/ /*Create an other button and use the red style too*/
// lv_style_init(&style_btn_red); lv_obj_t * btn2 = lv_btn_create(lv_scr_act(), NULL);
// lv_style_set_bg_color(&style_btn_red, LV_STATE_DEFAULT, LV_COLOR_RED); lv_obj_set_pos(btn2, 10, 80);
// lv_style_set_bg_grad_color(&style_btn_red, LV_STATE_DEFAULT, LV_COLOR_MAROON); lv_obj_set_size(btn2, 120, 50); /*Set its size*/
// lv_style_set_bg_color(&style_btn_red, LV_STATE_PRESSED, LV_COLOR_MAROON); lv_obj_remove_style(btn2, LV_PART_ANY, LV_STATE_ANY, NULL); /*Remove the styles coming from the theme*/
// lv_style_set_bg_grad_color(&style_btn_red, LV_STATE_PRESSED, LV_COLOR_RED); lv_obj_add_style(btn2, LV_PART_MAIN, LV_STATE_DEFAULT, &style_btn);
// lv_style_set_text_color(&style_btn_red, LV_STATE_DEFAULT, LV_COLOR_WHITE); lv_obj_add_style(btn2, LV_PART_MAIN, LV_STATE_DEFAULT, &style_btn_red);
//#if LV_USE_BTN lv_obj_add_style(btn2, LV_PART_MAIN, LV_STATE_PRESSED, &style_btn_pressed);
// /*Create buttons and use the new styles*/ lv_obj_set_style_radius(btn2, LV_PART_MAIN, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); /*Add a local style*/
// lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL); /*Add a button the current screen*/
// lv_obj_set_pos(btn, 10, 10); /*Set its position*/ label = lv_label_create(btn2, NULL); /*Add a label to the button*/
// lv_obj_set_size(btn, 120, 50); /*Set its size*/ lv_label_set_text(label, "Button 2"); /*Set the labels text*/
// lv_obj_reset_style_list(btn, LV_BTN_PART_MAIN); /*Remove the styles coming from the theme*/ lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
// lv_obj_add_style(btn, LV_BTN_PART_MAIN, &style_btn); }
//
// lv_obj_t * label = lv_label_create(btn, NULL); /*Add a label to the button*/ #endif
// lv_label_set_text(label, "Button"); /*Set the labels text*/
//
// /*Create a new button*/
// lv_obj_t * btn2 = lv_btn_create(lv_scr_act(), btn);
// lv_obj_set_pos(btn2, 10, 80);
// lv_obj_set_size(btn2, 120, 50); /*Set its size*/
// lv_obj_reset_style_list(btn2, LV_BTN_PART_MAIN); /*Remove the styles coming from the theme*/
// lv_obj_add_style(btn2, LV_BTN_PART_MAIN, &style_btn);
// lv_obj_add_style(btn2, LV_BTN_PART_MAIN, &style_btn_red); /*Add the red style on top of the current */
// lv_obj_set_style_local_radius(btn2, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); /*Add a local style*/
//
// label = lv_label_create(btn2, NULL); /*Add a label to the button*/
// lv_label_set_text(label, "Button 2"); /*Set the labels text*/
//#endif
//}
//
//

View File

@@ -1,31 +1,33 @@
//#include "../../lv_examples.h" #include "../../lvgl.h"
// #if LV_BUILD_EXAMPLES && LV_USE_SLIDER
//static lv_obj_t * label;
// static lv_obj_t * label;
//static void slider_event_cb(lv_obj_t * slider, lv_event_t event)
//{ static void slider_event_cb(lv_obj_t * slider, lv_event_t event)
// if(event == LV_EVENT_VALUE_CHANGED) { {
// /*Refresh the text*/ if(event == LV_EVENT_VALUE_CHANGED) {
// lv_label_set_text_fmt(label, "%d", lv_slider_get_value(slider)); /*Refresh the text*/
// lv_obj_align(label, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 20); /*Align below the slider*/ lv_label_set_text_fmt(label, "%d", lv_slider_get_value(slider));
// } lv_obj_align(label, slider, LV_ALIGN_OUT_TOP_MID, 0, -15); /*Align below the slider*/
//} }
// }
///**
// * Create a slider and write its value on a label. /**
// */ * Create a slider and write its value on a label.
//void lv_example_get_started_3(void) */
//{ void lv_example_get_started_3(void)
// /* Create a slider in the center of the display */ {
// lv_obj_t * slider = lv_slider_create(lv_scr_act(), NULL); /* Create a slider in the center of the display */
// lv_obj_set_width(slider, 200); /*Set the width*/ lv_obj_t * slider = lv_slider_create(lv_scr_act(), NULL);
// lv_obj_align(slider, NULL, LV_ALIGN_CENTER, 0, 0); /*Align to the center of the parent (screen)*/ lv_obj_set_width(slider, 200); /*Set the width*/
// lv_obj_set_event_cb(slider, slider_event_cb); /*Assign an event function*/ lv_obj_align(slider, NULL, LV_ALIGN_CENTER, 0, 0); /*Align to the center of the parent (screen)*/
// lv_obj_add_event_cb(slider, slider_event_cb, NULL); /*Assign an event function*/
// /* Create a label below the slider */
// label = lv_label_create(lv_scr_act(), NULL); /* Create a label below the slider */
// lv_label_set_text(label, "0"); label = lv_label_create(lv_scr_act(), NULL);
// lv_obj_align(label, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 20); /*Align below the slider*/ lv_label_set_text(label, "0");
//} lv_obj_align(label, slider, LV_ALIGN_OUT_TOP_MID, 0, -15); /*Align below the slider*/
// }
//
#endif