Skip to content

Commit a2fdcca

Browse files
committed
Update Widget, Control definitions per review feedback, added documentation and updated api.rst
1 parent faf2588 commit a2fdcca

File tree

3 files changed

+229
-99
lines changed

3 files changed

+229
-99
lines changed

adafruit_displayio_layout/widgets/control.py

100755100644
Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: 2021 Kevin Matocha
1+
# SPDX-FileCopyrightText: 2021 Kevin Matocha, Tim Cocks
22
#
33
# SPDX-License-Identifier: MIT
44

@@ -21,19 +21,26 @@
2121
2222
"""
2323

24-
# pylint: disable=unnecessary-pass
25-
2624
__version__ = "0.0.0-auto.0"
2725
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_Layout.git"
2826

27+
# pylint: disable=unsubscriptable-object, unnecessary-pass
28+
2929

3030
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.
3332
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.
3744
3845
"""
3946

@@ -43,17 +50,22 @@ def __init__(
4350
self.touch_boundary = (
4451
None # `self.touch_boundary` should be updated by the subclass
4552
)
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`
4656

4757
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.
5260
5361
:param touch_point: x,y location of the screen, converted to local coordinates.
62+
:type touch_point: Tuple[x,y]
5463
:return: Boolean
5564
5665
"""
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
5769
if (self.touch_boundary is not None) and (
5870
(
5971
self.touch_boundary[0]
@@ -74,34 +86,7 @@ def selected(self, touch_point):
7486
"""Response function when Control is selected. Should be overridden by subclass.
7587
7688
: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]
10590
:return: None
10691
10792
"""

0 commit comments

Comments
 (0)