回到main.c,下面可以来跑一个demo【网上找的,别人写的----->CV攻城狮(自豪)】了:/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
static void btn_event_cb(lv_event_t * event)
{
lv_obj_t *btn = lv_event_get_target(event); //获得事件最初瞄准的对象。即使事件是冒泡的,也是一样的。
if(event->code == LV_EVENT_CLICKED)
{
static uint8_t cnt = 0;
cnt++;
/*Get the first child of the button which is the label and change its text*/
lv_obj_t * label = lv_obj_get_child(btn, NULL);
lv_label_set_text_fmt(label, "Button: %d", cnt);
}
}
static void lvgl_first_demo_start(void)
{
lv_obj_t * btn = lv_btn_create(lv_scr_act()); /*Add a button the current screen*/
lv_obj_set_pos(btn, 10, 10); /*Set its position*/
lv_obj_set_size(btn, 120, 50); /*Set its size*/
lv_obj_add_event_cb(btn, (lv_event_cb_t)btn_event_cb, LV_EVENT_CLICKED, NULL);/*Assign a callback to the button*/
lv_obj_t * label = lv_label_create(btn); /*Add a label to the button*/
lv_label_set_text(label, "Yeah"); /*Set the labels text*/
lv_obj_t * label1 = lv_label_create(lv_scr_act());
lv_label_set_text(label1, "Hello world!");
lv_obj_align(label1, LV_ALIGN_CENTER, 0, 0);
lv_obj_align_to(btn, label1, LV_ALIGN_OUT_TOP_MID, 0, -10);
}
/* USER CODE END 0 */
|