嵌入式UI开发-lvgl+wsl2+vscode系列:9、控件(Widgets)(二)

一、前言

接下来我们总结第二部分的控件。

二、示例

1、image(图像)

1.1、示例1
#include "../../lv_examples.h"
#if LV_USE_IMAGE && LV_BUILD_EXAMPLESvoid lv_example_image_1(void)
{LV_IMAGE_DECLARE(img_cogwheel_argb);lv_obj_t * img1 = lv_image_create(lv_screen_active());lv_image_set_src(img1, &img_cogwheel_argb);lv_obj_align(img1, LV_ALIGN_CENTER, 0, 0);lv_obj_t * img2 = lv_image_create(lv_screen_active());lv_image_set_src(img2, LV_SYMBOL_OK "Accept");lv_obj_align_to(img2, img1, LV_ALIGN_OUT_BOTTOM_MID, 0, 20);
}#endif

image.png

1.2、示例2
#include "../../lv_examples.h"
#if LV_USE_IMAGE && LV_USE_SLIDER && LV_BUILD_EXAMPLESstatic lv_obj_t * create_slider(lv_color_t color);
static void slider_event_cb(lv_event_t * e);static lv_obj_t * red_slider, * green_slider, * blue_slider, * intense_slider;
static lv_obj_t * img1;/*** 演示运行时图像重新着色*/
void lv_example_image_2(void)
{/*创建 4 个滑块来调整 RGB 颜色和重新着色强度*/red_slider = create_slider(lv_palette_main(LV_PALETTE_RED));green_slider = create_slider(lv_palette_main(LV_PALETTE_GREEN));blue_slider = create_slider(lv_palette_main(LV_PALETTE_BLUE));intense_slider = create_slider(lv_palette_main(LV_PALETTE_GREY));lv_slider_set_value(red_slider, LV_OPA_20, LV_ANIM_OFF);lv_slider_set_value(green_slider, LV_OPA_90, LV_ANIM_OFF);lv_slider_set_value(blue_slider, LV_OPA_60, LV_ANIM_OFF);lv_slider_set_value(intense_slider, LV_OPA_50, LV_ANIM_OFF);lv_obj_align(red_slider, LV_ALIGN_LEFT_MID, 25, 0);lv_obj_align_to(green_slider, red_slider, LV_ALIGN_OUT_RIGHT_MID, 25, 0);lv_obj_align_to(blue_slider, green_slider, LV_ALIGN_OUT_RIGHT_MID, 25, 0);lv_obj_align_to(intense_slider, blue_slider, LV_ALIGN_OUT_RIGHT_MID, 25, 0);/*现在创建实际图像*/LV_IMAGE_DECLARE(img_cogwheel_argb);img1 = lv_image_create(lv_screen_active());lv_image_set_src(img1, &img_cogwheel_argb);lv_obj_align(img1, LV_ALIGN_RIGHT_MID, -20, 0);lv_obj_send_event(intense_slider, LV_EVENT_VALUE_CHANGED, NULL);
}static void slider_event_cb(lv_event_t * e)
{LV_UNUSED(e);/*根据滑块的值重新着色图像*/lv_color_t color  = lv_color_make(lv_slider_get_value(red_slider), lv_slider_get_value(green_slider),lv_slider_get_value(blue_slider));lv_opa_t intense = lv_slider_get_value(intense_slider);lv_obj_set_style_image_recolor_opa(img1, intense, 0);lv_obj_set_style_image_recolor(img1, color, 0);
}static lv_obj_t * create_slider(lv_color_t color)
{lv_obj_t * slider = lv_slider_create(lv_screen_active());lv_slider_set_range(slider, 0, 255);lv_obj_set_size(slider, 10, 200);lv_obj_set_style_bg_color(slider, color, LV_PART_KNOB);lv_obj_set_style_bg_color(slider, lv_color_darken(color, LV_OPA_40), LV_PART_INDICATOR);lv_obj_add_event_cb(slider, slider_event_cb, LV_EVENT_VALUE_CHANGED, NULL);return slider;
}#endif

image.gif

1.3、示例3
#include "../../lv_examples.h"
#if LV_USE_IMAGE && LV_BUILD_EXAMPLESstatic void set_angle(void * img, int32_t v)
{lv_image_set_rotation(img, v);
}static void set_scale(void * img, int32_t v)
{lv_image_set_scale(img, v);
}/*** 使用枢轴点显示变换(缩放和旋转)。*/
void lv_example_image_3(void)
{LV_IMAGE_DECLARE(img_cogwheel_argb);/*现在创建实际图像*/lv_obj_t * img = lv_image_create(lv_screen_active());lv_image_set_src(img, &img_cogwheel_argb);lv_obj_align(img, LV_ALIGN_CENTER, 50, 50);lv_image_set_pivot(img, 0, 0);    /*绕左上角旋转*/lv_anim_t a;lv_anim_init(&a);lv_anim_set_var(&a, img);lv_anim_set_exec_cb(&a, set_angle);lv_anim_set_values(&a, 0, 3600);lv_anim_set_duration(&a, 5000);lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);lv_anim_start(&a);lv_anim_set_exec_cb(&a, set_scale);lv_anim_set_values(&a, 128, 256);lv_anim_set_playback_duration(&a, 3000);lv_anim_start(&a);
}#endif

image2.gif

1.4、示例4
#include "../../lv_examples.h"
#if LV_USE_IMAGE && LV_BUILD_EXAMPLESstatic void ofs_y_anim(void * img, int32_t v)
{lv_image_set_offset_y(img, v);
}/*** 图像样式和偏移*/
void lv_example_image_4(void)
{LV_IMAGE_DECLARE(img_skew_strip);static lv_style_t style;lv_style_init(&style);lv_style_set_bg_color(&style, lv_palette_main(LV_PALETTE_YELLOW));lv_style_set_bg_opa(&style, LV_OPA_COVER);lv_style_set_image_recolor_opa(&style, LV_OPA_COVER);lv_style_set_image_recolor(&style, lv_color_black());lv_obj_t * img = lv_image_create(lv_screen_active());lv_obj_add_style(img, &style, 0);lv_image_set_src(img, &img_skew_strip);lv_obj_set_size(img, 150, 100);lv_obj_center(img);lv_anim_t a;lv_anim_init(&a);lv_anim_set_var(&a, img);lv_anim_set_exec_cb(&a, ofs_y_anim);lv_anim_set_values(&a, 0, 100);lv_anim_set_duration(&a, 3000);lv_anim_set_playback_duration(&a, 500);lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);lv_anim_start(&a);}#endif

image3.gif

2、image button(图像按钮)

