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

lvppBase is the root of the C++ library LVGLPlusPlus. It strives to create consistent ways to manipulate a variety of LVGL-based widgets in a consistent manner - hiding the details away from the user where possible. More...

#include <lvppBase.h>

Inheritance diagram for lvppBase:

Public Member Functions

 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.
 

Static Public Member Functions

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.
 

Protected Member Functions

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.
 

Static Protected Member Functions

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.
 

Protected Attributes

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.
 

Static Protected Attributes

static bool bEventNamesInitComplete = false
 Status of the event names table to avoid re-processing.
 

Detailed Description

lvppBase is the root of the C++ library LVGLPlusPlus. It strives to create consistent ways to manipulate a variety of LVGL-based widgets in a consistent manner - hiding the details away from the user where possible.

The topmost concepts for lvppBase are:

  • Having a handle to an LVGL object 'obj' which gets created (and named) for each widget.
  • Event handling for each widget is handled by the class and callbacks are used to give the user the ability to take action on changes or events.
  • Lambda functions are used in some cases to allow users to utilize the widget class without having to derive their own class from it for the sole purpose of a callback.
  • A main 'label' is defined for all base widgets.
  • An options 'adjacent label' can be used to enable a separate label that acts (often) as a label for the item. Think of a dropdown list that needs a nearby label to tell the user what this dropdown is intended for.
  • Font setting
  • Background color setting
  • Size and location/alignment of the widget
  • Setting of text for the main label as well as ancillary labels.

Constructor & Destructor Documentation

◆ lvppBase()

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

Construct a new lvpp Base object.

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.

◆ ~lvppBase()

lvppBase::~lvppBase ( )

Member Function Documentation

◆ align()

void lvppBase::align ( lv_align_t  align,
lv_coord_t  x_ofs,
lv_coord_t  y_ofs 
)

Change the x/y location of the object.

Parameters
alignThis is an LVGL notion of alignment type. It is a very rich concept of alignment that does not simply use x/y screen coordinates but uses the x/y as an offset from some other 'anchor'. In concrete terms, this is one of LV_ALIGN_CENTER, LV_ALIGN_TOP_MID, LV_ALIGN_BOTTON_RIGHT, etc.
x_ofsThe x offset from the align point.
y_ofsThe y offset from the align point.

◆ baseEventHandler()

void lvppBase::baseEventHandler ( lv_event_t *  event)
protected

Main event handler loop for all events. This handler makes calls for onClicked() and onValueChanged()

Parameters
eventLVGL lv_event_t type event to be handled.

◆ createObj()

void lvppBase::createObj ( lv_obj_t *  o)

Create the handlers and store the newly created object.

The pattern here is that any derived widget type will, in its constructor, call createObj() with a pointer to the appropriate LVGL object type. For instance createObj(lv_dropdown_create(objParent)); This effectively make it the responsibility of the derived class to create the right type of object and pass it to createObj() so that the base class can hang on to that handle and then setup event callbacks for the object.

Parameters
oThe lv_obj_t pointer created by the derived class. Might this be better named storeNewObj() - but lots of refacotring to do if so.

◆ eventHandler()

virtual void lvppBase::eventHandler ( lv_event_t *  event)
inlineprotectedvirtual

Any events not handled by baseEventHandler come here. Can be overridden by a derived class.

Parameters
eventLVGL lv_event_t type event to be handled.

◆ getEventName()

const char * lvppBase::getEventName ( lv_event_code_t  code)
static

Get the Event Name from a given event code. Translate it to text, essentially.

Parameters
codeAn lv_event_code_t type from LVGL.
Returns
const char* Pointer to a string with the textual description of the code type.

◆ getFriendlyName()

std::string lvppBase::getFriendlyName ( )
inline

Get the Friendly Name of the object.

Returns
std::string of the internal friendly name of the object.

◆ getLabelObj()

lv_obj_t * lvppBase::getLabelObj ( void  )
inline

Get the label object.

Returns
lv_obj_t* Returns the LVGL lv_obj_t for the actual label object. Great for more advanced users who may wish to manipulate the label more fully outside of the lvpp* class library.

◆ getObj()

