22
22
"""
23
23
24
24
# 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
26
26
27
27
28
28
import math
36
36
37
37
from adafruit_display_text import bitmap_label
38
38
from adafruit_displayio_layout .widgets .widget import Widget
39
+ from terminalio import FONT as terminalio_FONT
39
40
40
41
41
42
class Dial (Widget ):
@@ -44,13 +45,15 @@ class Dial(Widget):
44
45
:param int x: pixel position
45
46
:param int y: pixel position
46
47
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
49
50
:param int padding: keepout padding amount around the border, in pixels
50
51
51
52
:param float sweep_angle: dial rotation, in degrees, maximum value is 360 degrees
52
53
: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.
54
57
55
58
:param float min_value: the minimum value displayed on the dial
56
59
:param float max_value: the maximum value displayed the dial
@@ -97,8 +100,6 @@ class Dial(Widget):
97
100
98
101
See file: ``examples/displayio_layout_dial_simpletest.py``
99
102
100
-
101
-
102
103
.. figure:: dial.gif
103
104
:scale: 100 %
104
105
:figwidth: 50%
@@ -135,6 +136,22 @@ class Dial(Widget):
135
136
136
137
Diagram showing the various parameters for setting the dial labels
137
138
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.
138
155
"""
139
156
140
157
# The dial is a subclass of Group->Widget.
@@ -143,7 +160,7 @@ def __init__(
143
160
self ,
144
161
width = 100 ,
145
162
height = 100 ,
146
- padding = 0 , # keepout amount around border, in pixels
163
+ padding = 12 , # keepout amount around border, in pixels
147
164
sweep_angle = 90 , # maximum value is 180 degrees
148
165
start_angle = None ,
149
166
clip_needle = False ,
@@ -198,7 +215,10 @@ def __init__(
198
215
else :
199
216
self ._value = value
200
217
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
202
222
self ._value_color = value_color
203
223
self ._display_value = display_value
204
224
self ._value_format_string = value_format_string
@@ -230,7 +250,10 @@ def __init__(
230
250
231
251
self ._tick_color = tick_color
232
252
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
234
257
self ._tick_label_scale = tick_label_scale
235
258
self ._rotate_tick_labels = rotate_tick_labels
236
259
0 commit comments