lvgl_t113 0.1
t113-s3 86盒的LVGL桌面时钟程序
载入中...
搜索中...
未找到
calender_page.c
浏览该文件的文档.
1
22#include "lvgl/lvgl.h"
23#include <pthread.h>
24#include <time.h>
25#include <sys/time.h>
26#include "calender_page.h"
27#include "home_page.h"
28#include "source/img/home.h"
29
30
31lv_obj_t *Calender_OBJ;
32static lv_coord_t hor_res = 480;
33static lv_coord_t ver_res = 480;
34static lv_coord_t rect_width =(lv_coord_t)((float)480 * 0.2f);
40static void home_img_clicked_callback(lv_event_t *e){
41 LV_LOG_USER("Clicked");
42 // lv_scr_load(HomePage_OBJ);
43 lv_scr_load_anim(HomePage_OBJ, LV_SCR_LOAD_ANIM_FADE_ON, 200, 0, false);
44}
45
50static void clock_calender_task_callback(lv_timer_t *timer){
51 static time_t unix_time;
52 static struct tm *time_info;
53 unix_time = time(NULL);
54 time_info = localtime(&unix_time);
55 uint32_t year = time_info->tm_year + 1900;
56 uint32_t month = time_info->tm_mon + 1;
57 uint32_t day = time_info->tm_mday;
58 printf("year:%d,month:%d,day:%d\n", year, month, day);
59 lv_obj_t *calendar_obj=(lv_obj_t *)(timer->user_data);
60 lv_calendar_set_today_date(calendar_obj, year, month, day);
61 lv_calendar_set_showed_date(calendar_obj, year, month);
62 printf("set date\n");
63}
68void CalenderPage(void)
69{
70
71 static time_t unix_time;
72 static struct tm *time_info;
73 unix_time = time(NULL);
74 time_info = localtime(&unix_time);
75 uint32_t year = time_info->tm_year + 1900;
76 uint32_t month = time_info->tm_mon + 1;
77 uint32_t day = time_info->tm_mday;
78 printf("year:%d,month:%d,day:%d\n", year, month, day);
79 if (lv_obj_get_parent(Calender_OBJ)!=NULL) {
80 lv_obj_del(Calender_OBJ);
81 printf("del\n");
82 Calender_OBJ = NULL; // 确保指针重置
83 }
84 Calender_OBJ = lv_obj_create(NULL);
85 lv_obj_t *calendar_obj = lv_calendar_create(Calender_OBJ);
86 static lv_style_t style_rect_back;
87 lv_style_init(&style_rect_back); // 初始化样式
88 lv_style_set_bg_color(&style_rect_back, lv_color_hex(0xf0e6e8));
89 lv_obj_add_style(Calender_OBJ, &style_rect_back, 0);
90 lv_obj_set_size(calendar_obj, (ver_res-rect_width)*0.7, hor_res*0.7);
91 lv_obj_align(calendar_obj, LV_ALIGN_TOP_LEFT,(ver_res-rect_width-(ver_res-rect_width)*0.7)/2, (hor_res-hor_res*0.7)/2);
92 // lv_obj_add_event_cb(calendar_obj, event_handler, LV_EVENT_ALL, NULL);
93 lv_calendar_set_today_date(calendar_obj, year, month, day);
94 lv_calendar_set_showed_date(calendar_obj, year, month);
95 lv_calendar_header_dropdown_create(calendar_obj);
96 lv_timer_t *claender_task_timer = lv_timer_create(clock_calender_task_callback, 1000, calendar_obj); // 创建定时任务,200ms刷新一次
97
98 static lv_style_t style_rect;
99 lv_obj_t *rect;
100 lv_color_t c = lv_color_hex(0xb4848c); // 修改颜色值
101 lv_style_init(&style_rect); // 初始化样式
102 lv_style_set_bg_color(&style_rect, c); // 设置颜色
103 lv_style_set_width(&style_rect, rect_width); // 设置宽度
104 lv_style_set_height(&style_rect, ver_res); // 设置高度
105 lv_style_set_radius(&style_rect, 0); // 设置圆角
106 // lv_style_set_opa(&style_rect,LV_OPA_COVER); //设置透明度
107 lv_style_set_shadow_width(&style_rect, 25); // 设置阴影宽度
108 lv_style_set_shadow_ofs_x(&style_rect, -3); // 设置水平偏移
109 // lv_style_set_shadow_color(&style_rect,lv_palette_main(LV_PALETTE_NONE));//设置阴影颜色
110 lv_style_set_border_width(&style_rect, 0); // 设置边框宽度
111 rect = lv_obj_create(Calender_OBJ);
112 lv_obj_align(rect, LV_ALIGN_TOP_RIGHT, 0, 0);
113 lv_obj_add_style(rect, &style_rect, 0);
114
115 lv_obj_t *home_img_btn = lv_imgbtn_create(Calender_OBJ); // 创建在当前活动的屏幕
116 // 设置正常状态下的图片
117 lv_imgbtn_set_src(home_img_btn, LV_IMGBTN_STATE_RELEASED, &home, NULL, NULL);
118 // lv_imgbtn_set_src(calendar_img_btn, LV_IMGBTN_STATE_CHECKED_RELEASED, NULL, &calendar, NULL);
119 lv_obj_align(home_img_btn, LV_ALIGN_TOP_RIGHT, -1 * rect_width / 2.0 + 64 / 2, ver_res / 2.0 - 64 / 2);
120 lv_obj_set_size(home_img_btn, 64, 64);
121 lv_obj_add_event_cb(home_img_btn, home_img_clicked_callback, LV_EVENT_CLICKED, NULL);
122
123}
static lv_coord_t ver_res
static void clock_calender_task_callback(lv_timer_t *timer)
时钟定时触发回调
static lv_coord_t hor_res
void CalenderPage(void)
日历页面
lv_obj_t * Calender_OBJ
static lv_coord_t rect_width
static void home_img_clicked_callback(lv_event_t *e)
主页按键触发回调
const lv_img_dsc_t home
定义 home.c:312
lv_obj_t * HomePage_OBJ