lv_obj_t * lvppBase::getObj ( void  )
inline

Get the Obj object.

Returns
lv_obj_t* Returns the LVGL lv_obj_t for the actual widget/object. Great for more advanced users who may wish to manipulate the object more fully outside of the lvpp* class library.

◆ getObjType()

std::string lvppBase::getObjType ( )
inline

Get the Obj Type.

Returns
std::string of the internal object type. This is what is given in the constructor as oType. It can be used to determine the type of an object without the need for RTTI library support and dynamic_cast<> or other such RTTI support methodologies.

◆ getText()

std::string lvppBase::getText ( )

Get the Text from the object/label and put it in a std::string.

Returns
std::string return the text into a string.

◆ initEventNames()

void lvppBase::initEventNames ( void  )
staticprotected

One-time initialization of the event names array.

◆ internalOnClicked()

virtual void lvppBase::internalOnClicked ( )
inlinevirtual

Internal version of the onClicked() callback which is used for other derived internal objects in the library.

Reimplemented in lvppCycleButton.

◆ internalOnValueChanged()

virtual void lvppBase::internalOnValueChanged ( )
inlinevirtual

Internal version of the onValueChanged() callback which is used for other derived internal objects in the library.

Reimplemented in lvppBaseWithValue.

◆ isUnknownCode()

bool lvppBase::isUnknownCode ( lv_event_code_t  code)
static

Check to see if an event code is valid or not. Utility function.

Parameters
codeEvent code from LVGL
Returns
If the event code has a valid lookup, returns true.

◆ lvCallback()

void lvppBase::lvCallback ( lv_event_t *  event)
staticprotected

Static member to handle all inbound callback events. Used to "route" event handling to the appropriate C++ object.

Parameters
eventAn LVGL lv_event_t event object pointer to be handled.

◆ onClicked()

virtual void lvppBase::onClicked ( )
inlinevirtual

Callback that derived objects can use to get notification when the object is clicked.

◆ onValueChanged()

virtual void lvppBase::onValueChanged ( )
inlinevirtual

Callback that derived objects can use to get notification when the value changes of an object.

Reimplemented in lvppFullImageToggleButton.

◆ setAdjBGColor()

void lvppBase::setAdjBGColor ( lv_color_t  color)

set the background color for the adjacent text

Parameters
colorlv_color_t to describe the background color.

◆ setAdjColorGradient()

void lvppBase::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.

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)

◆ setAdjFont()

void lvppBase::setAdjFont ( const lv_font_t *  pF)

Set the Font to be used for the adjacent text.

Parameters
pFA pointer to a valid lv_font_t to be used for the object.

◆ setAdjJustificationAlignment()

void lvppBase::setAdjJustificationAlignment ( lv_text_align_t  _align)

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

Parameters
_alignan lv_text_align_t like LV_TEXT_ALIGN_CENTER

◆ setAdjText()

void lvppBase::setAdjText ( const char *  pText,
lv_coord_t  x_ofs = -10000,
lv_coord_t  y_ofs = -10000 
)
virtual

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.

Parameters
pTextPointer to the text to use.
x_ofsX offset from the center of the main object.
y_ofsY offset from the center of the main object.

◆ setAdjTextColor()

void lvppBase::setAdjTextColor ( lv_color_t  newColor)

Set the Adjacent text color.

Parameters
newColorlv_color_t value for the new color of the adjacent text

◆ setBGColor()

void lvppBase::setBGColor ( lv_color_t  color)

Set the background color of the object.

Parameters
colorlv_color_t color to be used for the background.
Todo:
I think this add_style needs to go away and an 'invalidate' should be used instead.

◆ setCallbackOnClicked()

void lvppBase::setCallbackOnClicked ( std::function< void()>  cbF)
inline

Uses a lambda callback for when an object is clicked.

This method allows users to instantiate most objects without deriving their own class from them. They can instantiate the object, set its font, size, alignment, and text all using the built in methods and they can receive a callback through the use of this lambda callback methodology.

Parameters
cbFThis is a std::function<> lambda defining the callback 'inline'.

◆ setCallbackOnValueChanged()

void lvppBase::setCallbackOnValueChanged ( std::function< void()>  cbF)
inline

