1#
2# Demonstrate cell placement and span
3#
4
5col_dsc = [70, 70, 70, lv.GRID_TEMPLATE.LAST]
6row_dsc = [50, 50, 50, lv.GRID_TEMPLATE.LAST]
7
8# Create a container with grid
9cont = lv.obj(lv.scr_act())
10cont.set_grid_dsc_array(col_dsc, row_dsc)
11cont.set_size(300, 220)
12cont.center()
13
14# Cell to 0;0 and align to the start (left/top) horizontally and vertically too
15obj = lv.obj(cont)
16obj.set_size(lv.SIZE.CONTENT, lv.SIZE.CONTENT)
17obj.set_grid_cell(lv.GRID_ALIGN.START, 0, 1,
18                  lv.GRID_ALIGN.START, 0, 1)
19label = lv.label(obj)
20label.set_text("c0, r0")
21
22# Cell to 1;0 and align to the start (left) horizontally and center vertically too
23obj = lv.obj(cont)
24obj.set_size(lv.SIZE.CONTENT, lv.SIZE.CONTENT)
25obj.set_grid_cell(lv.GRID_ALIGN.START, 1, 1,
26                  lv.GRID_ALIGN.CENTER, 0, 1)
27label = lv.label(obj)
28label.set_text("c1, r0")
29
30# Cell to 2;0 and align to the start (left) horizontally and end (bottom) vertically too
31obj = lv.obj(cont)
32obj.set_size(lv.SIZE.CONTENT, lv.SIZE.CONTENT)
33obj.set_grid_cell(lv.GRID_ALIGN.START, 2, 1,
34                  lv.GRID_ALIGN.END, 0, 1)
35label = lv.label(obj)
36label.set_text("c2, r0")
37
38# Cell to 1;1 but 2 column wide (span = 2).Set width and height to stretched.
39obj = lv.obj(cont)
40obj.set_size(lv.SIZE.CONTENT, lv.SIZE.CONTENT)
41obj.set_grid_cell(lv.GRID_ALIGN.STRETCH, 1, 2,
42                  lv.GRID_ALIGN.STRETCH, 1, 1)
43label = lv.label(obj)
44label.set_text("c1-2, r1")
45
46# Cell to 0;1 but 2 rows tall (span = 2).Set width and height to stretched.
47obj = lv.obj(cont)
48obj.set_size(lv.SIZE.CONTENT, lv.SIZE.CONTENT)
49obj.set_grid_cell(lv.GRID_ALIGN.STRETCH, 0, 1,
50                  lv.GRID_ALIGN.STRETCH, 1, 2)
51label = lv.label(obj)
52label.set_text("c0\nr1-2")
53