Hi,大家好,欢迎来到STM32之littlevGL课堂,我们在上节课中学习了标签控件(lv_label)和LED控件(lv_led),那么这节课继续跟大家学习一个比较简单的控件,废话不多说! 一 有图有真相 没错,你没看错,就是一个很简单的控件! 二 代码分析 void line_test(void) { /*Create an array for the points of the line*/ static lv_point_t line_points[] = { {5, 5}, {70, 70}, {120, 10}, {180, 60}, {240, 10} }; /*Create new style (thick dark blue)*/ static lv_style_t style_line; lv_style_copy(&style_line, &lv_style_plain); style_line.line.color = LV_COLOR_MAKE(0x00, 0x3b, 0x75); style_line.line.width = 3; style_line.line.rounded = 1; /*Copy the previous line and apply the new style*/ lv_obj_t * line1; line1 = lv_line_create(lv_scr_act(), NULL); lv_line_set_points(line1, line_points, 5); /*Set the points*/ lv_line_set_style(line1, LV_LINE_STYLE_MAIN, &style_line); lv_obj_align(line1, NULL, LV_ALIGN_CENTER, 0, 0); } 在屏幕中,左上角我们规定为原点,也就是(0,0),然后横坐标X是水平方向向右变大,纵坐标竖直向下变大,值得说明的是这里不是负增长,大家不要理解成了水平坐标系中的第四象限。 那么我们知道了屏幕或者窗口对应的坐标系就简单多了,我们就可以通过下面的方式设置坐标点,当然坐标点对应的就是我们像素点: static lv_point_t line_points[] = { {5, 5}, {70, 70}, {120, 10}, {180, 60}, {240, 10} }; static lv_style_t style_line; lv_style_copy(&style_line, &lv_style_plain); style_line.line.color = LV_COLOR_MAKE(0x00, 0x3b, 0x75); style_line.line.width = 3; style_line.line.rounded = 1; line1 = lv_line_create(lv_scr_act(), NULL); lv_line_set_points(line1, line_points, 5); /*Set the points*/ lv_line_set_style(line1, LV_LINE_STYLE_MAIN, &style_line); lv_obj_align(line1, NULL, LV_ALIGN_CENTER, 0, 0); lv_line_set_points(line1, line_points, 5); 对了,画水平线和竖直线大家应该会吧~(Tips:保持横坐标相同,或者纵坐标相同~) OK,本节课就到这里,我们下节课学习列表控件,没错,就是可以滑动选择的列表控件! |