HrBarο
Overviewο
The HrBar widget is a custom TouchGFX container designed to visually represent heart rate levels using a series of heart-shaped icons. It provides a simple, intuitive way to display heart rate data in wearable or fitness applications, with five distinct visual states ranging from very low to very high heart rate.
Purposeο
The HrBar widget serves as a graphical indicator for heart rate monitoring. It displays one of five heart icons based on the current heart rate value compared against configurable thresholds. This allows users to quickly assess their heart rate status at a glance, making it ideal for fitness trackers, smartwatches, and health monitoring applications.
Componentsο
The widget consists of the following visual elements:
Background Group: A static background image (
HR_group.png) that provides the base visual contextHeart Icons: Five individual heart images representing different heart rate levels:
HR_1.png: Very low heart rate (default visible state)HR_2.png: Low heart rateHR_3.png: Medium heart rate (centered position)HR_4.png: High heart rateHR_5.png: Very high heart rate
The heart icons are positioned asymmetrically to create a balanced visual bar effect, with the medium level icon centered and the extreme levels positioned at the edges.
Functionalityο
Core Featuresο
Threshold-Based Display: Accepts a heart rate value and four threshold values to determine which icon to display
Five Visual States: Supports five distinct heart rate levels for granular feedback
Dynamic Visibility: Only one heart icon is visible at a time, with others hidden
Automatic Invalidation: Refreshes the display after state changes
Threshold Logicο
The widget uses the following logic to select which heart icon to display:
if (hr > th[3]) {
// Show very high heart rate (hr5)
} else if (hr > th[2]) {
// Show high heart rate (hr4)
} else if (hr > th[1]) {
// Show medium heart rate (hr3)
} else if (hr > th[0]) {
// Show low heart rate (hr2)
} else {
// Show very low heart rate (hr1)
}
Where:
hr: Current heart rate value (float)th: Array of four threshold values (uint8_t[4]), ordered from lowest to highest
Usage in TouchGFX Designerο
Import the Custom Container:
Open your TouchGFX project
Go to the Designer view
Import the HrBar custom container package
Add to Screen:
Drag the HrBar widget from the custom containers panel onto your screen
Position and resize as needed (default size: 210x71 pixels)
Configure Properties:
The widget doesnβt have configurable properties in the Designer
All configuration is done programmatically
Usage in C++ Codeο
Basic Setupο
#include <gui/containers/HrBar.hpp>
// In your view or presenter
HrBar hrBar;
// Initialize in setup
hrBar.initialize();
Setting Heart Rateο
// Define thresholds (example values)
std::array<uint8_t, 4> thresholds = {60, 100, 140, 180}; // BPM thresholds
// Set current heart rate
float currentHR = 120.0f; // BPM
hrBar.setHR(currentHR, thresholds);
Integration Exampleο
class MainView : public MainViewBase
{
private:
HrBar hrBar;
public:
MainView() : hrBar() {}
void setupScreen()
{
MainViewBase::setupScreen();
hrBar.initialize();
add(hrBar); // Add to screen
}
void updateHeartRate(float bpm)
{
std::array<uint8_t, 4> thresholds = {50, 80, 120, 160};
hrBar.setHR(bpm, thresholds);
}
};
Advanced Featuresο
Customizable Thresholdsο
The widgetβs thresholds are fully configurable, allowing adaptation to different user profiles or activity contexts:
Resting Heart Rate: Lower thresholds for sedentary users
Athletic Training: Higher thresholds for athletes
Age-Adjusted: Different ranges for various age groups
Visual Design Considerationsο
Asymmetric Layout: The heart icons are positioned to create visual balance and flow
Size Variation: Icons vary in size to emphasize the center position
Background Integration: The group background provides context and framing
Performance Notesο
Minimal redraw operations (only the active icon is visible)
Efficient state management with automatic invalidation
Suitable for real-time heart rate updates
Technical Detailsο
Base Class: Inherits from
HrBarBase(generated by TouchGFX Designer)Minimum TouchGFX Version: 4.26.0
File Structure:
HrBar.hpp: Class declarationHrBar.cpp: ImplementationImage assets: 6 PNG files
Configuration files: Manifests and export data
Best Practicesο
Threshold Calibration: Set meaningful thresholds based on user health data
Real-time Updates: Call
setHR()frequently for live monitoringUser Feedback: Combine with numerical display for precise values
Accessibility: Consider color-blind users when designing heart rate zones
Limitationsο
Fixed visual design (5 levels, specific icon positions)
No animation between states
Thresholds must be provided programmatically (not configurable in Designer)