#include "../../lv_examples.h"
#if LV_USE_IMAGEBUTTON && LV_BUILD_EXAMPLESvoid lv_example_imagebutton_1(void)
{LV_IMAGE_DECLARE(imagebutton_left);LV_IMAGE_DECLARE(imagebutton_right);LV_IMAGE_DECLARE(imagebutton_mid);/*创建宽度变换和重新着色的过渡动画。*/static lv_style_prop_t tr_prop[] = {LV_STYLE_TRANSFORM_WIDTH, LV_STYLE_IMAGE_RECOLOR_OPA, 0};static lv_style_transition_dsc_t tr;lv_style_transition_dsc_init(&tr, tr_prop, lv_anim_path_linear, 200, 0, NULL);static lv_style_t style_def;lv_style_init(&style_def);lv_style_set_text_color(&style_def, lv_color_white());lv_style_set_transition(&style_def, &tr);/*按下按钮时使按钮变暗并使其反射*/static lv_style_t style_pr;lv_style_init(&style_pr);lv_style_set_image_recolor_opa(&style_pr, LV_OPA_30);lv_style_set_image_recolor(&style_pr, lv_color_black());lv_style_set_transform_width(&style_pr, 20);/*创建图像按钮*/lv_obj_t * imagebutton1 = lv_imagebutton_create(lv_screen_active());lv_imagebutton_set_src(imagebutton1, LV_IMAGEBUTTON_STATE_RELEASED, &imagebutton_left, &imagebutton_mid,&imagebutton_right);lv_obj_add_style(imagebutton1, &style_def, 0);lv_obj_add_style(imagebutton1, &style_pr, LV_STATE_PRESSED);lv_obj_set_width(imagebutton1, 100);lv_obj_align(imagebutton1, LV_ALIGN_CENTER, 0, 0);/*在图像按钮上创建标签*/lv_obj_t * label = lv_label_create(imagebutton1);lv_label_set_text(label, "Button");lv_obj_align(label, LV_ALIGN_CENTER, 0, -4);
}#endif

imageButton.gif

3、keyboard(键盘)

3.1、示例1
#include "../../lv_examples.h"
#if LV_USE_KEYBOARD && LV_BUILD_EXAMPLESstatic void ta_event_cb(lv_event_t * e)
{lv_event_code_t code = lv_event_get_code(e);lv_obj_t * ta = lv_event_get_target(e);lv_obj_t * kb = lv_event_get_user_data(e);if(code == LV_EVENT_FOCUSED) {lv_keyboard_set_textarea(kb, ta);lv_obj_remove_flag(kb, LV_OBJ_FLAG_HIDDEN);}if(code == LV_EVENT_DEFOCUSED) {lv_keyboard_set_textarea(kb, NULL);lv_obj_add_flag(kb, LV_OBJ_FLAG_HIDDEN);}
}void lv_example_keyboard_1(void)
{/*创建一个键盘以将其与文本区域一起使用*/lv_obj_t * kb = lv_keyboard_create(lv_screen_active());/*创建一个文本区域。键盘会写到这里*/lv_obj_t * ta1;ta1 = lv_textarea_create(lv_screen_active());lv_obj_align(ta1, LV_ALIGN_TOP_LEFT, 10, 10);lv_obj_add_event_cb(ta1, ta_event_cb, LV_EVENT_ALL, kb);lv_textarea_set_placeholder_text(ta1, "Hello");lv_obj_set_size(ta1, 140, 80);lv_obj_t * ta2;ta2 = lv_textarea_create(lv_screen_active());lv_obj_align(ta2, LV_ALIGN_TOP_RIGHT, -10, 10);lv_obj_add_event_cb(ta2, ta_event_cb, LV_EVENT_ALL, kb);lv_obj_set_size(ta2, 140, 80);lv_keyboard_set_textarea(kb, ta1);/*如果启用,键盘将显示阿拉伯字符 */
#if LV_USE_ARABIC_PERSIAN_CHARS && LV_FONT_DEJAVU_16_PERSIAN_HEBREWlv_obj_set_style_text_font(kb, &lv_font_dejavu_16_persian_hebrew, 0);lv_obj_set_style_text_font(ta1, &lv_font_dejavu_16_persian_hebrew, 0);lv_obj_set_style_text_font(ta2, &lv_font_dejavu_16_persian_hebrew, 0);
#endif
}
#endif

keyboard.gif

3.2 示例2
#include "../../lv_examples.h"
#if LV_USE_KEYBOARD && LV_BUILD_EXAMPLESvoid lv_example_keyboard_2(void)
{/*创建 AZERTY 键盘映射*/static const char * kb_map[] = {"A", "Z", "E", "R", "T", "Y", "U", "I", "O", "P", LV_SYMBOL_BACKSPACE, "\n","Q", "S", "D", "F", "G", "J", "K", "L", "M",  LV_SYMBOL_NEW_LINE, "\n","W", "X", "C", "V", "B", "N", ",", ".", ":", "!", "?", "\n",LV_SYMBOL_CLOSE, " ",  " ", " ", LV_SYMBOL_OK, NULL};/*设置按钮和其他控件的相对宽度*/static const lv_buttonmatrix_ctrl_t kb_ctrl[] = {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6,4, 4, 4, 4, 4, 4, 4, 4, 4, 6,4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,2, LV_BUTTONMATRIX_CTRL_HIDDEN | 2, 6, LV_BUTTONMATRIX_CTRL_HIDDEN | 2, 2};/*创建键盘并将新地图添加为 USER_1 模式*/lv_obj_t * kb = lv_keyboard_create(lv_screen_active());lv_keyboard_set_map(kb, LV_KEYBOARD_MODE_USER_1, kb_map, kb_ctrl);lv_keyboard_set_mode(kb, LV_KEYBOARD_MODE_USER_1);/*创建一个文本区域。键盘会写到这里*/lv_obj_t * ta;ta = lv_textarea_create(lv_screen_active());lv_obj_align(ta, LV_ALIGN_TOP_MID, 0, 10);lv_obj_set_size(ta, lv_pct(90), 80);lv_obj_add_state(ta, LV_STATE_FOCUSED);lv_keyboard_set_textarea(kb, ta);
}
#endif

keyboard2.gif

4、label(标签)略

同样在最开始的三大标签中已经总结过了。

5、led(指示灯)

#include "../../lv_examples.h"
#if LV_USE_LED && LV_BUILD_EXAMPLES/*** 创建具有不同亮度和颜色的 LED*/
void lv_example_led_1(void)
{/*Create a LED and switch it OFF*/lv_obj_t * led1  = lv_led_create(lv_screen_active());lv_obj_align(led1, LV_ALIGN_CENTER, -80, 0);lv_led_off(led1);/*复制之前的 LED 并设置亮度*/lv_obj_t * led2  = lv_led_create(lv_screen_active());lv_obj_align(led2, LV_ALIGN_CENTER, 0, 0);lv_led_set_brightness(led2, 150);lv_led_set_color(led2, lv_palette_main(LV_PALETTE_RED));/*复制之前的 LED 并将其打开*/lv_obj_t * led3  = lv_led_create(lv_screen_active());lv_obj_align(led3, LV_ALIGN_CENTER, 80, 0);lv_led_on(led3);
}#endif

image.png

6、line(线条)

#include "../../lv_examples.h"
#if LV_USE_LINE && LV_BUILD_EXAMPLESvoid lv_example_line_1(void)
{/*为线的点创建一个数组*/static lv_point_precise_t line_points[] = { {5, 5}, {70, 70}, {120, 10}, {180, 60}, {240, 10} };/*Create style*/static lv_style_t style_line;lv_style_init(&style_line);lv_style_set_line_width(&style_line, 8);lv_style_set_line_color(&style_line, lv_palette_main(LV_PALETTE_BLUE));lv_style_set_line_rounded(&style_line, true);/*创建一条线并应用新样式*/lv_obj_t * line1;line1 = lv_line_create(lv_screen_active());lv_line_set_points(line1, line_points, 5);     /*Set the points*/lv_obj_add_style(line1, &style_line, 0);lv_obj_center(line1);
}#endif

