Skip to content

Commit 5daad48

Browse files
authored
Merge pull request #57 from FoamyGuy/allow_missing_vectorio
allow missing vectorio
2 parents 2d7ba2c + f2142a2 commit 5daad48

File tree

3 files changed

+91
-3
lines changed

3 files changed

+91
-3
lines changed

adafruit_displayio_layout/widgets/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
=======================
88
"""
99

10-
import vectorio
10+
try:
11+
import vectorio
12+
except ImportError:
13+
pass
1114

1215
try:
1316
import bitmaptools

examples/displayio_layout_gridlayout_pygame_display_simpletest.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
#
33
# SPDX-License-Identifier: MIT
44
"""
5-
Make green and purple rectangles and a
6-
"Hello World" label. Displayed with Blinka_Displayio_PyGameDisplay
5+
Make a GridLayout with some Labels in it's cells.
6+
Displayed with Blinka_Displayio_PyGameDisplay
7+
8+
Requires: https://github.com/FoamyGuy/Blinka_Displayio_PyGameDisplay
79
"""
810
import displayio
911
import terminalio
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# SPDX-FileCopyrightText: 2021 Tim C
2+
#
3+
# SPDX-License-Identifier: MIT
4+
"""
5+
Make a GridLayout with some Labels in it's cells.
6+
Displayed with Blinka_Displayio_PyGameDisplay
7+
8+
Requires: https://github.com/FoamyGuy/Blinka_Displayio_PyGameDisplay
9+
"""
10+
import displayio
11+
import pygame
12+
from blinka_displayio_pygamedisplay import PyGameDisplay
13+
from adafruit_displayio_layout.widgets.switch_round import SwitchRound as Switch
14+
15+
16+
# Make the display context. Change size if you want
17+
display = PyGameDisplay(width=320, height=240)
18+
19+
# Make the display context
20+
main_group = displayio.Group()
21+
display.show(main_group)
22+
23+
switch_x = 30
24+
switch_y = 30
25+
switch_radius = 20
26+
27+
switch_fill_color_off = (200, 44, 200)
28+
switch_fill_color_on = (0, 100, 0)
29+
30+
switch_outline_color_off = (30, 30, 30)
31+
switch_outline_color_on = (0, 60, 0)
32+
33+
background_color_off = (255, 255, 255)
34+
background_color_on = (90, 255, 90)
35+
36+
background_outline_color_off = background_color_off
37+
background_outline_color_on = background_color_on
38+
39+
switch_width = 4 * switch_radius # This is a good aspect ratio to start with
40+
41+
switch_stroke = 2 # Width of the outlines (in pixels)
42+
text_stroke = switch_stroke # width of text lines
43+
touch_padding = 0 # Additional boundary around widget that will accept touch input
44+
45+
animation_time = 0.2 # time for switch to display change (in seconds).
46+
# animation_time=0.15 is a good starting point
47+
display_text = True # show the text (0/1)
48+
49+
# initialize state variables
50+
switch_value = False
51+
switch_value = True
52+
53+
my_switch = Switch(
54+
x=switch_x,
55+
y=switch_y,
56+
height=switch_radius * 2,
57+
fill_color_off=switch_fill_color_off,
58+
fill_color_on=switch_fill_color_on,
59+
outline_color_off=switch_outline_color_off,
60+
outline_color_on=switch_outline_color_on,
61+
background_color_off=background_color_off,
62+
background_color_on=background_color_on,
63+
background_outline_color_off=background_outline_color_off,
64+
background_outline_color_on=background_outline_color_on,
65+
switch_stroke=switch_stroke,
66+
display_button_text=display_text,
67+
touch_padding=10,
68+
animation_time=animation_time,
69+
value=False,
70+
)
71+
72+
73+
main_group.append(my_switch)
74+
while display.running:
75+
76+
# get mouse up events
77+
ev = pygame.event.get(eventtype=pygame.MOUSEBUTTONUP)
78+
# proceed events
79+
for event in ev:
80+
pos = pygame.mouse.get_pos()
81+
print(pos)
82+
if my_switch.contains(pos):
83+
my_switch.selected(pos)

0 commit comments

Comments
 (0)