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

Construct a canvas which uses INDEXED color rather than FULL color methods. More...

#include <lvpp.h>

Inheritance diagram for lvppCanvasIndexed:
Collaboration diagram for lvppCanvasIndexed:

Public Member Functions

 lvppCanvasIndexed (const char *fName, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, uint8_t colorDepth, lv_color_t *providedBuffer=nullptr, lv_obj_t *parent=nullptr)
 Construct a new lvpp Canvas Full Color object.
 
virtual ~lvppCanvasIndexed ()
 
bool addColorToIndex (lv_color_t col)
 Add a single color to the indexed color set.
 
bool addPaletteToIndex (lv_palette_t pal)
 Add a full palette of color to the indexed color set. This is 10 colors.
 
void clearColorIndex ()
 Remove all colors from the indexed color set.
 
bool getIndexFromColor (lv_color_t col, lv_color_t &ind)
 Get the Index of a single Color.
 
void setbgColor (lv_color_t bgColor)
 Set the background color of the canvas.
 
void setbgColorByIndex (lv_color_t bgColorIndex)
 Set the backgrond color from an index color.
 
void drawPixel (lv_coord_t x, lv_coord_t y, lv_color_t color)
 Draw a single pixel on to the canvas.
 
void drawPixelByIndex (lv_coord_t x, lv_coord_t y, lv_color_t colorIndex)
 Draw a single pixel on to the canvas using an index color.
 
void drawLineVert (lv_coord_t x1, lv_coord_t y1, lv_coord_t h, lv_color_t color)
 Draw a verical line on the canvas.
 
void drawLineVertByIndex (lv_coord_t x1, lv_coord_t y1, lv_coord_t h, lv_color_t indexCol)
 Draw a verical line on the canvas using an index color.
 
void drawLineHoriz (lv_coord_t x1, lv_coord_t y1, lv_coord_t w, lv_color_t color)
 Draw a horizontal line on the canvas.
 
void drawLineHorizByIndex (lv_coord_t x1, lv_coord_t y1, lv_coord_t w, lv_color_t indexCol)
 Draw a horizontal line on the canvas using an index color.
 
void drawRectWithoutFill (lv_coord_t x1, lv_coord_t y1, lv_coord_t w, lv_coord_t h, lv_color_t borderColor)
 Draw a rectangle on the canvas without filling in the rectangle.
 
void drawRectWithoutFillByIndex (lv_coord_t x1, lv_coord_t y1, lv_coord_t w, lv_coord_t h, lv_color_t borderColorInd)
 Draw a rectangle on the canvas without filling in the rectangle using an index color.
 
void drawRectWithFill (lv_coord_t x1, lv_coord_t y1, lv_coord_t w, lv_coord_t h, lv_color_t borderColor, lv_color_t fillColor)
 Draw a rectangle on the canvas and fill in the center of the rectangle.
 
void drawRectWithFillByIndex (lv_coord_t x1, lv_coord_t y1, lv_coord_t w, lv_coord_t h, lv_color_t borderColorInd, lv_color_t fillColorInd)
 Draw a rectangle on the canvas and fill in the center of the rectangle. This uses index colors.
 
void drawCenteredRectWithoutFill (lv_coord_t xBorder, lv_coord_t yBorder, lv_color_t borderColor)
 Draw a centered rectangle on the canvas. Will have xBorder/yBorder around it.
 
void drawCenteredRectWithoutFillByIndex (lv_coord_t xBorder, lv_coord_t yBorder, lv_color_t borderColorInd)
 Draw a centered rectangle on the canvas. Will have xBorder/yBorder around it. This uses index colors.
 
void drawCenteredRectWithFill (lv_coord_t xBorder, lv_coord_t yBorder, lv_color_t borderColor, lv_color_t fillColor)
 Draw a centered rectangle on the canvas and fill in the rectangle. Will have xBorder/yBorder around it.
 
void drawCenteredRectWithFillByIndex (lv_coord_t xBorder, lv_coord_t yBorder, lv_color_t borderColorInd, lv_color_t fillColorInd)
 Draw a centered rectangle on the canvas and fill in the rectangle. Will have xBorder/yBorder around it. This uses index colors.
 
- 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 Attributes

uint16_t maxColorIndexesAllowed
 Number of color indexes available based on the color depth at creation time.
 
uint8_t colorIndexesUsed
 