image.png

7、list(列表)

7.1、示例1
#include "../../lv_examples.h"
#if LV_USE_LIST && LV_BUILD_EXAMPLES
static lv_obj_t * list1;static void event_handler(lv_event_t * e)
{lv_event_code_t code = lv_event_get_code(e);lv_obj_t * obj = lv_event_get_target(e);if(code == LV_EVENT_CLICKED) {LV_UNUSED(obj);LV_LOG_USER("Clicked: %s", lv_list_get_button_text(list1, obj));}
}
void lv_example_list_1(void)
{/*创建一个列表*/list1 = lv_list_create(lv_screen_active());lv_obj_set_size(list1, 180, 220);lv_obj_center(list1);/*将按钮添加到列表中*/lv_obj_t * btn;lv_list_add_text(list1, "File");btn = lv_list_add_button(list1, LV_SYMBOL_FILE, "New");lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);btn = lv_list_add_button(list1, LV_SYMBOL_DIRECTORY, "Open");lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);btn = lv_list_add_button(list1, LV_SYMBOL_SAVE, "Save");lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);btn = lv_list_add_button(list1, LV_SYMBOL_CLOSE, "Delete");lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);btn = lv_list_add_button(list1, LV_SYMBOL_EDIT, "Edit");lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);lv_list_add_text(list1, "Connectivity");btn = lv_list_add_button(list1, LV_SYMBOL_BLUETOOTH, "Bluetooth");lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);btn = lv_list_add_button(list1, LV_SYMBOL_GPS, "Navigation");lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);btn = lv_list_add_button(list1, LV_SYMBOL_USB, "USB");lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);btn = lv_list_add_button(list1, LV_SYMBOL_BATTERY_FULL, "Battery");lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);lv_list_add_text(list1, "Exit");btn = lv_list_add_button(list1, LV_SYMBOL_OK, "Apply");lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);btn = lv_list_add_button(list1, LV_SYMBOL_CLOSE, "Close");lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);
}#endif

list.gif

7.2、示例2
#include <stdlib.h>#include "../../lv_examples.h"
#if LV_USE_LIST && LV_BUILD_EXAMPLESstatic lv_obj_t * list1;
static lv_obj_t * list2;static lv_obj_t * currentButton = NULL;static void event_handler(lv_event_t * e)
{lv_event_code_t code = lv_event_get_code(e);lv_obj_t * obj = lv_event_get_target(e);if(code == LV_EVENT_CLICKED) {LV_LOG_USER("Clicked: %s", lv_list_get_button_text(list1, obj));if(currentButton == obj) {currentButton = NULL;}else {currentButton = obj;}lv_obj_t * parent = lv_obj_get_parent(obj);uint32_t i;for(i = 0; i < lv_obj_get_child_count(parent); i++) {lv_obj_t * child = lv_obj_get_child(parent, i);if(child == currentButton) {lv_obj_add_state(child, LV_STATE_CHECKED);}else {lv_obj_remove_state(child, LV_STATE_CHECKED);}}}
}static void event_handler_top(lv_event_t * e)
{lv_event_code_t code = lv_event_get_code(e);if(code == LV_EVENT_CLICKED) {if(currentButton == NULL) return;lv_obj_move_background(currentButton);lv_obj_scroll_to_view(currentButton, LV_ANIM_ON);}
}static void event_handler_up(lv_event_t * e)
{lv_event_code_t code = lv_event_get_code(e);if((code == LV_EVENT_CLICKED) || (code == LV_EVENT_LONG_PRESSED_REPEAT)) {if(currentButton == NULL) return;uint32_t index = lv_obj_get_index(currentButton);if(index <= 0) return;lv_obj_move_to_index(currentButton, index - 1);lv_obj_scroll_to_view(currentButton, LV_ANIM_ON);}
}static void event_handler_center(lv_event_t * e)
{const lv_event_code_t code = lv_event_get_code(e);if((code == LV_EVENT_CLICKED) || (code == LV_EVENT_LONG_PRESSED_REPEAT)) {if(currentButton == NULL) return;lv_obj_t * parent = lv_obj_get_parent(currentButton);const uint32_t pos = lv_obj_get_child_count(parent) / 2;lv_obj_move_to_index(currentButton, pos);lv_obj_scroll_to_view(currentButton, LV_ANIM_ON);}
}static void event_handler_dn(lv_event_t * e)
{const lv_event_code_t code = lv_event_get_code(e);if((code == LV_EVENT_CLICKED) || (code == LV_EVENT_LONG_PRESSED_REPEAT)) {if(currentButton == NULL) return;const uint32_t index = lv_obj_get_index(currentButton);lv_obj_move_to_index(currentButton, index + 1);lv_obj_scroll_to_view(currentButton, LV_ANIM_ON);}
}static void event_handler_bottom(lv_event_t * e)
{const lv_event_code_t code = lv_event_get_code(e);if(code == LV_EVENT_CLICKED) {if(currentButton == NULL) return;lv_obj_move_foreground(currentButton);lv_obj_scroll_to_view(currentButton, LV_ANIM_ON);}
}static void event_handler_swap(lv_event_t * e)
{const lv_event_code_t code = lv_event_get_code(e);// lv_obj_t* obj = lv_event_get_target(e);if((code == LV_EVENT_CLICKED) || (code == LV_EVENT_LONG_PRESSED_REPEAT)) {uint32_t cnt = lv_obj_get_child_count(list1);for(int i = 0; i < 100; i++)if(cnt > 1) {lv_obj_t * obj = lv_obj_get_child(list1, rand() % cnt);lv_obj_move_to_index(obj, rand() % cnt);if(currentButton != NULL) {lv_obj_scroll_to_view(currentButton, LV_ANIM_ON);}}}
}void lv_example_list_2(void)
{/*创建一个列表*/list1 = lv_list_create(lv_screen_active());lv_obj_set_size(list1, lv_pct(60), lv_pct(100));lv_obj_set_style_pad_row(list1, 5, 0);/*将按钮添加到列表中*/lv_obj_t * btn;int i;for(i = 0; i < 15; i++) {btn = lv_button_create(list1);lv_obj_set_width(btn, lv_pct(50));lv_obj_add_event_cb(btn, event_handler, LV_EVENT_CLICKED, NULL);lv_obj_t * lab = lv_label_create(btn);lv_label_set_text_fmt(lab, "Item %d", i);}/*默认选择第一个按钮*/currentButton = lv_obj_get_child(list1, 0);lv_obj_add_state(currentButton, LV_STATE_CHECKED);/*创建带有向上和向下按钮的第二个列表*/list2 = lv_list_create(lv_screen_active());lv_obj_set_size(list2, lv_pct(40), lv_pct(100));lv_obj_align(list2, LV_ALIGN_TOP_RIGHT, 0, 0);lv_obj_set_flex_flow(list2, LV_FLEX_FLOW_COLUMN);btn = lv_list_add_button(list2, NULL, "Top");lv_obj_add_event_cb(btn, event_handler_top, LV_EVENT_ALL, NULL);lv_group_remove_obj(btn);btn = lv_list_add_button(list2, LV_SYMBOL_UP, "Up");lv_obj_add_event_cb(btn, event_handler_up, LV_EVENT_ALL, NULL);lv_group_remove_obj(btn);btn = lv_list_add_button(list2, LV_SYMBOL_LEFT, "Center");lv_obj_add_event_cb(btn, event_handler_center, LV_EVENT_ALL, NULL);lv_group_remove_obj(btn);btn = lv_list_add_button(list2, LV_SYMBOL_DOWN, "Down");lv_obj_add_event_cb(btn, event_handler_dn, LV_EVENT_ALL, NULL);lv_group_remove_obj(btn);btn = lv_list_add_button(list2, NULL, "Bottom");lv_obj_add_event_cb(btn, event_handler_bottom, LV_EVENT_ALL, NULL);lv_group_remove_obj(btn);btn = lv_list_add_button(list2, LV_SYMBOL_SHUFFLE, "Shuffle");lv_obj_add_event_cb(btn, event_handler_swap, LV_EVENT_ALL, NULL);lv_group_remove_obj(btn);
}#endif

