displayio_switchround
¶
A sliding switch widget with a round shape.
Author(s): Kevin Matocha
Implementation Notes¶
Hardware:
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://github.com/adafruit/circuitpython/releases
Inheritance¶
- class displayio_switchround.SwitchRound(x=0, y=0, width=None, height=40, touch_padding=0, horizontal=True, flip=False, anchor_point=None, anchored_position=None, fill_color_off=(66, 44, 66), fill_color_on=(0, 100, 0), outline_color_off=(30, 30, 30), outline_color_on=(0, 60, 0), background_color_off=(255, 255, 255), background_color_on=(0, 60, 0), background_outline_color_off=None, background_outline_color_on=None, switch_stroke=2, text_stroke=None, display_button_text=True, animation_time=0.2, value=False, **kwargs)¶
Create a SwitchRound. See Overview for more details.
- Parameters
x (int) – pixel position, defaults to 0
y (int) – pixel position, defaults to 0
width (None,int) – width of the switch in pixels, if set to
None
(recommended) the width will auto-size relative to the height, defaults toNone
height (int) – height of the switch in pixels, defaults to 40 pixels
touch_padding (int) – the width of an additional border surrounding the switch that extends the touch response boundary, defaults to 0
horizontal (bool) – To set vertical orientation, set
horizontal
toFalse
, defaults toTrue
flip (bool) – If
True
the on and off direction will be flipped, default isTrue
anchor_point (None,tuple(float,float)) – (X,Y) values from 0.0 to 1.0 to define the anchor point relative to the switch bounding box, default is
None
anchored_position (None,tuple(int,int)) – (x,y) pixel value for the location of the anchor_point, default is
None
fill_color_off (tuple(int,int,int),int) – switch off-state fill color, as an RGB-tuple or 24-bit hex, default is
(66, 44, 66)
gray.fill_color_on (tuple(int,int,int),int) – switch on-state fill color, as an RGB-tuple or 24-bit hex, default is
(0, 100, 0)
green.outline_color_off (tuple(int,int,int),int) – switch off-state outline color, as an RGB-tuple or 24-bit hex, default is
(30, 30, 30)
dark gray.outline_color_on (tuple(int,int,int),int) – switch on-state outline color, as an RGB-tuple or 24-bit hex, default is
(0, 60, 0)
greenbackground_color_off (tuple(int,int,int),int) – background off-state color, as an RGB-tuple or 24-bit hex, default is
(255, 255, 255)
whitebackground_color_on (tuple(int,int,int),int) – background on-state color, as an RGB-tuple or 24-bit hex, default is
(0, 60, 0)
dark greenbackground_outline_color_off (None,tuple(int,int,int),int) – background outline color in off-state, as an RGB-tuple or 24-bit hex or `None`. If set to
None
this will default tobackground_color_off
, default isNone
background_outline_color_on (None,tuple(int,int,int),int) – background outline color in on-state, as an RGB-tuple or 24-bit hex or `None`. If set to
None
this will default tobackground_color_on
, default isNone
switch_stroke (int) – outline stroke width for the switch and background, in pixels, default is 2
text_stroke (None,int) – outline stroke width (in pixels) for the 0/1 text shape outlines, if set to
None
it will use the value forswitch_stroke
, default value isNone
display_button_text (bool) – If
True
display the 0/1 text shapes on the sliding switch. IfFalse
hide the 0/1 text shapes, default value isTrue
animation_time (float) – time for the switching animation, in seconds, default value is 0.2 seconds.
value (bool) – the initial value for the switch, default is
False
- selected(touch_point)¶
Response function when Switch is selected. When selected, the switch position and value is changed with an animation.
- contains(touch_point)¶
Checks if the Widget was touched. Returns True if the touch_point is within the Control’s touch_boundary.
- property value¶
The current Switch value (Boolean).
- Returns
bool
- property width¶
The width of the Switch (int).
- Returns
int
- property anchor_point¶
The anchor point for positioning the widget, works in concert with
anchored_position
The relative (X,Y) position of the widget where the anchored_position is placed. For example (0.0, 0.0) is the Widget’s upper left corner, (0.5, 0.5) is the Widget’s center point, and (1.0, 1.0) is the Widget’s lower right corner.
- property anchored_position¶
The anchored position (in pixels) for positioning the widget, works in concert with
anchor_point
. Theanchored_position
is the x,y pixel position for the placement of the Widget’sanchor_point
.
- append(layer)¶
Append a layer to the group. It will be drawn above other layers.
- property bounding_box¶
The boundary of the widget. [x, y, width, height] in Widget’s local coordinates (in pixels). (getter only)
- Returns
Tuple[int, int, int, int]
- property height¶
The height of the Switch (int).
- Returns
int
True when the Group and all of it’s layers are not visible. When False, the Group’s layers are visible if they haven’t been hidden.
- index(layer)¶
Returns the index of the first copy of layer. Raises ValueError if not found.
- insert(index, layer)¶
Insert a layer into the group.
- pop(index=- 1)¶
Remove the ith item and return it.
- remove(layer)¶
Remove the first copy of layer. Raises ValueError if it is not present.
- property scale¶
Scales each pixel within the Group in both directions. For example, when scale=2 each pixel will be represented by 2x2 pixels.
- update_transform(parent_transform)¶
Update the parent transform and child transforms
- property x¶
X position of the Group in the parent.
- property y¶
Y position of the Group in the parent.