-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlayouts.py
More file actions
44 lines (40 loc) · 1.34 KB
/
Copy pathlayouts.py
File metadata and controls
44 lines (40 loc) · 1.34 KB
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
"""
A layout is a list of regions expressed as fractions of the canvas
(x, y, w, h, each 0..1) — fractions rather than pixels so the same layout
name works whether it's being applied to a 250x122 strip or an 800x480
panel. Which layouts make sense for a given device is a judgment call the
dashboard author makes (a tiny mono strip probably shouldn't use grid-4),
not something this module tries to enforce.
"""
LAYOUTS = {
"full": [
(0.0, 0.0, 1.0, 1.0),
],
"split-2h": [ # stacked, top/bottom
(0.0, 0.0, 1.0, 0.5),
(0.0, 0.5, 1.0, 0.5),
],
"split-2v": [ # side by side
(0.0, 0.0, 0.5, 1.0),
(0.5, 0.0, 0.5, 1.0),
],
"grid-4": [
(0.0, 0.0, 0.5, 0.5),
(0.5, 0.0, 0.5, 0.5),
(0.0, 0.5, 0.5, 0.5),
(0.5, 0.5, 0.5, 0.5),
],
}
def regions_for(layout_name: str, width: int, height: int) -> list[tuple[int, int, int, int]]:
"""Returns absolute pixel regions as (x, y, w, h) for the given canvas size."""
fractions = LAYOUTS.get(layout_name)
if fractions is None:
raise ValueError(f"Unknown layout: {layout_name}")
regions = []
for fx, fy, fw, fh in fractions:
x = round(fx * width)
y = round(fy * height)
w = round(fw * width)
h = round(fh * height)
regions.append((x, y, w, h))
return regions