list2.gif

8、menu(菜单)

8.1、示例1
#include "../../lv_examples.h"
#if LV_USE_MENU && LV_BUILD_EXAMPLESvoid lv_example_menu_1(void)
{/*创建菜单对象*/lv_obj_t * menu = lv_menu_create(lv_screen_active());lv_obj_set_size(menu, lv_display_get_horizontal_resolution(NULL), lv_display_get_vertical_resolution(NULL));lv_obj_center(menu);lv_obj_t * cont;lv_obj_t * label;/*创建子页面*/lv_obj_t * sub_page = lv_menu_page_create(menu, NULL);cont = lv_menu_cont_create(sub_page);label = lv_label_create(cont);lv_label_set_text(label, "Hello, I am hiding here");/*创建一个主页*/lv_obj_t * main_page = lv_menu_page_create(menu, NULL);cont = lv_menu_cont_create(main_page);label = lv_label_create(cont);lv_label_set_text(label, "Item 1");cont = lv_menu_cont_create(main_page);label = lv_label_create(cont);lv_label_set_text(label, "Item 2");cont = lv_menu_cont_create(main_page);label = lv_label_create(cont);lv_label_set_text(label, "Item 3 (Click me!)");lv_menu_set_load_page_event(menu, cont, sub_page);lv_menu_set_page(menu, main_page);
}#endif

menu.gif

8.2、示例2
#include "../../lv_examples.h"
#if LV_USE_MENU && LV_USE_MSGBOX && LV_BUILD_EXAMPLESstatic void back_event_handler(lv_event_t * e)
{lv_obj_t * obj = lv_event_get_target(e);lv_obj_t * menu = lv_event_get_user_data(e);if(lv_menu_back_button_is_root(menu, obj)) {lv_obj_t * mbox1 = lv_msgbox_create(NULL);lv_msgbox_add_title(mbox1, "Hello");lv_msgbox_add_text(mbox1, "Root back btn click.");lv_msgbox_add_close_button(mbox1);}
}void lv_example_menu_2(void)
{lv_obj_t * menu = lv_menu_create(lv_screen_active());lv_menu_set_mode_root_back_button(menu, LV_MENU_ROOT_BACK_BUTTON_ENABLED);lv_obj_add_event_cb(menu, back_event_handler, LV_EVENT_CLICKED, menu);lv_obj_set_size(menu, lv_display_get_horizontal_resolution(NULL), lv_display_get_vertical_resolution(NULL));lv_obj_center(menu);lv_obj_t * cont;lv_obj_t * label;/*创建子页面*/lv_obj_t * sub_page = lv_menu_page_create(menu, NULL);cont = lv_menu_cont_create(sub_page);label = lv_label_create(cont);lv_label_set_text(label, "Hello, I am hiding here");/*创建主页面*/lv_obj_t * main_page = lv_menu_page_create(menu, NULL);cont = lv_menu_cont_create(main_page);label = lv_label_create(cont);lv_label_set_text(label, "Item 1");cont = lv_menu_cont_create(main_page);label = lv_label_create(cont);lv_label_set_text(label, "Item 2");cont = lv_menu_cont_create(main_page);label = lv_label_create(cont);lv_label_set_text(label, "Item 3 (Click me!)");lv_menu_set_load_page_event(menu, cont, sub_page);lv_menu_set_page(menu, main_page);
}#endif

menu2.gif

8.3、示例3
#include "../../lv_examples.h"
#if LV_USE_MENU && LV_BUILD_EXAMPLESvoid lv_example_menu_3(void)
{/*创建菜单对象*/lv_obj_t * menu = lv_menu_create(lv_screen_active());lv_obj_set_size(menu, lv_display_get_horizontal_resolution(NULL), lv_display_get_vertical_resolution(NULL));lv_obj_center(menu);/*修改标题*/lv_obj_t * back_btn = lv_menu_get_main_header_back_button(menu);lv_obj_t * back_button_label = lv_label_create(back_btn);lv_label_set_text(back_button_label, "Back");lv_obj_t * cont;lv_obj_t * label;/*创建子页面*/lv_obj_t * sub_1_page = lv_menu_page_create(menu, "Page 1");cont = lv_menu_cont_create(sub_1_page);label = lv_label_create(cont);lv_label_set_text(label, "Hello, I am hiding here");lv_obj_t * sub_2_page = lv_menu_page_create(menu, "Page 2");cont = lv_menu_cont_create(sub_2_page);label = lv_label_create(cont);lv_label_set_text(label, "Hello, I am hiding here");lv_obj_t * sub_3_page = lv_menu_page_create(menu, "Page 3");cont = lv_menu_cont_create(sub_3_page);label = lv_label_create(cont);lv_label_set_text(label, "Hello, I am hiding here");/*创建一个主页*/lv_obj_t * main_page = lv_menu_page_create(menu, NULL);cont = lv_menu_cont_create(main_page);label = lv_label_create(cont);lv_label_set_text(label, "Item 1 (Click me!)");lv_menu_set_load_page_event(menu, cont, sub_1_page);cont = lv_menu_cont_create(main_page);label = lv_label_create(cont);lv_label_set_text(label, "Item 2 (Click me!)");lv_menu_set_load_page_event(menu, cont, sub_2_page);cont = lv_menu_cont_create(main_page);label = lv_label_create(cont);lv_label_set_text(label, "Item 3 (Click me!)");lv_menu_set_load_page_event(menu, cont, sub_3_page);lv_menu_set_page(menu, main_page);
}#endif

menu3.gif

