LVGLPlusPlus
C++ library on top of the lovely LVGL project.
Loading...
Searching...
No Matches
lvppBaseWithValue Class Referenceabstract

Derivation from lvppBase. Those widgets which have an inherant 'value' to show are based on this slight modified version of lvppBase which includes a value label and an associated style object. More...

#include <lvppBase.h>

Inheritance diagram for lvppBaseWithValue:
Collaboration diagram for lvppBaseWithValue:

Public Member Functions

 lvppBaseWithValue (const char *fName, const char *oType)
 Construct a new lvpp object based on lvppBase which has an associated value.
 
virtual void setValue (int16_t value, bool animate=true)
 Set the Value associated with the object. This is a pure virtual function and must be overridden and implemented by the derived class. When implementing your own derived class, be sure to not only set curValue = value, but also to send an event to trigger the update notification via: lv_event_send(obj, LV_EVENT_VALUE_CHANGED, NULL);
 
int16_t getValue (void)
 Get the Value from the object.
 
uint16_t getValuePercentage (void)
 Get the 'percentage' Value from the object. This is the percentage represented from min to max of the current value. It is bounded by min/max and returned as 0-100 as an integer value.
 
void enableValueLabel (lv_coord_t xoff, lv_coord_t yoff, lv_align_t alignment=LV_ALIGN_CENTER)
 In the case where a label is desired to be shown for the value, enable it and align it here.
 
void setValueLabelFormat (const char *fmt)
 Set the Value Label Format. This 'format' allows the label to be more than simply a number. The format needs a 'd' in there somewhere (ala printf style) but this allows you to have text before the number and even a '' after - for instance "Completeness: %d%%". When the value changes, the class will automatically apply this format with the new value.
 
void setValueLabelColor (lv_color_t newColor)
 Set the Value Label's text Color.
 
void setValueLabelBGColor (lv_color_t newColor)
 Set the Value Label's background Color.
 
void setValueLabelColorGradient (lv_color_t col1, lv_color_t col2, lv_grad_dir_t direction)
 Sets a Color Gradient from col1 to col2 in a vertical or horizontal direction.
 
void setValueLabelJustificationAlignment (lv_text_align_t _align)
 Set the value Label's text alignment (left/right/center)
 
void setValueLabelFont (const lv_font_t *pF)
 Set the Value Label Font.
 
void setValueRange (int16_t _min, int16_t _max)
 Set the Value Range allowed. NOTE: This enforcement needs to happen in the derived setValue() function.
 
virtual void setNewParent (lv_obj_t *pNewParent)
 Changes the parent object on the fly. Used primarily for lvppScreen::addObject(). Sets parents of adjacent label, value label, and label appropriately.
 
- Public Member Functions inherited from lvppBase
 lvppBase (const char *fName, const char *oType)
 Construct a new lvpp Base object.
 
 ~lvppBase ()
 
void createObj (lv_obj_t *o)
 Create the handlers and store the newly created object.
 
lv_obj_t * getObj (void)
 Get the Obj object.
 
lv_obj_t * getLabelObj (void)
 Get the label object.
 
virtual void setSize (lv_coord_t width, lv_coord_t height)
 Set the Size object. Most of the time, LVGL does a great job of setting a sane size, but manipulation of things like the text or the font size can cause this to no longer be a good size. It is a common use pattern to instantiate a widget and then use setSize() and align() to place them in your user interface as needed.
 
void align (lv_align_t align, lv_coord_t x_ofs, lv_coord_t y_ofs)
 Change the x/y location of the object.
 
void setFontSize (uint8_t points)
 Set the Font Size for the object in simple 'points'.
 
void setFont (const lv_font_t *pF)
 Set the Font to be used. This is a more complete/complex version of setFontSize(). The fact that the font pointer is required at least means the user knows the font exists.
 
void setBGColor (lv_color_t color)
 Set the background color of the object.
 
void setColorGradient (lv_color_t col1, lv_color_t col2, lv_grad_dir_t direction)
 Sets a Color Gradient from col1 to col2 in a vertical or horizontal direction. The gradient is place on the indicator for lvppBar, lvppSlider, and lvppArc. The graident is placed on the 'main' area of all other objects.
 
