CircuitPython Rotary Slider Library

rotary_slider

Displayio Layout Rotary Slider Widget

  • Author(s): Jose D. Montoya

class rotary_slider.Slider(*args: Any, **kwargs: Any)[source]
Parameters:
  • x (int) – pixel position, defaults to 0

  • y (int) – pixel position, defaults to 0

  • radius (int) – radius of the rotary slider in pixels. It is recommended to use 100

  • touch_padding (int) – the width of an additional border surrounding the switch that extends the touch response boundary. Defaults to 0

  • anchor_point (Tuple[float, float]) – starting point for the annotation line, where anchor_point is an (A,B) tuple in relative units of the size of the widget, for example (0.0, 0.0) is the upper left corner, and (1.0, 1.0) is the lower right corner of the widget. If anchor_point is None, then anchored_position is used to set the annotation line starting point, in widget size relative units. Defaults to (0.0, 0.0)

  • anchored_position (Tuple[int, int]) – pixel position starting point for the annotation line where anchored_position is an (x,y) tuple in pixel units relative to the upper left corner of the widget, in pixel units (default is None).

Quickstart: Importing and using RotarySlider

Here is one way of importing the Slider class so you can use it as the name Slider:

from rotary_slider import Slider

Now you can create a Rotary Slider at pixel position x=20, y=30 using:

my_slider=Slider(x=20, y=30)

Once your setup your display, you can now add my_slider to your display using:

display.show(my_slider) # add the group to the display

If you want to have multiple display elements, you can create a group and then append the slider and the other elements to the group. Then, you can add the full group to the display as in this example:

my_slider= Slider(20, 30)
my_group = displayio.Group() # make a group
my_group.append(my_slider) # Add my_slider to the group

#
# Append other display elements to the group
#

display.show(my_group) # add the group to the display

Summary: Slider Features and input variables

The Slider widget has some options for controlling its position, visible appearance, and value through a collection of input variables:

  • position: x, y or anchor_point and anchored_position

  • size: radius

  • knob color: fill_color, outline_color

  • background color: background_color

  • touch boundaries: touch_padding defines the number of additional pixels surrounding the switch that should respond to a touch. (Note: The touch_padding variable updates the touch_boundary Control class variable. The definition of the touch_boundary is used to determine the region on the Widget that returns True in the when_inside function.)

when_inside(touch_point)[source]

Checks if the Widget was touched.

Parameters:

touch_point – x,y location of the screen, in absolute display coordinates.

Returns:

Boolean

when_selected(touch_point)[source]

Manages internal logic when widget is selected