lv_color_t * pBuffer
 
lv_coord_t width
 
lv_coord_t height
 
- 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.
 
- 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.
 
- 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

Construct a canvas which uses INDEXED color rather than FULL color methods.

Canvas drawing is very powerful in LVGL, but only when a full color canvas is available. In many smaller CPUs, full color isn't an option due to the sheer size of needing to have a buffer which is width * height * 4-bytes plus a bit more. LVGL has some great facilities around drawing rectangles, lines, and labels with really nice options like rounded ends, line thicknesses, and other style attributes. Many of these functions simply do not work in the indexed color world.

The underlying LVGL library allows for pixel drawing using an lv_color_t where the '.full' member is not actually a color but instead is an index based on how many colors are in the indexed color set. For instance, if you've chosen a 4-bit indexed color set, then the indexes would run from 0-15 and it is up to the user to "set up" the indexed color set (palette) prior to using any of those indexed values.

In lvppCanvasIndexed, some of the mystery and intricacy is taken out of the drawing and also the class supports drawing of lines and rectangles in a more limited fashion than the native full color canvas LVGL drawing routines.

To alleviate the complexity of keeping track of which color corresponds to which index value, this class allows the user to utilize either lv_color_t values or index values to do the drawing functions. The internals of the class work out the translation. This is accomplished by the user adding colors and/or palettes to the object through addColorToIndex() and addPaletteToIndex(). These colors are then mapped to index values internally which then allows the user to work in "colors" rather than indexes to colors, if they wish.

While it was the original intention to have users utilize only colors in this class, it was revamped to allow drawing by index as well. It is up to the user to keep track of what color is which index. And all of the drawing functions which are draw*Indexed() do take an lv_color_t but this is done in the same manner that LVGL intends it. The ".full" member of that color is actually the index value and not a true color. While I didn't particularly like the type conflict between a real color and an index, I felt it important to lean, again, to being more similar to LVGL concepts than to make my own.

NOTE: If the user tries to draw using an lv_color_t color which is not already defined in the indexed color set via addColorToIndex() or addPaletteToIndex(), the drawing requested will not take place and there will be an LV_LOG_WARN() message created to note that the requested color was not in the indexed color set.

NOTE: The primative drawPixel() is likely 'more expensive' than drawLine() and drawRect() functions for situations where more than a few pixels are to be drawn. This is because the drawing is invalidated after every pixel draw in the primative case while in the case of lines and rects, the invalidation is only done once after all of the pixels are 'laid down' in the drawing area. This is only a performance warning and not a functional one.

Constructor & Destructor Documentation

◆ lvppCanvasIndexed()

lvppCanvasIndexed::lvppCanvasIndexed ( const char *  fName,
lv_coord_t  x,
lv_coord_t  y,
lv_coord_t  w,
lv_coord_t  h,
uint8_t  colorDepth,
lv_color_t *  providedBuffer = nullptr,
lv_obj_t *  parent = nullptr 
)

Construct a new lvpp Canvas Full Color object.

Parameters
fNameInternal object name. This is generally used in findObj() or lvppScreen
x,yTop-left starting point of the canvas on the display.
w,hWidth and height of the canvas referenced from x and y.
colorDepthHow many bits of color depth shall be used for this canvas. Valid values would be 1, 2, 4, or 8. For instance, a 4-bit color depth would have 16 colors available in the indexed color set. NOTE: If the user passes in a providedBuffer, it is incumbent upon that user to ensure this colorDepth and the size of that buffer are not in conflict with each other or bad things could occur.
providedBufferIf provided, a non-null value will cause the constructor to not allocate its own buffer. This is helpful when a series of screens intend to share a common canvas with no drawing changes between them.
parentIf provided, the parent of the object. This is a real LVGL lv_obj_t pointer

◆ ~lvppCanvasIndexed()

lvppCanvasIndexed::~lvppCanvasIndexed ( )
virtual

Member Function Documentation

◆ addColorToIndex()

bool lvppCanvasIndexed::addColorToIndex ( lv_color_t  col)

Add a single color to the indexed color set.

Parameters
colColor to add to the index.
Returns
true If there was room to add a new color or if the color was already in the index.
false If the index is already full based on the indexed color depth of the canvas.

◆ addPaletteToIndex()

bool lvppCanvasIndexed::addPaletteToIndex ( lv_palette_t  pal)

Add a full palette of color to the indexed color set. This is 10 colors.