virtual void setText (const char *pText)
 Set the Text for the primary text label. For a button, for instance, this is the text on top of the button.
 
std::string getText ()
 Get the Text from the object/label and put it in a std::string.
 
void setTextAlign (lv_align_t align, lv_coord_t xoff, lv_coord_t yoff)
 Set the Text Alignment. This allows the object's primary label to be moved from its 'center' position.
 
void setTextColor (lv_color_t newColor)
 Set the Text Color of the primary label object.
 
void setLabelJustificationAlignment (lv_text_align_t _align)
 Set the Label's text alignment (left/right/center)
 
void setLabelColorizationEnabled (bool bEnable=true)
 Turn on or off inline text colorization. To use colors inline, simply use #RRGGBB in the text where the R, G, and B are hex values. Be sure to have a space before and after.
 
virtual void setAdjText (const char *pText, lv_coord_t x_ofs=-10000, lv_coord_t y_ofs=-10000)
 Set the text for the adjacent text label. This label is not enabled by default. Setting this text will create and enable the adjacent label object. The label's position can be set, optionally, as well.
 
void setAdjTextColor (lv_color_t newColor)
 Set the Adjacent text color.
 
void setAdjBGColor (lv_color_t color)
 set the background color for the adjacent text
 
void setAdjColorGradient (lv_color_t col1, lv_color_t col2, lv_grad_dir_t direction)
 Sets a Color Gradient from col1 to col2 in a vertical or horizontal direction.
 
void setAdjFont (const lv_font_t *pF)
 Set the Font to be used for the adjacent text.
 
void setAdjJustificationAlignment (lv_text_align_t _align)
 Set the adjacent Label's text alignment (left/right/center)
 
virtual void onClicked ()
 Callback that derived objects can use to get notification when the object is clicked.
 
virtual void internalOnClicked ()
 Internal version of the onClicked() callback which is used for other derived internal objects in the library.
 
virtual void onValueChanged ()
 Callback that derived objects can use to get notification when the value changes of an object.
 
virtual void internalOnValueChanged ()
 Internal version of the onValueChanged() callback which is used for other derived internal objects in the library.
 
void setFriendlyName (const char *pName)
 Set the Friendly Name of the object. This is the name given in the constructor's fName parameter and is unlikely to be changed. However, it can be via this method.
 
std::string getFriendlyName ()
 Get the Friendly Name of the object.
 
std::string getObjType ()
 Get the Obj Type.
 
const char * whoAmI (void)
 Utility useful for dumping the friendly name and object type if needed.
 
void setCallbackOnClicked (std::function< void()> cbF)
 Uses a lambda callback for when an object is clicked.
 
void setCallbackOnValueChanged (std::function< void()> cbF)
 Uses a lambda callback for when an object value changes.
 
virtual void setNewParent (lv_obj_t *pNewParent)
 Changes the parent object on the fly. Used primarily for lvppScreen::addObject(). Sets parents of adjacent label, value label, and label appropriately.
 

Protected Member Functions

virtual int16_t baseGetter ()=0
 Derived classes must implement this pure virtual by getting the current value from the widget itself. This function generally gets called by getValue()
 
virtual void baseSetter (int16_t nVal, bool animate=true)=0
 Derived classes must implement this pure virtual which sets the current value of the widget itself. This function generally gets called by setValue()
 
void internalOnValueChanged ()
 Internal handler for value change. Does the formatting as well.
 
- Protected Member Functions inherited from lvppBase
void setObjType (const char *pType)
 
void baseEventHandler (lv_event_t *event)
 Main event handler loop for all events. This handler makes calls for onClicked() and onValueChanged()
 
virtual void eventHandler (lv_event_t *event)
 Any events not handled by baseEventHandler come here. Can be overridden by a derived class.
 

Protected Attributes

int16_t curValue
 The value we're keeping and handling in this class.
 
lv_obj_t * valueLabel
 The label that receives the formatted value if the label is enabled.
 
