class OverlayCategoryLegend : public OverlayItem

A color legend used to indicate the interpretation of the colors in the model.

For instance, a part color legend.

Any number of combinations of label and color can be specified.

See also

OverlayItem and View

Public Types

enum TickMarksPosition

Position of the legend tick marks.


enumerator LEFT

Draw tick marks on the left side of the color legend.

enumerator RIGHT

Draw tick marks on the right side of the color legend.

enumerator TOP

Draw tick marks above the color legend.

enumerator BOTTOM

Draw tick marks below the color legend.

enumerator FOLLOW_LAYOUT

Automatically position the tick marks left or right based on the color legend’s alignment in the view.

enum Direction

Direction of color legend bar.


enumerator HORIZONTAL

Draw horizontal color legend bar.

enumerator VERTICAL

Draw vertical color legend bar.

Public Functions


Constructs an overlay category legend.

OverlayCategoryLegend(Font *titleFont, Font *categoryFont)

Constructs an overlay category legend with custom fonts.

virtual unsigned int width() const

Returns the total width of the overlay item.

virtual unsigned int height() const

Returns the total height of the overlay item.

virtual int priority() const

Returns the render priority of the item.

virtual void setPriority(int priority)

Sets render priority of the item.

The render priority determines the order in which item get rendered. Items with lower priorities get rendered first. The default priority is 10.

virtual void setSize(unsigned int width, unsigned int height)

Sets the size of the legend, in pixels.

void setWidthToFitText()

Sets the width of the legend to fit the current text.

size_t categoryCount() const

Returns the number of categories.

Str categoryText(size_t index) const

Returns the text/label for the category with the given index.

Color3f categoryColor(size_t index) const

Returns the color of the category with the given index.

void addCategory(const Str &text, Color3f color)

Adds a category (label & color) to the legend.

void removeAllCategories()

Removes all categories from the legend.

Str title() const

Returns the title of the legend.

void setTitle(const Str &title)

Sets the title of the legend.

Multiple lines can be specified by using the ‘\n’ separator

Color3f textColor() const

Returns the text color.

void setTextColor(const Color3f &color)

Sets the text color for the category labels. Also sets the border color for the category bar.

TickMarksPosition tickMarksPosition() const

Returns if the labels are drawn on the left side, right side or automatically based on view layout.

void setTickMarksPosition(TickMarksPosition position)

If set to true, the category colors will be drawn on the right side and the text will be right aligned on the left side.

Direction direction() const

Returns the direction of the color legend bar.

void setDirection(Direction direction)

Sets the direction of the color legend bar.