8.4、示例4
#include "../../lv_examples.h"
#if LV_USE_MENU && LV_BUILD_EXAMPLESstatic uint32_t btn_cnt = 1;
static lv_obj_t * main_page;
static lv_obj_t * menu;static void float_button_event_cb(lv_event_t * e)
{LV_UNUSED(e);btn_cnt++;lv_obj_t * cont;lv_obj_t * label;lv_obj_t * sub_page = lv_menu_page_create(menu, NULL);cont = lv_menu_cont_create(sub_page);label = lv_label_create(cont);lv_label_set_text_fmt(label, "Hello, I am hiding inside %"LV_PRIu32"", btn_cnt);cont = lv_menu_cont_create(main_page);label = lv_label_create(cont);lv_label_set_text_fmt(label, "Item %"LV_PRIu32"", btn_cnt);lv_menu_set_load_page_event(menu, cont, sub_page);lv_obj_scroll_to_view_recursive(cont, LV_ANIM_ON);
}void lv_example_menu_4(void)
{/*创建菜单对象*/menu = lv_menu_create(lv_screen_active());lv_obj_set_size(menu, lv_display_get_horizontal_resolution(NULL), lv_display_get_vertical_resolution(NULL));lv_obj_center(menu);lv_obj_t * cont;lv_obj_t * label;/*创建子页面*/lv_obj_t * sub_page = lv_menu_page_create(menu, NULL);cont = lv_menu_cont_create(sub_page);label = lv_label_create(cont);lv_label_set_text(label, "Hello, I am hiding inside the first item");/*创建一个主页面*/main_page = lv_menu_page_create(menu, NULL);cont = lv_menu_cont_create(main_page);label = lv_label_create(cont);lv_label_set_text(label, "Item 1");lv_menu_set_load_page_event(menu, cont, sub_page);lv_menu_set_page(menu, main_page);/*创建浮动btn*/lv_obj_t * float_btn = lv_button_create(lv_screen_active());lv_obj_set_size(float_btn, 50, 50);lv_obj_add_flag(float_btn, LV_OBJ_FLAG_FLOATING);lv_obj_align(float_btn, LV_ALIGN_BOTTOM_RIGHT, -10, -10);lv_obj_add_event_cb(float_btn, float_button_event_cb, LV_EVENT_CLICKED, menu);lv_obj_set_style_radius(float_btn, LV_RADIUS_CIRCLE, 0);lv_obj_set_style_bg_image_src(float_btn, LV_SYMBOL_PLUS, 0);lv_obj_set_style_text_font(float_btn, lv_theme_get_font_large(float_btn), 0);
}#endif

menu4.gif

8.5、示例5
#include "../../lv_examples.h"
#if LV_USE_MENU && LV_USE_MSGBOX && LV_BUILD_EXAMPLESenum {LV_MENU_ITEM_BUILDER_VARIANT_1,LV_MENU_ITEM_BUILDER_VARIANT_2
};
typedef uint8_t lv_menu_builder_variant_t;static void back_event_handler(lv_event_t * e);
static void switch_handler(lv_event_t * e);
lv_obj_t * root_page;
static lv_obj_t * create_text(lv_obj_t * parent, const char * icon, const char * txt,lv_menu_builder_variant_t builder_variant);
static lv_obj_t * create_slider(lv_obj_t * parent,const char * icon, const char * txt, int32_t min, int32_t max, int32_t val);
static lv_obj_t * create_switch(lv_obj_t * parent,const char * icon, const char * txt, bool chk);void lv_example_menu_5(void)
{lv_obj_t * menu = lv_menu_create(lv_screen_active());lv_color_t bg_color = lv_obj_get_style_bg_color(menu, 0);if(lv_color_brightness(bg_color) > 127) {lv_obj_set_style_bg_color(menu, lv_color_darken(lv_obj_get_style_bg_color(menu, 0), 10), 0);}else {lv_obj_set_style_bg_color(menu, lv_color_darken(lv_obj_get_style_bg_color(menu, 0), 50), 0);}lv_menu_set_mode_root_back_button(menu, LV_MENU_ROOT_BACK_BUTTON_ENABLED);lv_obj_add_event_cb(menu, back_event_handler, LV_EVENT_CLICKED, menu);lv_obj_set_size(menu, lv_display_get_horizontal_resolution(NULL), lv_display_get_vertical_resolution(NULL));lv_obj_center(menu);lv_obj_t * cont;lv_obj_t * section;/*创建一个子页面*/lv_obj_t * sub_mechanics_page = lv_menu_page_create(menu, NULL);lv_obj_set_style_pad_hor(sub_mechanics_page, lv_obj_get_style_pad_left(lv_menu_get_main_header(menu), 0), 0);lv_menu_separator_create(sub_mechanics_page);section = lv_menu_section_create(sub_mechanics_page);create_slider(section, LV_SYMBOL_SETTINGS, "Velocity", 0, 150, 120);create_slider(section, LV_SYMBOL_SETTINGS, "Acceleration", 0, 150, 50);create_slider(section, LV_SYMBOL_SETTINGS, "Weight limit", 0, 150, 80);lv_obj_t * sub_sound_page = lv_menu_page_create(menu, NULL);lv_obj_set_style_pad_hor(sub_sound_page, lv_obj_get_style_pad_left(lv_menu_get_main_header(menu), 0), 0);lv_menu_separator_create(sub_sound_page);section = lv_menu_section_create(sub_sound_page);create_switch(section, LV_SYMBOL_AUDIO, "Sound", false);lv_obj_t * sub_display_page = lv_menu_page_create(menu, NULL);lv_obj_set_style_pad_hor(sub_display_page, lv_obj_get_style_pad_left(lv_menu_get_main_header(menu), 0), 0);lv_menu_separator_create(sub_display_page);section = lv_menu_section_create(sub_display_page);create_slider(section, LV_SYMBOL_SETTINGS, "Brightness", 0, 150, 100);lv_obj_t * sub_software_info_page = lv_menu_page_create(menu, NULL);lv_obj_set_style_pad_hor(sub_software_info_page, lv_obj_get_style_pad_left(lv_menu_get_main_header(menu), 0), 0);section = lv_menu_section_create(sub_software_info_page);create_text(section, NULL, "Version 1.0", LV_MENU_ITEM_BUILDER_VARIANT_1);lv_obj_t * sub_legal_info_page = lv_menu_page_create(menu, NULL);lv_obj_set_style_pad_hor(sub_legal_info_page, lv_obj_get_style_pad_left(lv_menu_get_main_header(menu), 0), 0);section = lv_menu_section_create(sub_legal_info_page);for(uint32_t i = 0; i < 15; i++) {create_text(section, NULL,"This is a long long long long long long long long long text, if it is long enough it may scroll.",LV_MENU_ITEM_BUILDER_VARIANT_1);}lv_obj_t * sub_about_page = lv_menu_page_create(menu, NULL);lv_obj_set_style_pad_hor(sub_about_page, lv_obj_get_style_pad_left(lv_menu_get_main_header(menu), 0), 0);lv_menu_separator_create(sub_about_page);section = lv_menu_section_create(sub_about_page);cont = create_text(section, NULL, "Software information", LV_MENU_ITEM_BUILDER_VARIANT_1);lv_menu_set_load_page_event(menu, cont, sub_software_info_page);cont = create_text(section, NULL, "Legal information", LV_MENU_ITEM_BUILDER_VARIANT_1);lv_menu_set_load_page_event(menu, cont, sub_legal_info_page);lv_obj_t * sub_menu_mode_page = lv_menu_page_create(menu, NULL);lv_obj_set_style_pad_hor(sub_menu_mode_page, lv_obj_get_style_pad_left(lv_menu_get_main_header(menu), 0), 0);lv_menu_separator_create(sub_menu_mode_page);section = lv_menu_section_create(sub_menu_mode_page);cont = create_switch(section, LV_SYMBOL_AUDIO, "Sidebar enable", true);lv_obj_add_event_cb(lv_obj_get_child(cont, 2), switch_handler, LV_EVENT_VALUE_CHANGED, menu);/*创建根页面*/root_page = lv_menu_page_create(menu, "Settings");lv_obj_set_style_pad_hor(root_page, lv_obj_get_style_pad_left(lv_menu_get_main_header(menu), 0), 0);section = lv_menu_section_create(root_page);cont = create_text(section, LV_SYMBOL_SETTINGS, "Mechanics", LV_MENU_ITEM_BUILDER_VARIANT_1);lv_menu_set_load_page_event(menu, cont, sub_mechanics_page);cont = create_text(section, LV_SYMBOL_AUDIO, "Sound", LV_MENU_ITEM_BUILDER_VARIANT_1);lv_menu_set_load_page_event(menu, cont, sub_sound_page);cont = create_text(section, LV_SYMBOL_SETTINGS, "Display", LV_MENU_ITEM_BUILDER_VARIANT_1);lv_menu_set_load_page_event(menu, cont, sub_display_page);create_text(root_page, NULL, "Others", LV_MENU_ITEM_BUILDER_VARIANT_1);section = lv_menu_section_create(root_page);cont = create_text(section, NULL, "About", LV_MENU_ITEM_BUILDER_VARIANT_1);lv_menu_set_load_page_event(menu, cont, sub_about_page);cont = create_text(section, LV_SYMBOL_SETTINGS, "Menu mode", LV_MENU_ITEM_BUILDER_VARIANT_1);lv_menu_set_load_page_event(menu, cont, sub_menu_mode_page);lv_menu_set_sidebar_page(menu, root_page);lv_obj_send_event(lv_obj_get_child(lv_obj_get_child(lv_menu_get_cur_sidebar_page(menu), 0), 0), LV_EVENT_CLICKED,NULL);
}static void back_event_handler(lv_event_t * e)
{lv_obj_t * obj = lv_event_get_target(e);lv_obj_t * menu = lv_event_get_user_data(e);if(lv_menu_back_button_is_root(menu, obj)) {lv_obj_t * mbox1 = lv_msgbox_create(NULL);lv_msgbox_add_title(mbox1, "Hello");lv_msgbox_add_text(mbox1, "Root back btn click.");lv_msgbox_add_close_button(mbox1);}
}static void switch_handler(lv_event_t * e)
{lv_event_code_t code = lv_event_get_code(e);lv_obj_t * menu = lv_event_get_user_data(e);lv_obj_t * obj = lv_event_get_target(e);if(code == LV_EVENT_VALUE_CHANGED) {if(lv_obj_has_state(obj, LV_STATE_CHECKED)) {lv_menu_set_page(menu, NULL);lv_menu_set_sidebar_page(menu, root_page);lv_obj_send_event(lv_obj_get_child(lv_obj_get_child(lv_menu_get_cur_sidebar_page(menu), 0), 0), LV_EVENT_CLICKED,NULL);}else {lv_menu_set_sidebar_page(menu, NULL);lv_menu_clear_history(menu); /* Clear history because we will be showing the root page later */lv_menu_set_page(menu, root_page);}}
}static lv_obj_t * create_text(lv_obj_t * parent, const char * icon, const char * txt,lv_menu_builder_variant_t builder_variant)
{lv_obj_t * obj = lv_menu_cont_create(parent);lv_obj_t * img = NULL;lv_obj_t * label = NULL;if(icon) {img = lv_image_create(obj);lv_image_set_src(img, icon);}if(txt) {label = lv_label_create(obj);lv_label_set_text(label, txt);lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR);lv_obj_set_flex_grow(label, 1);}if(builder_variant == LV_MENU_ITEM_BUILDER_VARIANT_2 && icon && txt) {lv_obj_add_flag(img, LV_OBJ_FLAG_FLEX_IN_NEW_TRACK);lv_obj_swap(img, label);}return obj;
}static lv_obj_t * create_slider(lv_obj_t * parent, const char * icon, const char * txt, int32_t min, int32_t max,int32_t val)
{lv_obj_t * obj = create_text(parent, icon, txt, LV_MENU_ITEM_BUILDER_VARIANT_2);lv_obj_t * slider = lv_slider_create(obj);lv_obj_set_flex_grow(slider, 1);lv_slider_set_range(slider, min, max);lv_slider_set_value(slider, val, LV_ANIM_OFF);if(icon == NULL) {lv_obj_add_flag(slider, LV_OBJ_FLAG_FLEX_IN_NEW_TRACK);}return obj;
}static lv_obj_t * create_switch(lv_obj_t * parent, const char * icon, const char * txt, bool chk)
{lv_obj_t * obj = create_text(parent, icon, txt, LV_MENU_ITEM_BUILDER_VARIANT_1);lv_obj_t * sw = lv_switch_create(obj);lv_obj_add_state(sw, chk ? LV_STATE_CHECKED : 0);return obj;
}#endif

