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

Support for drop-down lists and choosing from a dropdown. Utilizes multiple inheritance of lvppBase and lvppOptions. More...

#include <lvpp.h>

Inheritance diagram for lvppDropdown:
Collaboration diagram for lvppDropdown:

Public Member Functions

 lvppDropdown (const char *fName, const char *pOptions=nullptr, lv_obj_t *parent=nullptr)
 Construct a new lvpp Dropdown object and optionially give its starting options list.
 
void setOptions (const char *pOptions)
 sets the complete list of options by way of a char pointer with options separated by \n
 
void setOptions (std::vector< std::string > &options)
 sets the complete list of options by way of a reference to a vector of std::string values
 
void clearOptions (void)
 Removes all options from the dropdown.
 
void setDropdownDirection (lv_dir_t dropDirection)
 Set the Dropdown Direction. Depending on the screen location of the drop-down, it may be desirable to have the dropdown "open" above rather than below the widget location.
 
uint16_t getSelectedIndex ()
 Get the Index of the selected option.
 
void setSelectedIndex (uint16_t curInd)
 Set the selected option manually/programmatically.
 
void getSelectedText (char *selStr, uint8_t selStrLen)
 Get the Text value of the currently selected option.
 
- 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.
 
- Public Member Functions inherited from lvppOptions
virtual void setOptions (const char *pOpts)
 Set the Options all in one shot from a const char*.
 
virtual void setOptions (std::vector< std::string > &_opts)
 Set the Options using a vector of strings.
 
virtual void setOptionsWithIDs (std::vector< std::pair< std::string, uint64_t > > &valIDs)
 Set the Options along with a related ID. This is intended to give the user a more meaningful item to 'get' than text or index of what has been selected. Used in conjunction with getCurrentID()
 
virtual void addOption (const char *pOpt)
 Add a single option to the options list.
 
virtual void addOptionWithID (const char *pOpt, uint64_t id)
 Add a single option to the options list and pair it with a meaningful ID. To be used in conjunction with getSelectedID().
 
virtual void addOption (std::string &_opt)
 Add a single option to the options list.
 
virtual void addOptionWithID (std::string &_opt, uint64_t id)
 Add a single option to the options list and pair it with a meaningful ID. To be used in conjunction with getSelectedID().
 
virtual void clearOptions ()
 Removes all entries from the options list. NOTE: Method does not clear the LVGL widget. User should declare their own clearOptions() method and make a call to the base object for clearing the options list prior to the user clearing the widget's actual list visually.
 
virtual uint64_t getSelectedID ()
 Get the ID associated with the currently selected item. Using this method only makes sense if the list of options was built using setOptionsWithIDs() and/or addOptionWithID().
 

Protected Member Functions

void lvOptionSetter (const char *pOpts)
 This is the implementation of the pure virtual in lvppOptions. It is responsible for doing the actual class-specific 'set' - in this case lv_dropdown_set_options().
 
virtual uint16_t lvOptionGetIndex ()
 This is the implementation of the pure virtual in lvppOptions. It is responsible for doing the actual class-specific 'get' - in this case lv_dropdown_get_selected().
 
- 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 Member Functions inherited from lvppOptions
virtual void lvOptionSetter (const char *pOpts)=0
 This is the pure virtual which must be implemented by any class that utilizes lvppOptions. It is called by the 'set' functions to do the actual setting. Since lvppOptions is just a utility class, it must rely on the the child to do the actual appropriate set function.
 
virtual uint16_t lvOptionGetIndex ()=0
 This is the pure virtual method which must be implemented by any class that utilizes lvppOptions. The implementation should return the index of the currently selected value in the list. The specific function will vary based on what the child's widget type is.
 
const char * getNewlineSepOptions ()
 Packs all the option strings into a single newline separated pointer.
 

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.
 
- 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.
 
- Protected Attributes inherited from lvppOptions
std::string oneString
 Temp area for getNewlineSepOptions()
 
std::vector< std::string > options
 The vector of options kept locally.
 
std::vector< uint64_t > idList
 The vector of associated ID values (if used)
 
- Static Protected Attributes inherited from lvppBase
static bool bEventNamesInitComplete = false
 Status of the event names table to avoid re-processing.
 

Detailed Description

Support for drop-down lists and choosing from a dropdown. Utilizes multiple inheritance of lvppBase and lvppOptions.

Constructor & Destructor Documentation

◆ lvppDropdown()

lvppDropdown::lvppDropdown ( const char *  fName,
const char *  pOptions = nullptr,
lv_obj_t *  parent = nullptr 
)

Construct a new lvpp Dropdown object and optionially give its starting options list.

Parameters
fNameInternal object name. This is generally used in findObj() or lvppScreen
pOptionsOptional char pointer with a list of options which are separated by \n
parentIf provided, the parent of the object. This is a real LVGL lv_obj_t pointer

Member Function Documentation

◆ clearOptions()

void lvppDropdown::clearOptions ( void  )
virtual

Removes all options from the dropdown.

Reimplemented from lvppOptions.

◆ getSelectedIndex()

uint16_t lvppDropdown::getSelectedIndex ( )
inline

Get the Index of the selected option.

Returns
uint16_t Value from 0-(n-1) of the selected option.

◆ getSelectedText()

void lvppDropdown::getSelectedText ( char *  selStr,
uint8_t  selStrLen 
)
inline

Get the Text value of the currently selected option.

Parameters
selStrA pointer to a string where the current option string will be copied.
selStrLenThe size of the selStr location to ensure a long option value won't overrun selStr memory. Be sure to use the size of selStr MINUS one here to ensure you can fit a null terminator.

◆ lvOptionGetIndex()

uint16_t lvppDropdown::lvOptionGetIndex ( )
protectedvirtual

This is the implementation of the pure virtual in lvppOptions. It is responsible for doing the actual class-specific 'get' - in this case lv_dropdown_get_selected().

Implements lvppOptions.

◆ lvOptionSetter()

void lvppDropdown::lvOptionSetter ( const char *  pOpts)
protectedvirtual

This is the implementation of the pure virtual in lvppOptions. It is responsible for doing the actual class-specific 'set' - in this case lv_dropdown_set_options().

Parameters
pOptsnewline-separated list of options.

Implements lvppOptions.

◆ setDropdownDirection()

void lvppDropdown::setDropdownDirection ( lv_dir_t  dropDirection)

Set the Dropdown Direction. Depending on the screen location of the drop-down, it may be desirable to have the dropdown "open" above rather than below the widget location.

Parameters
dropDirectionAn lv_dir_t value such as LV_DIR_BOTTOM, LV_DIR_TOP.

◆ setOptions() [1/2]

void lvppDropdown::setOptions ( const char *  pOptions)
virtual

sets the complete list of options by way of a char pointer with options separated by \n

Parameters
pOptionspointer to a string of options separated by \n

Reimplemented from lvppOptions.

◆ setOptions() [2/2]

void lvppDropdown::setOptions ( std::vector< std::string > &  options)
virtual

sets the complete list of options by way of a reference to a vector of std::string values

Parameters
optionsA reference to a std::vector of std::string values.

Reimplemented from lvppOptions.

◆ setSelectedIndex()

void lvppDropdown::setSelectedIndex ( uint16_t  curInd)

Set the selected option manually/programmatically.

Parameters
curIndValue from 0-(n-1) of the desired option.

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