LVGL手冊官網
基本對象
概覽
基本對象是顯示空間的基本屬性。基本對象有:
- 座標
- 父對象,子對象
- 屏幕對象
- 圖層
- 樣式
- 事件
- 屬性
- 透明度
- 保護
- 羣組
- 擴展點擊區域
座標
- 設置寬度
lv_obj_set_width(obj, new_width)
功能:設置寬度
參數:
obj 目標對象
new_width 寬度
- 設置高度
lv_obj_set_height(obj, new_height)
功能:設置寬度
參數:
obj 目標對象
new_height 高度
- 設置寬度,高度
lv_obj_set_size(obj, new_width, new_height)
功能:設置寬度
參數:
obj 目標對象
new_width 寬度
new_height 高度
- 設置座標x
lv_obj_set_x(obj, new_x)
- 設置座標y
lv_obj_set_y(obj, new_y)
- 設置座標x,y
lv_obj_set_pos(obj, new_x, new_y)
- 對象對齊(坐上角定點)
lv_obj_align(obj, obj_ref, LV_ALIGN_..., x_shift, y_shift)
功能:對象對齊
參數:
obj 操作對象
obj_ref 參考對象,爲 NULL 時,將對齊父對象。
LV_ALIGN_... 對齊類型
x_shift 對齊之後x軸偏移像素點
y_shift 對齊之後y軸偏移像素點
- 對象對齊(中心點)
lv_obj_align_origo(obj, obj_ref, LV_ALIGN_..., x_shift, y_shift)
用法與 lv_obj_align 相同,區別是 lv_obj_align 對齊左上角頂點, lv_obj_align_origo 對齊中心點。
- 快速對齊
lv_obj_realign(obj)
如果 LV_USE_OBJ_REALIGN
使能,則對齊類型會被存儲,可以直接調用lv_obj_realign(obj)
快速對齊。等同於lv_obj_align
。
- 自動對齊
lv_obj_set_auto_realign(obj, true)
當對象重新設置尺寸時,可以保持對象對齊。
父對象,子對象
- 設置父對象
lv_obj_set_parent(obj, new_parent)
- 獲取父對象
lv_obj_get_parent(obj)
- 獲取子對象
lv_obj_get_child(obj, child_prev)
從前往後獲取父對象 obj 的子對象 child_prev 後的一個子對象。
lv_obj_get_child_back(obj, child_prev)
從後往前獲取父對象 obj 的子對象 child_prev 後的一個子對象。
當第二個參數爲 NULL 時,獲取父對象 obj 第一個子對象。
遍歷子對象demo
lv_obj_t * child;
child = lv_obj_get_child(parent, NULL);
while(child) {
/*使用"子對象" 做一些事情*/
child = lv_obj_get_child(parent, child);
}
- 獲取子對象數
lv_obj_count_children(obj)
- 獲取子對象數(含子對象的子對象數量)
lv_obj_count_children_recursive(obj)