Circular Slider Widget Documentation
Introduction
A circular slider widget is a graphical user interface component that allows you to input or select a value by rotating a knob or handle along a circular path. This type of slider is often used when there is a natural circular range of values, such as selecting a time, setting a temperature on a thermostat, adjusting volume, or choosing a color hue in a color picker.
This Circular Slider Widget document covers the following topics:
- Creating and customizing circular slider widget using Microchip Graphics Suite (MGS) Harmony Composer
- Circular slider properties
- Handling circular slider widget properties and events through application code
- Circular slider example project
- Application Program Interfaces (APIs) specific to circular slider widgets
Designing Circular Slider Widget
Follow these steps to add a circular slider widget to your design:
Select and drag the circular slider from the Tool Box to your screen designer workspace as shown in Figure 1:
To customize the circular slider, select it on the screen designer and modify its properties using the Object Editor.
The radius of the circular slider, the start and end angle, and the initial value for the circular slider widget can be set using the object editor. These are shown in Figure 2.
The outer and inner borders visibility and their thickness can be set as shown in Figure 3. If the border visibility is turned off, the widget looks as shown in Figure 4.
The active and inactive arc thickness and visibility can be set as shown in Figure 5.
If the Round Edges property for the Active Arc is unchecked, the circular slider active arc will look as shown in Figure 6.
The circular slider has a button that you can maneuver to set the input value. The button visibility, radius, and thickness can be set as shown in Figure 7.
Managing Circular Slider Widget Schemes
Schemes control the look and feel of a widget. For the circular slider, we can set two schemes to define a unique look for the active/inactive arc and the button.
To learn how to set the scheme for a circular slider, click on the button next to the scheme property editor of the Object Editor.
This launches the Circular Slider Scheme Helper window containing tips on how different sections of the scheme color table manipulate various elements of the widget.
Figure 10 shows an example color scheme and the resulting appearance of the circular slider:
The information from the circular slider scheme helper and the example color scheme is summarized in the following table:
Circular Slider Properties
You can set the following properties of the circular slider using the Object Editor.
Name | This will be used to reference the Circular Slider by the application. Example- Screen0_CircularSliderWidget_0. |
Radius | Radius of the circular slider (Refer to Figure 2). |
Start Angle | Starting value for the circular slider (Refer to Figure 2). |
Span Angle | Endling value for the circular slider (Refer to Figure 2). |
Value | Initial value for the circular slider (Refer to Figure 2). |
Outside Border Arc Visible | Sets the visibility of the outer border of the widget (Refer to Figure 3). |
Outside Border Arc Thickness | Sets the thickness of the outer border of the widget (Refer to Figure 3). |
Inside Border Arc Visible | Sets the visibility of the inner border of the widget (Refer to Figure 3). |
Inside Border Arc Thickness | Set the thickness of the inner border of the widget (Refer to Figure 3). |
Active Arc Visible | Sets the visibility of the active region, if the widget spans less than a value of 360 (Refer to Figure 5). |
Active Arc Round Edges | Sets the active region Arc to have a rounded edge (Refer to Figures 5 & 6). |
Active Arc Thickness | Sets the thickness of the active region (Refer to Figure 5). |
Inactive Arc Visible | Sets the visibility of the inactive region (Refer to Figure 5). |
Button Visible | Sets the visibility of the circular slider button. |
Button Radius | Sets the radius of the circular slider button (Refer to Figure 7). |
Button Thickness | Sets the thickness of the border of the circular slider button (Refer to Figure 7). |
Value Changed Event | Will generate an event when the button is moved. |
Pressed Event | Will generate an event when the button is pressed. |
Released Event | Will generate an event when the button is released. |
Managing Circular Slider Widget through Programming
Once the graphical design is completed using MGS Harmony Composer, MCC generates the required code for all the widgets based on the properties set in the Object Editor. To learn more about the process flow between designing a UI and developing application code, refer to the "Designing an Application with Microchip Graphics Suite (MGS)" page.
Let us suppose that a circular slider widget is created with the following properties in MGS Harmony Composer:
For the circular slider widget with the properties shown in the figure above, MCC will automatically generate the following lines of code in src\config\default\gfx\legato\generated\screen\le_gen_screen_Screen0.c:
- A new Circular Slider widget is created by the variable name Screen0_CircularSliderWidget_0.
- Its position is set to pixel location 227x210.
- The widget size is set to have a width of 276 pixels and a height of 260.
- The widget is set to a specific color scheme.
- The button of the widget is set to a unique scheme.
- The radius of the circular slider is set to 80 pixels.
- The outer border visibility is set to false (therefore its thickness is not relevant).
- The inner border visibility is set to false (therefore its thickness is not relevant).
- The arc thickness is set to 32 pixels (refer to Figure 5).
- The button radius is set to 20 pixels.
- The button border thickness is set to 5 pixels.
- The circular slider button is set to a different scheme.
- The setValueChangedEventCallback API adds a callback function when the button is moved. These callback functions are implemented in the application code.
- Finally, the circular slider is added to the screen:
Application Code
The default code generated by MCC sets the initial state of the widget. The property or behavior of the widgets can be changed by using the APIs discussed above, in the application code. Additional application code discussion related to the circular slider widget is presented below.
Here is an example of the onValueChanged callback function that can be added to the application code (in app.c):
* label displays the current value of the circle slider widget passed by the
* val parameter */
void event_Screen0_CircularSliderWidget_0_OnValueChanged(leCircularSliderWidget* sld, int32_t val)
{
memset(cSliderCharBuffer, 0, sizeof(cSliderCharBuffer));
sprintf(cSliderCharBuffer, "%ld", val);
p_SliderValstring.fn->setFromCStr(&p_SliderValstring, cSliderCharBuffer);
Screen0_LabelSliderVal->fn->setString(Screen0_LabelSliderVal, (leString*)&p_SliderValstring);
printf("%ld\r\n", val);
}
Circular Slider Widget Example Project
Refer to the Circular Slider widget example project in GitHub.
In this example, we show:
- How to create a circular slider widget and set its properties as mentioned in the "Circular Slider Properties" section.
- How to handle an onValueChanged event for the circular slider widget. A label is updated based on the value of the circular slider widget.
MGS Simulator Output
The callback function for handling the screen event when the button is moved along the active arc is defined in app.c.
The OnValueChanged function accepts a parameter called 'val', representing the widget's current value. This value is set as a string to the Screen0_LabelSliderVal label. Thus the label value changes when you move the circular slider button along the active arc.
Circular Slider APIs Description
This section describes the APIs specific to the circular slider widget. For a description of APIs common to all widgets, refer to the "Widget APIs Description" section.
getRadius()
Gets radius the radius of the circular slider widget. Refer to Figure 2.
Returns radius.
setRadius()
Sets the circular slider widget radius. Refer to Figure 2.
Parameters
leCircularSliderWidget* | _this | Circular Slider widget pointer to operate on |
uint32 | rad | The circle radius |
Returns LE_SUCCESS or LE_FAILURE.
getStartAngle()
Gets the start angle. Refer to Figure 2.
Returns start angle.
setStartAngle()
Sets the start angle. Refer to Figure 2.
Parameters
leCircularSliderWidget* | _this | Circular Slider widget pointer to operate on |
int32 | ang | The start angle |
Returns LE_SUCCESS or LE_FAILURE.
getSpanAngle()
Gets the span angle of the circular slider. Refer to Figure 2.
Returns span angle.
setSpanAngle()
Sets the span angle of the circular slider. Refer to Figure 2.
Parameters
leCircularSliderWidget* | _this | Circular Slider widget pointer to operate on |
int32 | angle | The span angle |
Returns LE_SUCCESS or LE_FAILURE.
getArcThickness()
Get the arc thickness value. Refer to Figure 5.
Returns arc thickness.
setArcThickness()
Sets the arc thickness value. Refer to Figure 5.
Parameters
leCircularSliderWidget* | _this | Circular Slider widget pointer to operate on |
uint32 | thck | Arc thickness value |
Returns LE_SUCCESS or LE_FAILURE.
getArcRadius()
When the leCircularSliderWidgetArcType is set to CIRCLE_BUTTON, getArcRadius gets the radius of the circular slider button. Refer to Figure 7; else returns the radius based on the leCircularSliderWidgetArcType parameter, which could be - OUTSIDE_CIRCLE_BORDER, INSIDE_CIRCLE_BORDER, ACTIVE_AREA, INACTIVE_AREA, CIRCLE_BUTTON.
Returns radius.
setArcRadius()
When the leCircularSliderWidgetArcType is set to CIRCLE_BUTTON, setArcRadius sets the radius of the circular slider button. Refer to Figure 7.
Parameters
leCircularSliderWidget* | _this | Circular Slider widget pointer to operate on |
leCircularSliderWidgetArcType | type | Type (part of the circular slider widget) - OUTSIDE_CIRCLE_BORDER, INSIDE_CIRCLE_BORDER, ACTIVE_AREA, INACTIVE_AREA, CIRCLE_BUTTON |
uint32_t | rad | Radius to be set |
Returns LE_SUCCESS or LE_FAILURE.
getArcScheme()
Gets the scheme of the circular slider button if the leCircularSliderWidgetArcType is set to CIRCLE_BUTTON.
Returns scheme.
setArcScheme()
leCircularSliderWidgetArcType type, const leScheme* schm)
Sets the scheme of the circular slider button if the leCircularSliderWidgetArcType is set to CIRCLE_BUTTON.
Parameters
leCircularSliderWidget* | _this | Circular Slider widget pointer to operate on |
leCircularSliderWidgetArcType | type | Type (part of the circular slider widget) - OUTSIDE_CIRCLE_BORDER, INSIDE_CIRCLE_BORDER, ACTIVE_AREA, INACTIVE_AREA, CIRCLE_BUTTON |
leScheme* | schm | Scheme |
Returns LE_SUCCESS or LE_FAILURE.
getArcVisible()
leCircularSliderWidgetArcType type)
Gets the visibility of the part of the circular slider widget based on the leCircularSliderWidgetArcType parameter, which could be - OUTSIDE_CIRCLE_BORDER, INSIDE_CIRCLE_BORDER, ACTIVE_AREA, INACTIVE_AREA, CIRCLE_BUTTON.
Returns LE_TRUE or LE_FALSE.
setArcVisible()
leCircularSliderWidgetArcType type,
leBool visible)
Sets the visibility based on the leCircularSliderWidgetArcType parameter, which could be - OUTSIDE_CIRCLE_BORDER, INSIDE_CIRCLE_BORDER, ACTIVE_AREA, INACTIVE_AREA, CIRCLE_BUTTON.
Parameters
leCircularSliderWidget* | _this | Circular Slider widget pointer to operate on |
leCircularSliderWidgetArcType | type | Type (part of the circle slider widget) - OUTSIDE_CIRCLE_BORDER, INSIDE_CIRCLE_BORDER, ACTIVE_AREA, INACTIVE_AREA, CIRCLE_BUTTON |
leBool | visible | LE_TRUE or LE_FALSE |
Returns LE_SUCCESS or LE_FAILURE.
getValue()
Gets the current value of the circular slider widget.
Returns current value.
setValue()
Sets the current value of the circular slider widget.
Parameters
leCircularSliderWidget* | _this | Circular Slider widget pointer to operate on |
int32 | value | The current value |
Returns LE_SUCCESS or LE_FAILURE.
getStartValue()
Gets the start value.
Returns start value.
setStartValue()
Sets the start value.
Parameters
leCircularSliderWidget* | _this | Circular Slider widget pointer to operate on |
uint32_t | val | Start value |
Returns LE_SUCCESS or LE_FAILURE.
getEndValue()
Gets the end value.
Returns end value.
setEndValue()
Sets the end value.
Parameters
leCircularSliderWidget* | _this | Circular Slider widget pointer to operate on |
uint32_t | val | End value |
Returns LE_SUCCESS or LE_FAILURE.
getRoundEdges()
Gets the rounded edge setting for the active arc.
Returns LE_TRUE or LE_FALSE.
setRoundEdges()
Sets rounded edge setting for the active arc.
Parameters
leCircularSliderWidget* | _this | Circular Slider widget pointer to operate on |
leBool | rnd | LE_FALSE or LE_TRUE |
Returns LE_SUCCESS or LE_FAILURE.
getStickyButton()
Gets the sticky button setting.
Returns LE_TRUE or LE_FALSE.
setStickyButton()
Sets the sticky button setting.
Parameters
leCircularSliderWidget* | _this | Circular Slider widget pointer to operate on |
leBool | stk | LE_FALSE or LE_TRUE |
Returns LE_SUCCESS or LE_FAILURE.
getSnapDivisions()
Gets the snap division for the widget.
Returns snap division.
setSnapDivisions()
Sets the snap division for the widget.
Parameters
leCircularSliderWidget* | _this | Circular Slider widget pointer to operate on |
uint32_t | div | Snap division |
Returns LE_SUCCESS or LE_FAILURE.
getTouchOnButtonOnly()
Gets the touch on button setting.
Returns LE_TRUE or LE_FALSE.
setTouchOnButtonOnly()
Sets the touch on button setting.
Parameters
leCircularSliderWidget* | _this | Circular Slider widget pointer to operate on |
leBool | tch | LE_FALSE or LE_TRUE |
Returns LE_SUCCESS or LE_FAILURE.
getDirection()
Gets the current direction.
Returns LE_COUNTER_CLOCKWISE or LE_CLOCKWISE.
setDirection()
Sets the current direction.
Parameters
leCircularSliderWidget* | _this | Circular Slider widget pointer to operate on |
leRotationDirection | dir | LE_COUNTER_CLOCKWISE or LE_CLOCKWISE |
Returns LE_SUCCESS or LE_FAILURE.
setPressedEventCallback()
leCircularSliderWidget_PressedEvent cb)
Sets the pressed event callback function.
Parameters
leCircularSliderWidget* | _this | Circular Slider widget pointer to operate on |
leCircularSliderWidget_PressedEvent | cb | Callback function |
Returns LE_SUCCESS or LE_FAILURE.
setValueChangedEventCallback()
leCircularSliderWidget_ValueChangedEvent cb)
Sets the value changed event callback function.
Parameters
leCircularSliderWidget* | _this | Circular Slider widget pointer to operate on |
leCircularSliderWidget_ValueChangedEvent | cb | Callback function |
Returns LE_SUCCESS or LE_FAILURE.
setReleasedEventCallback()
leCircularSliderWidget_ReleasedEvent cb)
Sets the released event callback function.
Parameters
leCircularSliderWidget* | _this | Circular Slider widget pointer to operate on |
leCircularSliderWidget_ReleasededEvent | cb | Callback function |
Returns LE_SUCCESS or LE_FAILURE.