1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// SPDX-License-Identifier: MIT OR Apache-2.0
//! Layout methods (flex, grid) for [`Obj`]. These are `impl` blocks on the
//! same type defined in `obj.rs` — no new types introduced.
use core::ptr::null_mut;
use oxivgl_sys::*;
use super::obj::Obj;
use crate::layout::{FlexAlign, FlexFlow, GridAlign, GridCell};
impl<'p> Obj<'p> {
/// Set flex layout flow direction.
pub fn set_flex_flow(&self, flow: FlexFlow) -> &Self {
assert_ne!(self.handle(), null_mut());
// SAFETY: handle non-null (asserted above).
unsafe { lv_obj_set_flex_flow(self.handle(), flow as lv_flex_flow_t) };
self
}
/// Set flex alignment (main, cross, track).
pub fn set_flex_align(&self, main: FlexAlign, cross: FlexAlign, track: FlexAlign) -> &Self {
assert_ne!(self.handle(), null_mut());
// SAFETY: handle non-null (asserted above).
unsafe {
lv_obj_set_flex_align(
self.handle(),
main as lv_flex_align_t,
cross as lv_flex_align_t,
track as lv_flex_align_t,
)
};
self
}
/// Set flex grow factor for this child.
pub fn set_flex_grow(&self, grow: u8) -> &Self {
assert_ne!(self.handle(), null_mut());
// SAFETY: handle non-null (asserted above).
unsafe { lv_obj_set_flex_grow(self.handle(), grow) };
self
}
/// Set the layout engine (flex or grid).
pub fn set_layout(&self, layout: crate::layout::Layout) -> &Self {
assert_ne!(self.handle(), null_mut());
// SAFETY: handle non-null (asserted above).
unsafe { lv_obj_set_layout(self.handle(), layout as u32) };
self
}
/// Set grid column/row descriptors and enable grid layout.
/// The slices must be `'static` — LVGL stores the pointers internally.
pub fn set_grid_dsc_array(&self, col_dsc: &'static [i32], row_dsc: &'static [i32]) -> &Self {
assert_ne!(self.handle(), null_mut());
// SAFETY: handle non-null (asserted above); slices are 'static.
unsafe { lv_obj_set_grid_dsc_array(self.handle(), col_dsc.as_ptr(), row_dsc.as_ptr()) };
self
}
/// Place this child in a grid cell (column + row placement).
pub fn set_grid_cell(&self, col: GridCell, row: GridCell) -> &Self {
assert_ne!(self.handle(), null_mut());
// SAFETY: handle non-null (asserted above).
unsafe {
lv_obj_set_grid_cell(
self.handle(),
col.align as lv_grid_align_t,
col.pos,
col.span,
row.align as lv_grid_align_t,
row.pos,
row.span,
)
};
self
}
/// Set grid content alignment (column and row axes).
pub fn set_grid_align(&self, col_align: GridAlign, row_align: GridAlign) -> &Self {
assert_ne!(self.handle(), null_mut());
// SAFETY: handle non-null (asserted above).
unsafe { lv_obj_set_grid_align(self.handle(), col_align as lv_grid_align_t, row_align as lv_grid_align_t) };
self
}
}