menu5.gif

9、message box(消息框)

#include "../../lv_examples.h"
#if LV_USE_MSGBOX && LV_BUILD_EXAMPLESstatic void event_cb(lv_event_t * e)
{lv_obj_t * btn = lv_event_get_target(e);lv_obj_t * label = lv_obj_get_child(btn, 0);LV_UNUSED(label);LV_LOG_USER("Button %s clicked", lv_label_get_text(label));
}void lv_example_msgbox_1(void)
{lv_obj_t * mbox1 = lv_msgbox_create(NULL);lv_msgbox_add_title(mbox1, "Hello");lv_msgbox_add_text(mbox1, "This is a message box with two buttons.");lv_msgbox_add_close_button(mbox1);lv_obj_t * btn;btn = lv_msgbox_add_footer_button(mbox1, "Apply");lv_obj_add_event_cb(btn, event_cb, LV_EVENT_CLICKED, NULL);btn = lv_msgbox_add_footer_button(mbox1, "Cancel");lv_obj_add_event_cb(btn, event_cb, LV_EVENT_CLICKED, NULL);return;
}#endif

msgbox.gif

10、roller(滚轮)

10.1、示例1
#include "../../lv_examples.h"
#if LV_USE_ROLLER && LV_BUILD_EXAMPLESstatic void event_handler(lv_event_t * e)
{lv_event_code_t code = lv_event_get_code(e);lv_obj_t * obj = lv_event_get_target(e);if(code == LV_EVENT_VALUE_CHANGED) {char buf[32];lv_roller_get_selected_str(obj, buf, sizeof(buf));LV_LOG_USER("Selected month: %s\n", buf);}
}/*** 带有月份名称的无限滚轮*/
void lv_example_roller_1(void)
{lv_obj_t * roller1 = lv_roller_create(lv_screen_active());lv_roller_set_options(roller1,"January\n""February\n""March\n""April\n""May\n""June\n""July\n""August\n""September\n""October\n""November\n""December",LV_ROLLER_MODE_INFINITE);lv_roller_set_visible_row_count(roller1, 4);lv_obj_center(roller1);lv_obj_add_event_cb(roller1, event_handler, LV_EVENT_ALL, NULL);
}#endif

roller.gif

