28
28
__version__ = "0.0.0-auto.0"
29
29
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_Layout.git"
30
30
31
+
31
32
class GridLayout (displayio .Group ):
32
33
33
34
"""
@@ -36,16 +37,8 @@ class GridLayout(displayio.Group):
36
37
:param int x: x location the layout should be placed
37
38
:param int y: y location the layout should be placed
38
39
"""
39
- def __init__ (
40
- self ,
41
- x ,
42
- y ,
43
- width ,
44
- height ,
45
- grid_size ,
46
- child_padding ,
47
- max_children = 4
48
- ):
40
+
41
+ def __init__ (self , x , y , width , height , grid_size , child_padding , max_children = 4 ):
49
42
super ().__init__ (x = x , y = y , max_size = max_children )
50
43
self .x = x
51
44
self .y = y
@@ -68,21 +61,37 @@ def _layout_sub_views(self):
68
61
button_size_x = sub_view ["view_grid_size" ][0 ]
69
62
button_size_y = sub_view ["view_grid_size" ][1 ]
70
63
71
- print ("setting width to: {}" .format (
72
- int (button_size_x * self ._width / grid_size_x ) - 2 * self .child_padding ))
73
- sub_view ["view" ].width = int (button_size_x * self ._width / grid_size_x ) - 2 * self .child_padding
74
- sub_view ["view" ].height = int (button_size_y * self ._height / grid_size_y ) - 2 * self .child_padding
75
-
76
- sub_view ["view" ].x = int (grid_position_x * self ._width / grid_size_x ) + self .child_padding
77
- sub_view ["view" ].y = int (grid_position_y * self ._height / grid_size_y ) + self .child_padding
64
+ print (
65
+ "setting width to: {}" .format (
66
+ int (button_size_x * self ._width / grid_size_x )
67
+ - 2 * self .child_padding
68
+ )
69
+ )
70
+ sub_view ["view" ].width = (
71
+ int (button_size_x * self ._width / grid_size_x )
72
+ - 2 * self .child_padding
73
+ )
74
+ sub_view ["view" ].height = (
75
+ int (button_size_y * self ._height / grid_size_y )
76
+ - 2 * self .child_padding
77
+ )
78
+
79
+ sub_view ["view" ].x = (
80
+ int (grid_position_x * self ._width / grid_size_x )
81
+ + self .child_padding
82
+ )
83
+ sub_view ["view" ].y = (
84
+ int (grid_position_y * self ._height / grid_size_y )
85
+ + self .child_padding
86
+ )
78
87
79
88
self .append (sub_view ["view" ])
80
89
81
90
def add_sub_view (self , new_view , grid_position , view_grid_size ):
82
91
sub_view_obj = {
83
92
"view" : new_view ,
84
93
"grid_position" : grid_position ,
85
- "view_grid_size" : view_grid_size
94
+ "view_grid_size" : view_grid_size ,
86
95
}
87
96
self ._sub_views .append (sub_view_obj )
88
97
self ._layout_sub_views ()
0 commit comments