displayio_switchround

A sliding switch widget with a round shape.

  • Author(s): Kevin Matocha

Implementation Notes

Hardware:

Software and Dependencies:

Inheritance

Inheritance diagram of displayio_switchround

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 to None

  • 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 to False, defaults to True

  • flip (bool) – If True the on and off direction will be flipped, default is True

  • 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) green

  • background_color_off (tuple(int,int,int),int) – background off-state color, as an RGB-tuple or 24-bit hex, default is (255, 255, 255) white

  • background_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 green

  • background_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 to background_color_off, default is None

  • 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 to background_color_on, default is None

  • 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 for switch_stroke, default value is None

  • display_button_text (bool) – If True display the 0/1 text shapes on the sliding switch. If False hide the 0/1 text shapes, default value is True

  • 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.

Parameters

touch_point (tuple(int,int)) – x,y location of the screen, in absolute display coordinates.

Returns

None

contains(touch_point)

Checks if the Widget was touched. Returns True if the touch_point is within the Control’s touch_boundary.

Parameters

touch_point (tuple(int,int)) – x,y location of the screen, in absolute display coordinates.

Returns

bool

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.

Parameters

anchor_point (Tuple[float, float]) – In relative units of the Widget size.

property anchored_position

The anchored position (in pixels) for positioning the widget, works in concert with anchor_point. The anchored_position is the x,y pixel position for the placement of the Widget’s anchor_point.

Parameters

anchored_position (Tuple[int, int]) – The (x,y) pixel position for the anchored_position (in pixels).

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

property hidden

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.

resize(new_width, new_height)

Resize the Switch to a new requested width and height.

Parameters
  • new_width (int) – requested maximum width

  • new_height (int) – requested maximum height

Returns

None