10.2、示例2
#include "../../lv_examples.h"
#if LV_USE_ROLLER && LV_FONT_MONTSERRAT_14 && LV_BUILD_EXAMPLESstatic void event_handler(lv_event_t * e)
{lv_event_code_t code = lv_event_get_code(e);lv_obj_t * obj = lv_event_get_target(e);if(code == LV_EVENT_VALUE_CHANGED) {char buf[32];lv_roller_get_selected_str(obj, buf, sizeof(buf));LV_LOG_USER("Selected value: %s", buf);}
}/*** 所选区域中具有各种对齐方式和较大文本的滚轮*/
void lv_example_roller_2(void)
{/*使所选选项更大的样式*/static lv_style_t style_sel;lv_style_init(&style_sel);lv_style_set_text_font(&style_sel, &lv_font_montserrat_14);lv_style_set_bg_color(&style_sel, lv_color_hex3(0xf88));lv_style_set_border_width(&style_sel, 2);lv_style_set_border_color(&style_sel, lv_color_hex3(0xf00));const char * opts = "1\n2\n3\n4\n5\n6\n7\n8\n9\n10";lv_obj_t * roller;/*左侧的滚轮,带有左对齐文本和自定义宽度*/roller = lv_roller_create(lv_screen_active());lv_roller_set_options(roller, opts, LV_ROLLER_MODE_NORMAL);lv_roller_set_visible_row_count(roller, 2);lv_obj_set_width(roller, 100);lv_obj_add_style(roller, &style_sel, LV_PART_SELECTED);lv_obj_set_style_text_align(roller, LV_TEXT_ALIGN_LEFT, 0);lv_obj_set_style_bg_color(roller, lv_color_hex3(0x0f0), 0);lv_obj_set_style_bg_grad_color(roller, lv_color_hex3(0xafa), 0);lv_obj_set_style_bg_grad_dir(roller, LV_GRAD_DIR_VER, 0);lv_obj_align(roller, LV_ALIGN_LEFT_MID, 10, 0);lv_obj_add_event_cb(roller, event_handler, LV_EVENT_ALL, NULL);lv_roller_set_selected(roller, 2, LV_ANIM_OFF);/*中间有一个滚轮,文本居中对齐,宽度自动(默认)*/roller = lv_roller_create(lv_screen_active());lv_roller_set_options(roller, opts, LV_ROLLER_MODE_NORMAL);lv_roller_set_visible_row_count(roller, 3);lv_obj_add_style(roller, &style_sel, LV_PART_SELECTED);lv_obj_align(roller, LV_ALIGN_CENTER, 0, 0);lv_obj_add_event_cb(roller, event_handler, LV_EVENT_ALL, NULL);lv_roller_set_selected(roller, 5, LV_ANIM_OFF);/*右侧的滚轮具有右对齐的文本和自定义宽度*/roller = lv_roller_create(lv_screen_active());lv_roller_set_options(roller, opts, LV_ROLLER_MODE_NORMAL);lv_roller_set_visible_row_count(roller, 4);lv_obj_set_width(roller, 80);lv_obj_add_style(roller, &style_sel, LV_PART_SELECTED);lv_obj_set_style_text_align(roller, LV_TEXT_ALIGN_RIGHT, 0);lv_obj_align(roller, LV_ALIGN_RIGHT_MID, -10, 0);lv_obj_add_event_cb(roller, event_handler, LV_EVENT_ALL, NULL);lv_roller_set_selected(roller, 8, LV_ANIM_OFF);
}#endif

修改LV_FONT_MONTSERRAT_22 为1:
roller2.gif

10.3、示例3
#include "../../lv_examples.h"
//TODO
#if LV_USE_ROLLER && LV_DRAW_SW_COMPLEX && LV_BUILD_EXAMPLES && 0static void mask_event_cb(lv_event_t * e)
{lv_event_code_t code = lv_event_get_code(e);lv_obj_t * obj = lv_event_get_target(e);static int16_t mask_top_id = -1;static int16_t mask_bottom_id = -1;if(code == LV_EVENT_COVER_CHECK) {lv_event_set_cover_res(e, LV_COVER_RES_MASKED);}else if(code == LV_EVENT_DRAW_MAIN_BEGIN) {/* 添加蒙版 */const lv_font_t * font = lv_obj_get_style_text_font(obj, LV_PART_MAIN);int32_t line_space = lv_obj_get_style_text_line_space(obj, LV_PART_MAIN);int32_t font_h = lv_font_get_line_height(font);lv_area_t roller_coords;lv_obj_get_coords(obj, &roller_coords);lv_area_t rect_area;rect_area.x1 = roller_coords.x1;rect_area.x2 = roller_coords.x2;rect_area.y1 = roller_coords.y1;rect_area.y2 = roller_coords.y1 + (lv_obj_get_height(obj) - font_h - line_space) / 2;lv_draw_mask_fade_param_t * fade_mask_top = lv_malloc(sizeof(lv_draw_mask_fade_param_t));lv_draw_mask_fade_init(fade_mask_top, &rect_area, LV_OPA_TRANSP, rect_area.y1, LV_OPA_COVER, rect_area.y2);mask_top_id = lv_draw_mask_add(fade_mask_top, NULL);rect_area.y1 = rect_area.y2 + font_h + line_space - 1;rect_area.y2 = roller_coords.y2;lv_draw_mask_fade_param_t * fade_mask_bottom = lv_malloc(sizeof(lv_draw_mask_fade_param_t));lv_draw_mask_fade_init(fade_mask_bottom, &rect_area, LV_OPA_COVER, rect_area.y1, LV_OPA_TRANSP, rect_area.y2);mask_bottom_id = lv_draw_mask_add(fade_mask_bottom, NULL);}else if(code == LV_EVENT_DRAW_POST_END) {lv_draw_mask_fade_param_t * fade_mask_top = lv_draw_mask_remove_id(mask_top_id);lv_draw_mask_fade_param_t * fade_mask_bottom = lv_draw_mask_remove_id(mask_bottom_id);lv_draw_mask_free_param(fade_mask_top);lv_draw_mask_free_param(fade_mask_bottom);lv_free(fade_mask_top);lv_free(fade_mask_bottom);mask_top_id = -1;mask_bottom_id = -1;}
}/*** 给滚筒添加淡入淡出蒙版*/
void lv_example_roller_3(void)
{static lv_style_t style;lv_style_init(&style);lv_style_set_bg_color(&style, lv_color_black());lv_style_set_text_color(&style, lv_color_white());lv_style_set_border_width(&style, 0);lv_style_set_pad_all(&style, 0);lv_obj_add_style(lv_screen_active(), &style, 0);lv_obj_t * roller1 = lv_roller_create(lv_screen_active());lv_obj_add_style(roller1, &style, 0);lv_obj_set_style_bg_opa(roller1, LV_OPA_TRANSP, LV_PART_SELECTED);#if LV_FONT_MONTSERRAT_22lv_obj_set_style_text_font(roller1, &lv_font_montserrat_22, LV_PART_SELECTED);
#endiflv_roller_set_options(roller1,"January\n""February\n""March\n""April\n""May\n""June\n""July\n""August\n""September\n""October\n""November\n""December",LV_ROLLER_MODE_NORMAL);lv_obj_center(roller1);lv_roller_set_visible_row_count(roller1, 3);lv_obj_add_event_cb(roller1, mask_event_cb, LV_EVENT_ALL, NULL);
}
#endif

TODO,目前还未实现。

三、最后

接下来我们学习最后10个左右的控件就可以在开发板上进行实战了。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/52270.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

完成课题ssrf实现.SSH未创建写shell,同时完成其他漏洞复现

一、SSRF (Server-Side Request Forgery) 是一种网络安全漏洞&#xff0c;发生在服务器端应用程序中&#xff0c;允许攻击者通过服务器向任意网络资源发送请求&#xff0c;而无需用户直接参与。这种漏洞通常源于程序设计错误&#xff0c;例如当应用程序使用用户的输入作为URL请…

根据json字符串 自动生成 实体类 Model Entity .NET

