1
- # SPDX-FileCopyrightText: 2021 Kevin Matocha
1
+ # SPDX-FileCopyrightText: 2021 Kevin Matocha, Tim Cocks
2
2
#
3
3
# SPDX-License-Identifier: MIT
4
4
21
21
22
22
"""
23
23
24
- # pylint: disable=unnecessary-pass
25
-
26
24
__version__ = "0.0.0-auto.0"
27
25
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_Layout.git"
28
26
27
+ # pylint: disable=unsubscriptable-object, unnecessary-pass
28
+
29
29
30
30
class Control :
31
- """A Control class for responsive elements, including several response functions,
32
- including for touch response.
31
+ """A Control class for responsive elements, including touch response functions.
33
32
34
- **IMPORTANT**: The *touch_point* for all functions should be in local coordinates for this item.
35
- That means, any widget should adjust for self.x and self.y before passing
36
- the touchpoint up to this superclass function.
33
+ **IMPORTANT**: The *touch_point* for all functions should be in local coordinates
34
+ for this item. That means, any widget should adjust the touchpoint for self.x and
35
+ self.y before passing the touchpoint to this set of Control functions.
36
+
37
+ The Control class uses a state variable **touch_boundary** [x, y, width, height]
38
+ that defines the rectangular boundary for touch inputs. The **touch_boundary**
39
+ is used by the `contains` function to check when touches are within the Control's
40
+ boundary. Note: These **touch_boundary** dimensions are in the Control's local
41
+ pixel coordinates. The **x** and **y** values define the upper left corner of the
42
+ **touch_boundary**. The **touch_boundary** value should be updated by the sublcass
43
+ definiton.
37
44
38
45
"""
39
46
@@ -43,17 +50,22 @@ def __init__(
43
50
self .touch_boundary = (
44
51
None # `self.touch_boundary` should be updated by the subclass
45
52
)
53
+ # Tuple of [x, y, width, height]: [int, int, int, int] all in pixel units
54
+ # where x,y define the upper left corner
55
+ # and width and height define the size of the `touch_boundary`
46
56
47
57
def contains (self , touch_point ):
48
- # pylint: disable=unsubscriptable-object
49
-
50
- """Checks if the Control was touched. Returns True if the touch_point is
51
- within the Control's touch_boundary.
58
+ """Checks if the Control was touched. Returns True if the touch_point is within the
59
+ Control's touch_boundary.
52
60
53
61
:param touch_point: x,y location of the screen, converted to local coordinates.
62
+ :type touch_point: Tuple[x,y]
54
63
:return: Boolean
55
64
56
65
"""
66
+
67
+ # Note: if a widget's `scale` property is > 1, be sure to update the
68
+ # `touch_boundary` dimensions to accommodate the `scale` factor
57
69
if (self .touch_boundary is not None ) and (
58
70
(
59
71
self .touch_boundary [0 ]
@@ -74,34 +86,7 @@ def selected(self, touch_point):
74
86
"""Response function when Control is selected. Should be overridden by subclass.
75
87
76
88
:param touch_point: x,y location of the screen, converted to local coordinates.
77
- :return: None
78
-
79
- """
80
- pass
81
-
82
- def still_touched (self , touch_point ): # *** this needs a clearer name
83
- """Response function when Control remains touched. Should be overridden by subclass.
84
-
85
- :param touch_point: x,y location of the screen, converted to local coordinates.
86
- :return: None
87
-
88
- """
89
- pass
90
-
91
- def released (self , touch_point ):
92
- """Response function when Control is released. Should be overridden by subclass.
93
-
94
- :param touch_point: x,y location of the screen, converted to local coordinates.
95
- :return: None
96
-
97
- """
98
- pass
99
-
100
- def gesture_response (self , gesture ):
101
- """Response function to handle gestures (for future expansion). Should be
102
- overridden by subclass.
103
-
104
- :param gesture: To be defined
89
+ :type touch_point: Tuple[x,y]
105
90
:return: None
106
91
107
92
"""
0 commit comments