Skip to content

Commit 813b843

Browse files
committed
basic divider_lines argument implementation
1 parent 5312480 commit 813b843

File tree

1 file changed

+96
-24
lines changed

1 file changed

+96
-24
lines changed

adafruit_displayio_layout/layouts/grid_layout.py

Lines changed: 96 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -91,37 +91,109 @@ def _layout_cells(self):
9191
except AttributeError:
9292
# This element does not allow setting width and height.
9393
# No problem, we'll use whatever size it already is.
94-
_measured_width = cell["content"].width
95-
_measured_height = cell["content"].height
94+
# _measured_width = cell["content"].width
95+
# _measured_height = cell["content"].height
9696

9797
pass
9898

99-
cell["content"].x = (
100-
int(grid_position_x * self._width / grid_size_x) + self.cell_padding
101-
)
102-
cell["content"].y = (
103-
int(grid_position_y * self._height / grid_size_y)
104-
+ self.cell_padding
105-
)
106-
107-
palette = displayio.Palette(2)
108-
palette[0] = 0xFFFFFF
109-
palette[1] = 0xFFFFFF
110-
111-
_bottom_divider_line = displayio.Shape(_measured_width, _measured_height, mirror_x=False,
112-
mirror_y=False)
99+
if not hasattr(cell["content"], "anchor_point"):
113100

114-
_bottom_divider_tilegrid = displayio.TileGrid(
115-
_bottom_divider_line, pixel_shader=palette,
116-
y=cell["content"].y + _measured_height)
101+
cell["content"].x = (
102+
int(grid_position_x * self._width / grid_size_x) + self.cell_padding
103+
)
104+
cell["content"].y = (
105+
int(grid_position_y * self._height / grid_size_y) + self.cell_padding
106+
)
107+
else:
108+
print("int({} * {} / {}) + {}".format(grid_position_x, self._width, grid_size_x, self.cell_padding))
109+
print(
110+
"int({} * {} / {}) + {}".format(grid_position_y, self._height, grid_size_y, self.cell_padding))
117111

118-
self._divider_lines.append({
119-
"shape": _bottom_divider_line,
120-
"tilegrid": _bottom_divider_tilegrid
121-
})
112+
cell["content"].anchor_point = (0, 0)
113+
cell["content"].anchored_position = (
114+
int(grid_position_x * self._width / grid_size_x) + self.cell_padding,
115+
int(grid_position_y * self._height / grid_size_y) + self.cell_padding)
116+
print(cell["content"].anchored_position)
117+
print("---")
122118

123119
self.append(cell["content"])
124-
self.append(_bottom_divider_tilegrid)
120+
121+
if self._divider_lines_enabled:
122+
palette = displayio.Palette(2)
123+
palette[0] = 0xFFFFFF
124+
palette[1] = 0xFFFFFF
125+
126+
if not hasattr(cell["content"], "anchor_point"):
127+
_bottom_line_loc_y = cell["content"].y + _measured_height + self.cell_padding
128+
_bottom_line_loc_x = cell["content"].x - self.cell_padding
129+
130+
_top_line_loc_y = cell["content"].y - self.cell_padding
131+
_top_line_loc_x = cell["content"].x - self.cell_padding
132+
133+
_right_line_loc_y = cell["content"].y - self.cell_padding
134+
_right_line_loc_x = cell["content"].x + _measured_width + self.cell_padding
135+
else:
136+
_bottom_line_loc_y = cell["content"].anchored_position[1] + _measured_height + self.cell_padding
137+
_bottom_line_loc_x = cell["content"].anchored_position[0] - self.cell_padding
138+
139+
_top_line_loc_y = cell["content"].anchored_position[1] - self.cell_padding
140+
_top_line_loc_x = cell["content"].anchored_position[0] - self.cell_padding
141+
142+
_right_line_loc_y = cell["content"].anchored_position[1] - self.cell_padding
143+
_right_line_loc_x = cell["content"].anchored_position[0] + _measured_width + self.cell_padding
144+
145+
_horizontal_divider_line = displayio.Shape(
146+
_measured_width + (2 * self.cell_padding),
147+
1,
148+
mirror_x=False, mirror_y=False)
149+
150+
_bottom_divider_tilegrid = displayio.TileGrid(
151+
_horizontal_divider_line, pixel_shader=palette,
152+
y=_bottom_line_loc_y,
153+
x=_bottom_line_loc_x)
154+
155+
_top_divider_tilegrid = displayio.TileGrid(
156+
_horizontal_divider_line, pixel_shader=palette,
157+
y=_top_line_loc_y,
158+
x=_top_line_loc_x)
159+
160+
_vertical_divider_line = displayio.Shape(
161+
1,
162+
_measured_height + (2 * self.cell_padding),
163+
mirror_x=False, mirror_y=False)
164+
165+
_left_divider_tilegrid = displayio.TileGrid(
166+
_vertical_divider_line, pixel_shader=palette,
167+
y=_top_line_loc_y,
168+
x=_top_line_loc_x)
169+
170+
_right_divider_tilegrid = displayio.TileGrid(
171+
_vertical_divider_line, pixel_shader=palette,
172+
y=_right_line_loc_y,
173+
x=_right_line_loc_x)
174+
175+
for line_obj in self._divider_lines:
176+
self.remove(line_obj["tilegrid"])
177+
178+
self._divider_lines.append({
179+
"shape": _horizontal_divider_line,
180+
"tilegrid": _bottom_divider_tilegrid
181+
})
182+
self._divider_lines.append({
183+
"shape": _horizontal_divider_line,
184+
"tilegrid": _top_divider_tilegrid
185+
})
186+
self._divider_lines.append({
187+
"shape": _horizontal_divider_line,
188+
"tilegrid": _left_divider_tilegrid
189+
})
190+
self._divider_lines.append({
191+
"shape": _vertical_divider_line,
192+
"tilegrid": _right_divider_tilegrid
193+
})
194+
195+
for line_obj in self._divider_lines:
196+
self.append(line_obj["tilegrid"])
125197

126198
def add_content(self, cell_content, grid_position, cell_size):
127199
"""Add a child to the grid.

0 commit comments

Comments
 (0)