std::string valueLabelFormat
 The format to use when the value changes.
 
int16_t min
 
int16_t max
 The allowable range of the value.
 
- Protected Attributes inherited from lvppBase
lv_obj_t * label
 Primary label.
 
lv_obj_t * adjLabel
 For items that have a label 'nearby' (adjacent label)
 
std::function< void()> cbOnClicked =nullptr
 Start without a lambda callback.
 
std::function< void()> cbOnValueChanged =nullptr
 Start without a lambda callback.
 
lv_obj_t * obj
 The LVGL object that was created for this widget.
 
lv_obj_t * objParent
 Any parent object (following same principle as LVGL here)
 
std::string objType
 
std::string friendlyName
 
lv_style_t style_obj
 Main style object - unsure if I'm handling all of the style bit correctly.
 

Additional Inherited Members

- Static Public Member Functions inherited from lvppBase
static const char * getEventName (lv_event_code_t code)
 Get the Event Name from a given event code. Translate it to text, essentially.
 
static bool isUnknownCode (lv_event_code_t code)
 Check to see if an event code is valid or not. Utility function.
 
- Static Protected Member Functions inherited from lvppBase
static void lvCallback (lv_event_t *event)
 Static member to handle all inbound callback events. Used to "route" event handling to the appropriate C++ object.
 
static void initEventNames (void)
 One-time initialization of the event names array.
 
- Static Protected Attributes inherited from lvppBase
static bool bEventNamesInitComplete = false
 Status of the event names table to avoid re-processing.
 

Detailed Description

Derivation from lvppBase. Those widgets which have an inherant 'value' to show are based on this slight modified version of lvppBase which includes a value label and an associated style object.

Constructor & Destructor Documentation

◆ lvppBaseWithValue()

lvppBaseWithValue::lvppBaseWithValue ( const char *  fName,
const char *  oType 
)

Construct a new lvpp object based on lvppBase which has an associated value.

Parameters
fNameInternal object name. This is generally used in findObj() or lvppScreen
oTypeThe type of the object being created. This is primarily internal, but can be used to know the category/type of the object and can be obtained via getObjType() if needed.

Member Function Documentation

◆ baseGetter()

virtual int16_t lvppBaseWithValue::baseGetter ( )
protectedpure virtual

Derived classes must implement this pure virtual by getting the current value from the widget itself. This function generally gets called by getValue()

Returns
int16_t The value retrieved from the widget at this time.

Implemented in lvppBar, lvppSlider, and lvppArc.

◆ baseSetter()

virtual void lvppBaseWithValue::baseSetter ( int16_t  nVal,
bool  animate = true 
)
protectedpure virtual

Derived classes must implement this pure virtual which sets the current value of the widget itself. This function generally gets called by setValue()

Parameters
nValint16_t which is the value the widget shall be set to at this time.
animateIf widget supports it, animation to value.

Implemented in lvppBar, lvppSlider, and lvppArc.

◆ enableValueLabel()

void lvppBaseWithValue::enableValueLabel ( lv_coord_t  xoff,
lv_coord_t  yoff,
lv_align_t  alignment = LV_ALIGN_CENTER 
)

In the case where a label is desired to be shown for the value, enable it and align it here.

Parameters
xoffX offset of label
yoffY offset of label
alignmentDefaults to a 'center' alignment but other LV_ALIGN_* values can be experimented with.

◆ getValue()

int16_t lvppBaseWithValue::getValue ( void  )
inline

Get the Value from the object.

Returns
int16_t The current value is returned.

◆ getValuePercentage()

uint16_t lvppBaseWithValue::getValuePercentage ( void  )
inline

Get the 'percentage' Value from the object. This is the percentage represented from min to max of the current value. It is bounded by min/max and returned as 0-100 as an integer value.

Returns
uint16_t The current percentage along the way between min and max that value represents.

◆ internalOnValueChanged()

void lvppBaseWithValue::internalOnValueChanged ( )
protectedvirtual

Internal handler for value change. Does the formatting as well.

Reimplemented from lvppBase.

◆ setNewParent()

