Skip to content

Add Widget, Control and WidgetLabel class definitions, along with sliding switch and PyPortal example #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4dfdce6
Initial commit with Widget, Control and WidgetLabel class definitions…
kmatch98 Feb 2, 2021
a7eced3
Ran black, somehow failed for widget_label.py
kmatch98 Feb 2, 2021
ff05592
Add orientation and flip to switch, simplify animation functions with…
kmatch98 Feb 3, 2021
634f91c
Ran black and pylint, some cleanup
kmatch98 Feb 3, 2021
14303c8
Update widget name to SwitchRound
kmatch98 Feb 3, 2021
7272941
Change filename of example to remove _horizontal_
kmatch98 Feb 3, 2021
adb2dc0
Use .hidden property of TileGrid to handle text 0/1 display control
kmatch98 Feb 7, 2021
57eb704
Arrange folders to match library standard organization
kmatch98 Feb 7, 2021
bdc1f34
Update example to conform to correct directory structure
kmatch98 Feb 7, 2021
3158d43
Added resize function for compatibility with grid_layout
kmatch98 Feb 9, 2021
8072bb4
Some pylint fixes, delete debug print statements
kmatch98 Feb 9, 2021
bc24846
Initial commit of WidgetAnnotation
kmatch98 Feb 12, 2021
14b2543
Add Dial widget, add example for Switch, Dial and WidgetAnnotation an…
kmatch98 Feb 13, 2021
90c443e
Initial commit with Widget, Control and WidgetLabel class definitions…
kmatch98 Feb 2, 2021
3d6d443
Ran black, somehow failed for widget_label.py
kmatch98 Feb 2, 2021
4e2cfec
Merge branch 'main' of https://github.com/kmatch98/Adafruit_CircuitPy…
kmatch98 Feb 13, 2021
7582f2e
Initial commit with Widget, Control and WidgetLabel class definitions…
kmatch98 Feb 2, 2021
4daff4d
Merge branch 'main' of https://github.com/kmatch98/Adafruit_CircuitPy…
kmatch98 Feb 13, 2021
b8de020
Bring up to date with latest main upstream branch
kmatch98 Feb 13, 2021
4245291
Update to include merged changes from upstream
kmatch98 Feb 13, 2021
57fa93b
Ran black on widgets
kmatch98 Feb 13, 2021
7e4e3a4
Add comments to switch_round, add simpletest switch examples
kmatch98 Feb 14, 2021
e3cd623
Add font option for switch_round WidgetLabel
kmatch98 Feb 14, 2021
7aa9902
Add flip_input widget
kmatch98 Feb 15, 2021
759248d
Add flip_input example
kmatch98 Feb 15, 2021
8c5c397
add font file
kmatch98 Feb 15, 2021
4f62512
Streamline animation for flip_input, adapt to script fonts
kmatch98 Feb 16, 2021
c050b9a
Add easing animations for flip_input
kmatch98 Feb 18, 2021
dac960d
Updated animation redraws to allow springy animations
kmatch98 Feb 19, 2021
a0649d6
Add sphinx docs
kmatch98 Feb 19, 2021
fc9820d
Ran black
kmatch98 Feb 22, 2021
9275175
Update switch_round for new Widget and Control definitions
kmatch98 Feb 22, 2021
4550e20
Added extensive documentation
kmatch98 Feb 23, 2021
1b134ee
ran black
kmatch98 Feb 23, 2021
7184a13
More documentation updates
kmatch98 Feb 23, 2021
7a93cad
Repair bug in setting width
kmatch98 Feb 23, 2021
5f6117f
Add default values to Widget x,y
kmatch98 Feb 23, 2021
fd74f5d
Fix bug in time limit for switch_round animation
kmatch98 Feb 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added adafruit_displayio_layout/widgets/.DS_Store
Binary file not shown.
93 changes: 93 additions & 0 deletions adafruit_displayio_layout/widgets/control.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# SPDX-FileCopyrightText: 2021 Kevin Matocha, Tim Cocks
#
# SPDX-License-Identifier: MIT

"""
`control`
================================================================================
CircuitPython GUI Control Class for touch-related elements

* Author(s): Kevin Matocha

Implementation Notes
--------------------

**Hardware:**

**Software and Dependencies:**

* Adafruit CircuitPython firmware for the supported boards:
https://github.com/adafruit/circuitpython/releases

"""

__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_Layout.git"

# pylint: disable=unsubscriptable-object, unnecessary-pass


class Control:
"""A Control class for responsive elements, including touch response functions.

**IMPORTANT**: The *touch_point* for all functions should be in local coordinates
for this item. That means, any widget should adjust the touchpoint for self.x and
self.y before passing the touchpoint to this set of Control functions.

The Control class uses a state variable **touch_boundary** [x, y, width, height]
that defines the rectangular boundary for touch inputs. The **touch_boundary**
is used by the `contains` function to check when touches are within the Control's
boundary. Note: These **touch_boundary** dimensions are in the Control's local
pixel coordinates. The **x** and **y** values define the upper left corner of the
**touch_boundary**. The **touch_boundary** value should be updated by the sublcass
definiton.

"""

def __init__(
self,
):
self.touch_boundary = (
None # `self.touch_boundary` should be updated by the subclass
)
# Tuple of [x, y, width, height]: [int, int, int, int] all in pixel units
# where x,y define the upper left corner
# and width and height define the size of the `touch_boundary`

def contains(self, touch_point):
"""Checks if the Control was touched. Returns True if the touch_point is within the
Control's touch_boundary.

:param touch_point: x,y location of the screen, converted to local coordinates.
:type touch_point: Tuple[x,y]
:return: Boolean

"""

# Note: if a widget's `scale` property is > 1, be sure to update the
# `touch_boundary` dimensions to accommodate the `scale` factor
if (self.touch_boundary is not None) and (
(
self.touch_boundary[0]
<= touch_point[0]
<= (self.touch_boundary[0] + self.touch_boundary[2])
)
and (
self.touch_boundary[1]
<= touch_point[1]
<= (self.touch_boundary[1] + self.touch_boundary[3])
)
):
return True
return False

# place holder touch_handler response functions
def selected(self, touch_point):
"""Response function when Control is selected. Should be overridden by subclass.

:param touch_point: x,y location of the screen, converted to local coordinates.
:type touch_point: Tuple[x,y]
:return: None

"""
pass
Loading