Toggle
Overview
The Toggle widget is a two-state switch implemented entirely with vector primitives (no image assets). A rounded rail changes color and a circular handle slides horizontally to indicate the ON or OFF state.
Components
Name |
Type |
Description |
|---|---|---|
|
Line (round cap) |
Background track, 60×30 px |
|
Circle |
Sliding knob, 30×30 px |
Container size: 60×30 px.
Default Colors
Element |
OFF |
ON |
|---|---|---|
Rail |
|
|
Handle |
|
|
Colors can be overridden before the first setState() call.
API
void setState(bool state); // Set ON/OFF and update visuals
bool getState() const; // Return current state
void setRailOnColor(colortype); // Rail color when ON
void setRailOffColor(colortype); // Rail color when OFF
void setHandleOnColor(colortype); // Handle color when ON
void setHandleOffColor(colortype); // Handle color when OFF
Handle position: X = 0 (OFF), X = 30 (ON).
Usage in TouchGFX Designer
Import the package:
Open TouchGFX Designer
Go to
Edit→Import→Custom ContainersSelect
Toggle.tpkg
Add to screen: drag the
Togglecontainer onto your screen and position it.No designer properties — all behavior is controlled in C++.
Usage in C++ Code
#include <gui/containers/Toggle.hpp>
Toggle toggle;
add(toggle);
toggle.setPosition(x, y, 60, 30);
// Basic usage
toggle.setState(true);
bool on = toggle.getState();
// Custom colors (must be set before setState)
toggle.setRailOnColor(touchgfx::Color::getColorFromRGB(0, 200, 100));
toggle.setState(true);
// React to state change
void MyView::onToggleTapped() {
toggle.setState(!toggle.getState());
}
Files Included
manifest.xml— package manifest (requires TouchGFX ≥ 4.26.1)content/CustomContainerExport.touchgfx— Designer container definitioncontent/CustomContainerManifest.xml— container manifestfiles/gui/include/gui/containers/Toggle.hpp— headerfiles/gui/src/containers/Toggle.cpp— implementation
Dependencies
TouchGFX Framework (minimum version 4.26.1)
No image assets — fully vector-based