i. Toggle Widget

<< Click to Display Table of Contents >>

Navigation:  Tutorials > Tutorial 18 - Built-In FT81x Widgets >

i. Toggle Widget

The Toggle widget can be used for "on/off", "yes/no" type of controls.  This section shows how to draw the toggle widget with various parameters using the eve_toggle() command. The last parameter in the string label for the toggle. A character value of 255 (in C it can be written as \xff) separates the two labels.

 

 

Command Prototype

 

uint16_t eve_toggle(int x, int y, int16_t w, int16_t font, int16_t options, int16_t state, const char* String)

 

Parameters

Description

x

x-coordinate of top-left of toggle, in pixels

y

y-coordinate of top-left of toggle, in pixels

w

width of toggle, in pixels

font

font to use for text, 0-31

options

By default the toggle is drawn with a 3D effect and the value of options is zero. Options OPT_FLAT remove the 3D effect and its value is 256

state

state of the toggle: 0 is off, 65535 is on.

String

String label for toggle. A character value of 255 separates the two labels.

 

 

Code

 

 

void setup()

{

/* Initialize CleO - needs to be done only once */

 CleO.begin();

 

 /* Start building a screen frame */

 CleO.Start();

 uint16_t w = 155;

 int x = 400 - (w/2), y = 240;

 int font = FONT_SANS_6;

 uint16_t options = 0;

 

/* state of the toggle : 0 is off, 65535 is on */

 uint16_t value1 = 65535;

 uint16_t value2 = 0;

 uint16_t value3 = 30000;

 

/* Draw toggles with various state values */

 CleO.eve_toggle(x, y - 150, w, font, options, value1, "off" "\xff" "on");

 CleO.eve_toggle(x, y, w, font, options, value2, "off" "\xff" "on");

 CleO.eve_toggle(x, y + 150, w, font, options, value3, "off" "\xff" "on");

 

/* Display completed screen frame */

 CleO.Show();

}

 

void loop()

{

}

 

 

Description

 

In the above code snippet, the Setup() routine uses the eve_toggle() command to draw three toggle widgets at (x,y) location with w width and FONT_SANS_6 font. By default, the toggle is drawn with a 3D effect, and the value of options is zero. Option OPT_FLAT removes the 3D effect, and its value is 256. Value selects the state of the toggle: 0 is off, 65535 is on. The last parameter is string label for the toggle. A character value of 255 (in C it can be written as \xff) separates the two labels.

 

 

Output

 

Here is the output displayed upon executing the code snippet -

 

Tutorials18-ToggleWidget.50