①访问json2csharp的在线工具&#xff1a;http://json2csharp.com/ ②复制json字符串&#xff0c;粘贴到左边&#xff0c;按下面Convert按钮 ③右边就是 生成的 实体类 &#xff0c;直接复制到 .cs文件内就能使用 ④或者点击 Zip As File 按钮&#xff0c;直接生成 N个.cs文…

基于Springboot和BS架构的宠物健康咨询系统pf

TOC springboot509基于Springboot和BS架构的宠物健康咨询系统pf 第一章 课题背景及研究内容 1.1 课题背景 信息数据从传统到当代&#xff0c;是一直在变革当中&#xff0c;突如其来的互联网让传统的信息管理看到了革命性的曙光&#xff0c;因为传统信息管理从时效性&#x…

使用VRoid Studio二次元建模,创建专属于自己的二次元卡通人物模型,创建完全免费开源且属于自己VRM模型

最终效果 文章目录 最终效果什么是VRoid Studio官网地址下载安装VRoid Studio1、可以去它的官网下载2、steam安装 创建模型配置参数 导出模型使用别人的VRM模型这里我分享几个不错的模型&#xff0c;大家可以自行去下载 完结 什么是VRoid Studio 如果你玩过能捏脸的游戏你就能…

游戏开发设计模式之责任链模式

责任链模式&#xff08;Chain of Responsibility Pattern&#xff09;是一种行为型设计模式&#xff0c;它允许将请求沿着处理者链进行发送。每个处理者对象都有机会处理该请求&#xff0c;直到某个处理者决定处理该请求为止。 概念与定义 责任链模式的核心思想是将多个处理器…

【传输层协议】UDP协议 {端口号的范围划分;UDP数据报格式;UDP协议的特点;UDP的缓冲区;基于UDP的应用层协议}

一、再谈端口号 1.1 端口号标识网络进程 如何通过端口号找到主机上的网络进程&#xff1f; 在socket编程中bind绑定是最为重要的一步&#xff1a;他将套接字与指定的本地 IP 地址和端口号关联起来&#xff0c;这意味着指定的套接字可以接收来自指定 IP 地址和端口号的数据包…

前端宝典十:webpack性能优化最佳实践

Webpack 内置了很多功能。 通常你可用如下经验去判断如何配置 Webpack&#xff1a; 想让源文件加入到构建流程中去被 Webpack 控制&#xff0c;配置 entry&#xff1b;想自定义输出文件的位置和名称&#xff0c;配置 output&#xff1b;想自定义寻找依赖模块时的策略&#xff…

java swagger解析解决[malformed or unreadable swagger supplied]

原创不易&#xff0c;转载请注明出处&#xff1a; https://zhangxiaofan.blog.csdn.net/article/details/141498211 如果你想看完整的 利用swagger-parser解析yaml中的api请求类型、注释、接口名&#xff0c;可以参考这篇文章。 【Spring/Java项目】如何利用swagger-parser解析…

NC 最长上升子序列(三)

系列文章目录 文章目录 系列文章目录前言 前言 前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下给大家。点击跳转到网站&#xff0c;这篇文章男女通用&#xff0c;看懂了就去分享给你的码吧。 描述 给定数组 arr…

OpenCV+Python识别机读卡

背景介绍 正常机读卡是通过读卡机读取识别结果的&#xff0c;目前OpenCV已经这么强大了&#xff0c;尝试着用OpenCVPython来识别机读卡。要识别的机读卡长这样&#xff1a; 我们做以下操作&#xff1a; 1.识别答题卡中每题选中项结果。 不做以下操作&#xff1a; 1.不识别准…

宝塔面板配置node/npm/yarn/pm2....相关全局变量 npm/node/XXX: command not found

1.打开终端 , cd 到根目录 cd / 2.跳转至node目录下,我的node版本是v16.14.2 cd /www/server/nodejs/v16.14.2/bin 2.1 如果不知道自己node版本多少就跳转到 cd /www/server/nodejs 然后查找当前目录下的文件 ls 确定自己的node版本 cd /node版本/bin 3.继续查看bin…

秋招突击——8/21——知识补充——计算机网络——cookie、session和token

文章目录 引言正文Cookie——客户端存储和管理Session——服务端存储和管理Token补充签名和加密的区别常见的加密算法和签名算法 面试题1、HTTP用户后续的操作&#xff0c;服务端如何知道属于同一个用户&#xff1f;如果服务端是一个集群机器怎么办&#xff1f;2、如果禁用了Co…

android13隐藏调节声音进度条下面的设置按钮

总纲 android13 rom 开发总纲说明 目录 1.前言 2.情况分析 3.代码修改 4.编译运行 5.彩蛋 1.前言 将下面的声音调节底下的三个点的设置按钮,隐藏掉。 效果如下 2.情况分析 查看布局文件 通过布局我们可以知道这个按钮就是 com.android.keyguard.AlphaOptimizedImageB…

记忆化搜索与状态压缩:优化递归与动态规划的利器

记忆化搜索是解决递归和动态规划问题的一种高效优化技术。它结合了递归的灵活性和动态规划的缓存思想&#xff0c;通过保存已经计算过的子问题结果&#xff0c;避免了重复计算&#xff0c;大幅提升了算法的效率。当问题状态复杂时&#xff0c;状态压缩技术可以进一步优化空间使…

跨域解决 | 面试常问问题

跨域解决 | 面试常问问题 跨域问题一直是前端开发中不可避免的一部分&#xff0c;它涉及到浏览器的同源策略和安全机制。本文将深入解析跨域问题的本质&#xff0c;并探讨前端和后端的多种解决方案&#xff0c;同时分享一些扩展与高级技巧。最后&#xff0c;我们还将总结跨域解…

UE基础 —— Components

目录 Component Instancing Instanced Static Mesh Component Instanced Static Mesh Differences of an ISM and a Static Mesh Component Hierarchical Instanced Static Mesh Instancing Systems Working with ISMs Prefabrication Custom Data Creating and Edit…

ElasticSearch 8.15.0 与 Kibana 8.15.0 尝鲜体验

还不算晚&#xff0c;虽然已经距离发布过去了快半个月~ 跟着下面的步骤进行一步一步操作(CV)&#xff0c;只需要改动一下用户名、密码这些数据即可从零开始用 Docker安装 ES 与 Kibana 最新版&#xff0c;据说 Kibana 还有 AI 助手嘞(虽然是 8.12 推出的)~ 最后强调一点&#…

自动化开发流程:使用 GitHub Actions 进行 CI/CD

在现代软件开发过程中&#xff0c;持续集成&#xff08;Continuous Integration, CI&#xff09;和持续部署&#xff08;Continuous Deployment, CD&#xff09;是确保高质量软件交付的关键组成部分。GitHub Actions 提供了一种简便的方式来实现 CI/CD 流程的自动化。本文将介绍…

Unity XR Interaction Toolkit 通过两个手柄控制物体放大缩小

1&#xff1a;给物体添加 XR General Grab Transformer 脚本 2&#xff1a;XR Grab Interactable 的 select mode 选择 Multiple

java-队列--黑马

队列 别看这个&#xff0c;没用&#xff0c;还是多刷力扣队列题 定义 队列是以顺序的方式维护一组数据的集合&#xff0c;在一端添加数据&#xff0c;从另一端移除数据。一般来讲&#xff0c;添加的一端称之尾&#xff0c;而移除一端称为头 。 队列接口定义 // 队列的接口定…