The concept of palette used here is that of LVGL. I felt the palette concept was a powerful one and wanted to support it here, easily. Adding a color palette will effectively add (4) darker palette colors, (1) main palette color, and (5) lighter palette colors. These figures come from the lv_palette_darken(), lv_palette_main() and lv_palette_lighten() functions.

Parameters
palPalette (not color) to add to the index. This is generally done by the use of LV_PALETTE_BLUE, LV_PALETTE_TEAL, LV_PALETTE_BROWN, etc.
Returns
true If there was room to add a new color or if the color was already in the index.
false If the index is already full based on the indexed color depth of the canvas.

◆ clearColorIndex()

void lvppCanvasIndexed::clearColorIndex ( )

Remove all colors from the indexed color set.

◆ drawCenteredRectWithFill()

void lvppCanvasIndexed::drawCenteredRectWithFill ( lv_coord_t  xBorder,
lv_coord_t  yBorder,
lv_color_t  borderColor,
lv_color_t  fillColor 
)

Draw a centered rectangle on the canvas and fill in the rectangle. Will have xBorder/yBorder around it.

Parameters
xBorder,yBorderThe border size on each x-side and each y-side of the rectangle
borderColorColor of the rectangle's border lines.
fillColorColor to fill in the rectangle.

◆ drawCenteredRectWithFillByIndex()

void lvppCanvasIndexed::drawCenteredRectWithFillByIndex ( lv_coord_t  xBorder,
lv_coord_t  yBorder,
lv_color_t  borderColorInd,
lv_color_t  fillColorInd 
)

Draw a centered rectangle on the canvas and fill in the rectangle. Will have xBorder/yBorder around it. This uses index colors.

Parameters
xBorder,yBorderThe border size on each x-side and each y-side of the rectangle
borderColorIndThe index of the color to use. This is not a true color but only an index.
fillColorIndThe index of the color to use. This is not a true color but only an index.

◆ drawCenteredRectWithoutFill()

void lvppCanvasIndexed::drawCenteredRectWithoutFill ( lv_coord_t  xBorder,
lv_coord_t  yBorder,
lv_color_t  borderColor 
)

Draw a centered rectangle on the canvas. Will have xBorder/yBorder around it.

Parameters
xBorder,yBorderThe border size on each x-side and each y-side of the rectangle
borderColorColor of the rectangle's border lines.

◆ drawCenteredRectWithoutFillByIndex()

void lvppCanvasIndexed::drawCenteredRectWithoutFillByIndex ( lv_coord_t  xBorder,
lv_coord_t  yBorder,
lv_color_t  borderColorInd 
)

Draw a centered rectangle on the canvas. Will have xBorder/yBorder around it. This uses index colors.

Parameters
xBorder,yBorderThe border size on each x-side and each y-side of the rectangle
borderColorIndThe index of the color to use. This is not a true color but only an index.

◆ drawLineHoriz()

void lvppCanvasIndexed::drawLineHoriz ( lv_coord_t  x1,
lv_coord_t  y1,
lv_coord_t  w,
lv_color_t  color 
)

Draw a horizontal line on the canvas.

Parameters
x1,y1Starting point of the line to be drawn.
wWidth of the line to be drawn.
colorColor of the line to be drawn.

◆ drawLineHorizByIndex()

void lvppCanvasIndexed::drawLineHorizByIndex ( lv_coord_t  x1,
lv_coord_t  y1,
lv_coord_t  w,
lv_color_t  indexCol 
)

Draw a horizontal line on the canvas using an index color.

Parameters
x1,y1Starting point of the line to be drawn.
wWidth of the line to be drawn.
indexColThe index of the color to use. This is not a true color but only an index.

◆ drawLineVert()

void lvppCanvasIndexed::drawLineVert ( lv_coord_t  x1,
lv_coord_t  y1,
lv_coord_t  h,
lv_color_t  color 
)

Draw a verical line on the canvas.

Parameters
x1,y1Starting point of the line to be drawn.
hHeight of the line to be drawn.
colorColor of the line to be drawn.

◆ drawLineVertByIndex()

void lvppCanvasIndexed::drawLineVertByIndex ( lv_coord_t  x1,
lv_coord_t  y1,
lv_coord_t  h,
lv_color_t  indexCol 
)

Draw a verical line on the canvas using an index color.

