LVGL官方文档-7.11.0-10-Overview-Layer

Order of creation

默认情况下,老Object绘制在背景,新Object绘制在前景。

举例来说,我们创建一个名为button1的按钮,然后创建一个名为button2的按钮。那么button1及其子Object都会在背景中,并被button2及其子Object覆盖。

在这里插入图片描述

/*Create a screen*/
lv_obj_t * scr = lv_obj_create(NULL, NULL);
lv_scr_load(scr);          /*Load the screen*/

/*Create 2 buttons*/
lv_obj_t * btn1 = lv_btn_create(scr, NULL);         /*Create a button on the screen*/
lv_btn_set_fit(btn1, true, true);                   /*Enable to automatically set the size according to the content*/
lv_obj_set_pos(btn1, 60, 40);              	   /*Set the position of the button*/

lv_obj_t * btn2 = lv_btn_create(scr, btn1);         /*Copy the first button*/
lv_obj_set_pos(btn2, 180, 80);                    /*Set the position of the button*/

/*Add labels to the buttons*/
lv_obj_t * label1 = lv_label_create(btn1, NULL);	/*Create a label on the first button*/
lv_label_set_text(label1, "Button 1");          	/*Set the text of the label*/

lv_obj_t * label2 = lv_label_create(btn2, NULL);  	/*Create a label on the second button*/
lv_label_set_text(label2, "Button 2");            	/*Set the text of the label*/

/*Delete the second label*/
lv_obj_del(label2);

Bring to the foreground

有下面几种方法可以将Object放置到前景。

  • 调用lv_obj_set_top(obj, true)。如果Object或者其任何子Object被点击,LVGL将自动将这个Object放置于前景。这与PC上的GUI类似。当背景中的窗口被点击的时候,它将自动来到前景。
  • 调用lv_obj_move_foreground(obj)明确告知LVGL将一个Object移动到前景。类似的,调用lv_obj_move_background(obj)将Object移动到背景。
  • 当调用lv_obj_set_parent(obj, new_parent)的时候,Object将会被放置于new_parent的前景中。

Top and sys layers

LVGL有两个名称分别为layer_top和layer_sys的特殊Layer。这两个Layer在Display的所有Screen中都是可见和通用的,但是在不同的Display中却不是共享的。layer_top总是在默认Screen的最上层,layer_sys总是在layer_top的最上层。

用户可以用layer_top来创建一些在任何地方都可见的内容,例如菜单栏、弹出窗等等。如果Click属性是能,那么layer_top会吸收用户所有的点击,并且表现的像个对话框。

lv_obj_set_click(lv_layer_top(), true);

在LVGL中layer_sys也用于一样的目的。例如在所有的Layer之上放置鼠标光标以确保其一直可见。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值