Skip to content

Commit d9d96ec

Browse files
committed
updated docstrings, add graphic for clip_needle
1 parent 615dcee commit d9d96ec

File tree

4 files changed

+37
-11
lines changed

4 files changed

+37
-11
lines changed

adafruit_displayio_layout/widgets/dial.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"""
2323

2424
# pylint: disable=too-many-lines, too-many-instance-attributes, too-many-arguments
25-
# pylint: disable=too-many-locals
25+
# pylint: disable=too-many-locals, too-many-statements
2626

2727

2828
import math
@@ -36,6 +36,7 @@
3636

3737
from adafruit_display_text import bitmap_label
3838
from adafruit_displayio_layout.widgets.widget import Widget
39+
from terminalio import FONT as terminalio_FONT
3940

4041

4142
class Dial(Widget):
@@ -44,13 +45,15 @@ class Dial(Widget):
4445
:param int x: pixel position
4546
:param int y: pixel position
4647
47-
:param int width: requested width in pixels
48-
:param int height: requested height in pixels
48+
:param int width: requested width, in pixels
49+
:param int height: requested height, in pixels
4950
:param int padding: keepout padding amount around the border, in pixels
5051
5152
:param float sweep_angle: dial rotation, in degrees, maximum value is 360 degrees
5253
:param float start_angle: starting angle, in degrees. Defaults
53-
to `None` for symmetry along vertical axis
54+
to `None` for symmetry along vertical axis. Vertical is defined as 0 degrees.
55+
Negative values are counter-clockwise degrees; positive values
56+
are clockwise degrees.
5457
5558
:param float min_value: the minimum value displayed on the dial
5659
:param float max_value: the maximum value displayed the dial
@@ -97,8 +100,6 @@ class Dial(Widget):
97100
98101
See file: ``examples/displayio_layout_dial_simpletest.py``
99102
100-
101-
102103
.. figure:: dial.gif
103104
:scale: 100 %
104105
:figwidth: 50%
@@ -135,6 +136,22 @@ class Dial(Widget):
135136
136137
Diagram showing the various parameters for setting the dial labels
137138
and major and minor tick marks.
139+
140+
.. figure:: dial_variables_clip_needle.png
141+
:scale: 35 %
142+
:figwidth: 70%
143+
:align: center
144+
:alt: Diagram showing the impact of ``clip_needle`` Boolean value.
145+
146+
Diagram showing the impact of the ``clip_needle`` input parameter,
147+
with the dial's boundary shown. For ``sweep_angle`` values less than
148+
180 degrees, the needlecan protrude a long way from the dial ticks. By
149+
setting ``clip_needle = True``, the needle graphic will be clipped at the edge
150+
of the dial boundary (see comparison in the graphic above). The left dial is
151+
created with ``clip_needle = False``, meaning that the dial is not clipped. The
152+
right dial is created with ``clip_needle = True`` and the needle is clipped at
153+
the edge of the dial. Use additional ``padding`` to expose more length of
154+
needle, even when clipped.
138155
"""
139156

140157
# The dial is a subclass of Group->Widget.
@@ -143,7 +160,7 @@ def __init__(
143160
self,
144161
width=100,
145162
height=100,
146-
padding=0, # keepout amount around border, in pixels
163+
padding=12, # keepout amount around border, in pixels
147164
sweep_angle=90, # maximum value is 180 degrees
148165
start_angle=None,
149166
clip_needle=False,
@@ -198,7 +215,10 @@ def __init__(
198215
else:
199216
self._value = value
200217

201-
self._value_font = value_font
218+
if value_font is None:
219+
self._value_font = terminalio_FONT
220+
else:
221+
self._value_font = value_font
202222
self._value_color = value_color
203223
self._display_value = display_value
204224
self._value_format_string = value_format_string
@@ -230,7 +250,10 @@ def __init__(
230250

231251
self._tick_color = tick_color
232252
self._tick_label_color = tick_label_color
233-
self._tick_label_font = tick_label_font
253+
if tick_label_font is None:
254+
self._tick_label_font = terminalio_FONT
255+
else:
256+
self._tick_label_font = tick_label_font
234257
self._tick_label_scale = tick_label_scale
235258
self._rotate_tick_labels = rotate_tick_labels
236259

docs/dial_variables_clip_needle.png

66.2 KB
Loading
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SPDX-FileCopyrightText: 2021 Kevin Matocha
2+
3+
SPDX-License-Identifier: MIT

examples/displayio_layout_dial_simpletest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
my_dial = Dial(
2929
x=20, # set x-position of the dial inside of my_group
3030
y=20, # set y-position of the dial inside of my_group
31-
width=180, # requested width of the di
32-
height=180,
31+
width=180, # requested width of the dial
32+
height=180, # requested height of the dial
3333
padding=25, # add 25 pixels around the dial to make room for labels
3434
start_angle=-120, # left angle position at -120 degrees
3535
sweep_angle=240, # total sweep angle of 240 degrees

0 commit comments

Comments
 (0)