Parameters
x1,y1Starting point of the line to be drawn.
hHeight of the line to be drawn.
indexColThe index of the color to use. This is not a true color but only an index.

◆ drawPixel()

void lvppCanvasIndexed::drawPixel ( lv_coord_t  x,
lv_coord_t  y,
lv_color_t  color 
)

Draw a single pixel on to the canvas.

Parameters
xX location
yY location
colorColor to be drawn.

◆ drawPixelByIndex()

void lvppCanvasIndexed::drawPixelByIndex ( lv_coord_t  x,
lv_coord_t  y,
lv_color_t  colorIndex 
)

Draw a single pixel on to the canvas using an index color.

Parameters
xX location
yY location
colorIndexThe index of the color to use. This is not a true color but only an index.

◆ drawRectWithFill()

void lvppCanvasIndexed::drawRectWithFill ( lv_coord_t  x1,
lv_coord_t  y1,
lv_coord_t  w,
lv_coord_t  h,
lv_color_t  borderColor,
lv_color_t  fillColor 
)

Draw a rectangle on the canvas and fill in the center of the rectangle.

Parameters
x1,y1Starting point of the rectangle
w,hWidth and height of the rectangle
borderColorColor of the rectangle's border lines.
fillColorColor to fill in the rectangle.

◆ drawRectWithFillByIndex()

void lvppCanvasIndexed::drawRectWithFillByIndex ( lv_coord_t  x1,
lv_coord_t  y1,
lv_coord_t  w,
lv_coord_t  h,
lv_color_t  borderColorInd,
lv_color_t  fillColorInd 
)

Draw a rectangle on the canvas and fill in the center of the rectangle. This uses index colors.

Parameters
x1,y1Starting point of the rectangle
w,hWidth and height of the rectangle
borderColorIndThe index of the color to use. This is not a true color but only an index.
fillColorIndThe index of the color to use. This is not a true color but only an index.

◆ drawRectWithoutFill()

void lvppCanvasIndexed::drawRectWithoutFill ( lv_coord_t  x1,
lv_coord_t  y1,
lv_coord_t  w,
lv_coord_t  h,
lv_color_t  borderColor 
)

Draw a rectangle on the canvas without filling in the rectangle.

Parameters
x1,y1Starting point of the rectangle
w,hWidth and height of the rectangle
borderColorColor of the rectangle's border lines.

◆ drawRectWithoutFillByIndex()

void lvppCanvasIndexed::drawRectWithoutFillByIndex ( lv_coord_t  x1,
lv_coord_t  y1,
lv_coord_t  w,
lv_coord_t  h,
lv_color_t  borderColorInd 
)

Draw a rectangle on the canvas without filling in the rectangle using an index color.

Parameters
x1,y1Starting point of the rectangle
w,hWidth and height of the rectangle
borderColorIndThe index of the color to use. This is not a true color but only an index.

◆ getIndexFromColor()

bool lvppCanvasIndexed::getIndexFromColor ( lv_color_t  col,
lv_color_t &  ind 
)

Get the Index of a single Color.

Parameters
colColor being requested for translation
indReference to the index which will be returned (if successful)
Returns
true If the color col is found.
false If the color col is not found in the indexed color set.

◆ setbgColor()

void lvppCanvasIndexed::setbgColor ( lv_color_t  bgColor)

Set the background color of the canvas.

Parameters
bgColorThe color to be used in painting the background. This is an lv_color_t from LVGL.

◆ setbgColorByIndex()

void lvppCanvasIndexed::setbgColorByIndex ( lv_color_t  bgColorIndex)

Set the backgrond color from an index color.

Parameters
bgColorIndexThe index of the color to use. This is not a true color but only an index.

Member Data Documentation

◆ colorIndexesUsed

uint8_t lvppCanvasIndexed::colorIndexesUsed
protected

How many colors have presently been used in the indexed color set.

◆ height

lv_coord_t lvppCanvasIndexed::height
protected

◆ maxColorIndexesAllowed

uint16_t lvppCanvasIndexed::maxColorIndexesAllowed
protected

Number of color indexes available based on the color depth at creation time.

◆ pBuffer

lv_color_t* lvppCanvasIndexed::pBuffer
protected
Todo:
This use of LV_COLOR_DEPTH is believed to be correct at least for 8 and 16, but is this complete ?

◆ width

lv_coord_t lvppCanvasIndexed::width
protected

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