Uses a lambda callback for when an object value changes.

This method allows users to instantiate most objects without deriving their own class from them. They can instantiate the object, set its font, size, alignment, and text all using the built in methods and they can receive a callback through the use of this lambda callback methodology.

Parameters
cbFThis is a std::function<> lambda defining the callback 'inline'.

◆ setColorGradient()

void lvppBase::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.

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)

◆ setFont()

void lvppBase::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.

Parameters
pFA pointer to a valid lv_font_t to be used for the object.

◆ setFontSize()

void lvppBase::setFontSize ( uint8_t  points)

Set the Font Size for the object in simple 'points'.

NOTE: This makes easy work of changing font sizes, but its downfall is that the size can be given for font sizes that don't exist for several reasons. Be forewarned.

Parameters
pointsThe desired point size for the object.
Todo:
Possibly return a bool for errant point values or for requests of point sizes that weren't compiled in?

◆ setFriendlyName()

void lvppBase::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.

Parameters
pNamepointer to a new friendly name.

◆ setLabelColorizationEnabled()

void lvppBase::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.

Parameters
bEnableTurn on or off inline text colorization. Default is true.

◆ setLabelJustificationAlignment()

void lvppBase::setLabelJustificationAlignment ( lv_text_align_t  _align)

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

Parameters
_alignan lv_text_align_t like LV_TEXT_ALIGN_CENTER

◆ setNewParent()

void lvppBase::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 in lvppBaseWithValue.

◆ setObjType()

void lvppBase::setObjType ( const char *  pType)
inlineprotected

◆ setSize()

void lvppBase::setSize ( lv_coord_t  width,
lv_coord_t  height 
)
virtual

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.

Parameters
widthNew width of the widget.
heightNew height of the widget.

Reimplemented in lvppImage.

◆ setText()

void lvppBase::setText ( const char *  pText)
virtual

Set the Text for the primary text label. For a button, for instance, this is the text on top of the button.

Parameters
pTextchar pointer to the text

Reimplemented in lvppLabel.

◆ setTextAlign()

void lvppBase::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.

Parameters
alignThis is an LVGL notion of alignment type. It is a very rich concept of alignment that does not simply use x/y screen coordinates but uses the x/y as an offset from some other 'anchor'. In concrete terms, this is one of LV_ALIGN_CENTER, LV_ALIGN_TOP_MID, LV_ALIGN_BOTTON_RIGHT, etc.
xoffThe x offset from the align point.
yoffThe y offset from the align point.

◆ setTextColor()

void lvppBase::setTextColor ( lv_color_t  newColor)

Set the Text Color of the primary label object.

Parameters
newColorAn lv_color_t for the desired color to use.

◆ whoAmI()

const char * lvppBase::whoAmI ( void  )

Utility useful for dumping the friendly name and object type if needed.

Returns
const char* returned friendlyName(objectType)

Member Data Documentation

◆ adjLabel

lv_obj_t* lvppBase::adjLabel
protected

For items that have a label 'nearby' (adjacent label)

◆ bEventNamesInitComplete

bool lvppBase::bEventNamesInitComplete = false
staticprotected

Status of the event names table to avoid re-processing.

Uncommenting the definition of LOG_EVENTS will make for a noisy logging of all events. This can be useful if things feel upside down when you're adding features or something.

◆ cbOnClicked

std::function<void()> lvppBase::cbOnClicked =nullptr
protected

Start without a lambda callback.

◆ cbOnValueChanged

std::function<void()> lvppBase::cbOnValueChanged =nullptr
protected

Start without a lambda callback.

◆ friendlyName

std::string lvppBase::friendlyName
protected

◆ label

lv_obj_t* lvppBase::label
protected

Primary label.

◆ obj

lv_obj_t* lvppBase::obj
protected

The LVGL object that was created for this widget.

◆ objParent

lv_obj_t* lvppBase::objParent
protected

Any parent object (following same principle as LVGL here)

◆ objType

std::string lvppBase::objType
protected

◆ style_obj

lv_style_t lvppBase::style_obj
protected

Main style object - unsure if I'm handling all of the style bit correctly.


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