void lvppBaseWithValue::setNewParent ( lv_obj_t *  pNewParent)
virtual

Changes the parent object on the fly. Used primarily for lvppScreen::addObject(). Sets parents of adjacent label, value label, and label appropriately.

Parameters
pNewParentpointer to the new parent.

Reimplemented from lvppBase.

◆ setValue()

void lvppBaseWithValue::setValue ( int16_t  value,
bool  animate = true 
)
virtual

Set the Value associated with the object. This is a pure virtual function and must be overridden and implemented by the derived class. When implementing your own derived class, be sure to not only set curValue = value, but also to send an event to trigger the update notification via: lv_event_send(obj, LV_EVENT_VALUE_CHANGED, NULL);

One more note - the class has a 'min' and a 'max' that is expected to keep the value within those value bounds. It is the responsibility of this function, as written by the derived class, to enforce that min and max - and to decide whether to set curValue to 'max' in the case where value is greater than max or to simply ignore the value altogether due to it being out of the specified range.

Parameters
valueThe integer value to be set.
animateIf there is animation involved, we decide it in this parameter.
Todo:
TECHDEBT - should allow values outside range, but UI only shows inside range. However, this will impact the 'percentage' function too and likely needs to become getUIPercentage

◆ setValueLabelBGColor()

void lvppBaseWithValue::setValueLabelBGColor ( lv_color_t  newColor)

Set the Value Label's background Color.

Parameters
newColorThe lv_color_t of the desired color for the value label's background

◆ setValueLabelColor()

void lvppBaseWithValue::setValueLabelColor ( lv_color_t  newColor)

Set the Value Label's text Color.

Parameters
newColorThe lv_color_t of the desired color for the value label.

◆ setValueLabelColorGradient()

void lvppBaseWithValue::setValueLabelColorGradient ( lv_color_t  col1,
lv_color_t  col2,
lv_grad_dir_t  direction 
)

Sets a Color Gradient from col1 to col2 in a vertical or horizontal direction.

Parameters
col1First lv_color_t color in the gradient
col2Second lv_color_t color in the gradient
directiongradient color runs col1->col2 either LV_GRAD_DIR_VER (top to bottom) or LV_GRAD_DIR_HOR (left to right)

◆ setValueLabelFont()

void lvppBaseWithValue::setValueLabelFont ( const lv_font_t *  pF)

Set the Value Label Font.

Parameters
pFA pointer to the font to be used. This is a lv_font_t pointer.

◆ setValueLabelFormat()

void lvppBaseWithValue::setValueLabelFormat ( const char *  fmt)

Set the Value Label Format. This 'format' allows the label to be more than simply a number. The format needs a 'd' in there somewhere (ala printf style) but this allows you to have text before the number and even a '' after - for instance "Completeness: %d%%". When the value changes, the class will automatically apply this format with the new value.

Parameters
fmtA printf-style format to be used when values change in the object.

◆ setValueLabelJustificationAlignment()

void lvppBaseWithValue::setValueLabelJustificationAlignment ( lv_text_align_t  _align)

Set the value Label's text alignment (left/right/center)

Parameters
_alignan lv_text_align_t like LV_TEXT_ALIGN_CENTER

◆ setValueRange()

void lvppBaseWithValue::setValueRange ( int16_t  _min,
int16_t  _max 
)
inline

Set the Value Range allowed. NOTE: This enforcement needs to happen in the derived setValue() function.

Parameters
_minMinimum value allowed.
_maxMaximum value allowed.

Member Data Documentation

◆ curValue

int16_t lvppBaseWithValue::curValue
protected

The value we're keeping and handling in this class.

◆ max

int16_t lvppBaseWithValue::max
protected

The allowable range of the value.

◆ min

int16_t lvppBaseWithValue::min
protected

◆ valueLabel

lv_obj_t* lvppBaseWithValue::valueLabel
protected

The label that receives the formatted value if the label is enabled.

◆ valueLabelFormat

std::string lvppBaseWithValue::valueLabelFormat
protected

The format to use when the value changes.


The documentation for this class was generated from the following files: