|
DUDS
|
Distributed Update of Data from Something
|
Renders menus to bit-per-pixel images. More...
#include <BppMenuRenderer.hpp>
Public Types | |
| typedef duds::general::BitFlags< struct BppMenuFlags > | Flags |
| A type for configuration flags. More... | |
| enum | ScrollBarPlacement { ScrollRight, ScrollLeft, ScrollBottom, ScrollTop } |
| Values used to control which edge of the menu will host the scroll bar. More... | |
Public Member Functions | |
| BppMenuRenderer (Flags cfg=Flags::Zero()) | |
| Constructs a new menu renderer without a string cache or font. More... | |
| BppMenuRenderer (const duds::ui::graphics::BppStringCacheSptr &cachePtr, Flags cfg=Flags::Zero()) | |
| Constructs a new menu renderer. More... | |
| BppMenuRenderer (const duds::ui::graphics::BppStringCacheSptr &cachePtr, int vmItems, Flags cfg=Flags::Zero()) | |
| Constructs a new menu renderer; best for horizontally oriented menus. More... | |
| void | addScrollBar (std::uint16_t width=1, std::uint16_t margin=1, std::uint16_t minsize=4, ScrollBarPlacement place=ScrollRight) |
| Adds or replaces a scroll bar on the menu. More... | |
| const duds::ui::graphics::ConstBppImageSptr & | disabledIcon () const |
| Returns the currently configured disabled icon image. More... | |
| void | disabledIcon (const duds::ui::graphics::ConstBppImageSptr &img) |
| Changes the optional icon used to inform the user that a menu item is currently disabled. More... | |
| Flags | flags () const |
| Returns the configuration flags for this renderer. More... | |
| void | flags (Flags cfg) |
| Changes the configuration flags for this renderer. More... | |
| bool | hasScrollBar () const |
| Returns true if a scroll bar is in use. More... | |
| const duds::ui::graphics::ImageDimensions & | iconDimensions () const |
| Returns the dimensions used for rendering icons stored inside menu items derived from BppIconItem. More... | |
| void | iconDimensions (const duds::ui::graphics::ImageDimensions &dim) |
| Sets the dimensions used for rendering icons stored inside menu items derived from BppIconItem. More... | |
| std::uint16_t | iconTextMargin () const |
| Returns the size of the margin between icons from menu items and the text label of the item. More... | |
| void | iconTextMargin (std::uint16_t itm) |
| Sets the size of the margin between icons from menu items and the text label of the item. More... | |
| std::uint16_t | itemMargin () const |
| Returns the margin in pixels placed bewteen each menu item. More... | |
| void | itemMargin (std::uint16_t im) |
| Changes the margin in pixels placed bewteen each menu item. More... | |
| std::uint16_t | maxVisible () const |
| Returns the maximum number of visible items to show on the menu; try to avoid calling. More... | |
| void | maxVisible (std::uint16_t i) |
| Sets the maximum number of visible items for horizontally oriented menus. More... | |
| void | removeScrollBar () |
| Removes the scroll bar from the menu. More... | |
| void | render (duds::ui::graphics::BppImageSptr &dest, duds::ui::menu::MenuOutputAccess &mova) |
| Renders a menu to the given image. More... | |
| void | render (duds::ui::graphics::BppImageSptr &dest, duds::ui::menu::MenuOutput &mov) |
| Renders a menu to the given image. More... | |
| duds::ui::graphics::BppImageSptr | render (const duds::ui::graphics::ImageDimensions &dim, duds::ui::menu::MenuOutputAccess &mova) |
| Renders a menu of the given size. More... | |
| duds::ui::graphics::BppImageSptr | render (const duds::ui::graphics::ImageDimensions &dim, duds::ui::menu::MenuOutput &mov) |
| Renders a menu of the given size. More... | |
| const duds::ui::graphics::ConstBppImageSptr & | selectedIcon () const |
| Returns the currently set icon used to indicate item selection. More... | |
| void | selectedIcon (const duds::ui::graphics::ConstBppImageSptr &img) |
| Changes the optional selection icon used to inform the user what item they have selected and are poised to chose. More... | |
| const duds::ui::graphics::BppStringCacheSptr & | stringCache () const |
| Returns the string cache currently used to render menu item text. More... | |
| void | stringCache (const duds::ui::graphics::BppStringCacheSptr &sc) |
| Changes the string cache used to render menu item text. More... | |
| const duds::ui::graphics::ConstBppImageSptr & | toggledOffIcon () const |
| Returns the icon used to signify a toggle state in the off position. More... | |
| void | toggledOffIcon (const duds::ui::graphics::ConstBppImageSptr &img) |
| Changes the option icon used to signify a toggle state in the off position. More... | |
| const duds::ui::graphics::ConstBppImageSptr & | toggledOnIcon () const |
| Returns the icon used to signify a toggle state in the on position. More... | |
| void | toggledOnIcon (const duds::ui::graphics::ConstBppImageSptr &img) |
| Changes the option icon used to signify a toggle state in the on position. More... | |
| std::uint16_t | valueMargin () const |
| Returns the margin in pixels between a menu item's label text and its value text. More... | |
| void | valueMargin (std::uint16_t m) |
| Changes the margin in pixels between a menu item's label text and its value text. More... | |
| std::uint16_t | valueWidth () const |
| Returns the width in pixels of the value column. More... | |
| void | valueWidth (std::uint16_t w) |
| Changes the width in pixels of the value column. More... | |
Static Public Attributes | |
| static constexpr Flags | DoNotShowText = Flags::Bit(6) |
| Only show icons, not text, for the menu items. More... | |
| static constexpr Flags | HorizontalList = Flags::Bit(3) |
| Items are arranged horizontally instead of vertically. More... | |
| static constexpr Flags | InvertSelected = Flags::Bit(4) |
| The selected item will be rendered inverted. More... | |
| static constexpr Flags | ScrollBarMask = Flags(3) |
| Mask that defines where the ScrollBarPlacement value is put in the configuration flags. More... | |
| static constexpr Flags | ScrollBarNeverHides = Flags::Bit(2) |
| True to always show the scroll bar. More... | |
| static constexpr Flags | ValueRightJustified = Flags::Bit(5) |
| Right justify value text when values are placed in a column separate from the item label. More... | |
Private Member Functions | |
| void | recalculateDimensions (duds::ui::graphics::ImageDimensions fitDim) |
| Recalculates the dimension values needed to render a menu that fits into the given dimensions. More... | |
Private Attributes | |
| duds::ui::graphics::BppStringCacheSptr | cache |
| Pre-rendered strings for menu text. More... | |
| duds::ui::graphics::ImageDimensions | destDim |
| Destination dimensions; used to tell when to recompute dimensions of parts of the menu. More... | |
| duds::ui::graphics::ConstBppImageSptr | disIcon |
| Icon used to denote a disabled menu item. More... | |
| Flags | flgs |
| Option flags that modify how the menu is rendered. More... | |
| std::uint16_t | fracshow |
| The number of pixels to show of a partially visible menu item. More... | |
| duds::ui::graphics::ImageDimensions | iconDim |
| The size of a menu item's icon. More... | |
| std::uint16_t | iconTxMg = 0 |
| Space in pixels to have between icons and text. More... | |
| duds::ui::graphics::ImageDimensions | itemDim |
| Computed dimensions of a complete menu item. More... | |
| std::uint16_t | itemMg = 0 |
| The margin in pixels between menu items. More... | |
| std::uint16_t | items = 0 |
| Number of items to display. More... | |
| std::unique_ptr< duds::ui::graphics::BppPositionIndicator > | posInd |
| Optional position indicator to show user location within the menu. More... | |
| std::uint16_t | scrollMg = 0 |
| Space in pixels to have between label or value text and the scroll bar. More... | |
| std::uint16_t | scrollWidth |
| Thw width of the scroll bar in pixels. More... | |
| std::uint16_t | selDisWidth = 0 |
| The maximum width of the selection icon and the disabled icon. More... | |
| duds::ui::graphics::ConstBppImageSptr | selIcon |
| Icon used to denote a selected menu item. More... | |
| duds::ui::graphics::ImageDimensions | textDim |
| The size of a menu item's text. More... | |
| std::uint16_t | toggleWidth = 0 |
| The maximum width of the toggle icons. More... | |
| duds::ui::graphics::ConstBppImageSptr | togOffIcon |
| Icon used to denote a menu item in its toggled off state. More... | |
| duds::ui::graphics::ConstBppImageSptr | togOnIcon |
| Icon used to denote a menu item in its toggled on state. More... | |
| std::uint16_t | valMg = 0 |
| The margin in pixels between the label and value columns,. More... | |
| std::uint16_t | valWidth = 0 |
| The width of the value column. More... | |
Static Private Attributes | |
| static constexpr Flags | Calculated = Flags::Bit(15) |
| When set, indicates that internal dimension values have been calculated. More... | |
| static constexpr Flags | InternalMask = Flags(0xFF00) |
| The second byte (the one next to the least significant byte) is reserved for internal flags. More... | |
| static constexpr Flags | ScrollBarShown = Flags::Bit(14) |
| Indicates that the scroll bar was rendered on the previous render call. More... | |
Renders menus to bit-per-pixel images.
This class is not thread-safe; if rendering from multiple threads is required, use a separate instance for each thread.
The menu items can be ordered vertically (default) or horizontally. If horizontal, all items will be in the same row. Either way, each item will have the same columns, each the same size, which may include one or more of the following in the given order:
Each renderer instance caches information used to define the bounds of each MenuItem based on the instance's configuration, the provided font inside the string cache, and the size of the output image. When the configuration changes in a way that could affect the size of the items, and when the size of the output image changes, the internal item size data is recomputed. As a result, it works best to configure everything once and use the same size destination image for all menu renders. In that case, rendering different menus with one renderer incurs no size-recompute penalty.
Menus are oriented vertically (one item per row) by default. In this case, the number of menu items shown is based upon the computed size of each item and the size of the destination image. For horizontally oriented (one item per column) menus, the maximum number of items to show must be provided in a call to maxVisible(std::uint16_t) before rendering. Each item will take the same amount of space on the destination image.
A scoll bar may be optionally added to the menu by a call to addScrollBar(). By default, the scroll bar will only be present if there are too many menu items to fit in the destination image.
Horizontal ordering needs testing; assume broken for now.
Support rendering the selected menu item's description text somewhere.
Definition at line 120 of file BppMenuRenderer.hpp.
| typedef duds::general::BitFlags<struct BppMenuFlags> duds::ui::menu::renderers::BppMenuRenderer::Flags |
A type for configuration flags.
Definition at line 134 of file BppMenuRenderer.hpp.
Values used to control which edge of the menu will host the scroll bar.
| Enumerator | |
|---|---|
| ScrollRight | |
| ScrollLeft | |
| ScrollBottom | |
| ScrollTop | |
Definition at line 125 of file BppMenuRenderer.hpp.
|
inline |
Constructs a new menu renderer without a string cache or font.
This can work well for menus that won't render any text, or will be further configured later.
| cfg | The inital configuration flags. |
Definition at line 282 of file BppMenuRenderer.hpp.
|
inline |
Constructs a new menu renderer.
| cachePtr | The cache of rendered strings to use for menu text. |
| cfg | The inital configuration flags. |
Definition at line 288 of file BppMenuRenderer.hpp.
|
inline |
Constructs a new menu renderer; best for horizontally oriented menus.
| cachePtr | The cache of rendered strings to use for menu text. |
| vmItems | The maximum number of visible menu items. This is only useful if the menu is oriented horizontally. |
| cfg | The inital configuration flags. |
Definition at line 299 of file BppMenuRenderer.hpp.
| void duds::ui::menu::renderers::BppMenuRenderer::addScrollBar | ( | std::uint16_t | width = 1, |
| std::uint16_t | margin = 1, |
||
| std::uint16_t | minsize = 4, |
||
| ScrollBarPlacement | place = ScrollRight |
||
| ) |
Adds or replaces a scroll bar on the menu.
The menu only supports a single scroll bar.
| width | The width of the indicator, or slider, in pixels. |
| margin | The width of the border between the indicator and menu item(s). |
| minsize | The minimum length of the indicator (slider). |
| place | The edge occupied by the scroll bar. |
Definition at line 45 of file BppMenuRenderer.cpp.
|
inline |
Returns the currently configured disabled icon image.
Definition at line 334 of file BppMenuRenderer.hpp.
|
inline |
Changes the optional icon used to inform the user that a menu item is currently disabled.
Definition at line 341 of file BppMenuRenderer.hpp.
|
inline |
Returns the configuration flags for this renderer.
Definition at line 307 of file BppMenuRenderer.hpp.
Referenced by recalculateDimensions(), and render().
|
inline |
Changes the configuration flags for this renderer.
Definition at line 313 of file BppMenuRenderer.hpp.
|
inline |
Returns true if a scroll bar is in use.
Definition at line 507 of file BppMenuRenderer.hpp.
|
inline |
Returns the dimensions used for rendering icons stored inside menu items derived from BppIconItem.
Definition at line 377 of file BppMenuRenderer.hpp.
| void duds::ui::menu::renderers::BppMenuRenderer::iconDimensions | ( | const duds::ui::graphics::ImageDimensions & | dim | ) |
Sets the dimensions used for rendering icons stored inside menu items derived from BppIconItem.
Use an empty size to prevent icons from being rendered.
Definition at line 28 of file BppMenuRenderer.cpp.
|
inline |
Returns the size of the margin between icons from menu items and the text label of the item.
Definition at line 393 of file BppMenuRenderer.hpp.
|
inline |
Sets the size of the margin between icons from menu items and the text label of the item.
Definition at line 402 of file BppMenuRenderer.hpp.
|
inline |
Returns the margin in pixels placed bewteen each menu item.
Definition at line 472 of file BppMenuRenderer.hpp.
|
inline |
Changes the margin in pixels placed bewteen each menu item.
| im | The new margin size. |
Definition at line 479 of file BppMenuRenderer.hpp.
|
inline |
Returns the maximum number of visible items to show on the menu; try to avoid calling.
Definition at line 428 of file BppMenuRenderer.hpp.
| void duds::ui::menu::renderers::BppMenuRenderer::maxVisible | ( | std::uint16_t | i | ) |
Sets the maximum number of visible items for horizontally oriented menus.
For vertically oriented menus, this does nothing.
| i | The number of items to show. |
Definition at line 38 of file BppMenuRenderer.cpp.
|
private |
Recalculates the dimension values needed to render a menu that fits into the given dimensions.
| fitDim | The dimensions in which the menu must fit. |
| BppMenuDestinationTooSmall | Current settings will not fit the menu item(s) into fitDim. |
Definition at line 68 of file BppMenuRenderer.cpp.
Referenced by render().
| void duds::ui::menu::renderers::BppMenuRenderer::removeScrollBar | ( | ) |
Removes the scroll bar from the menu.
Definition at line 62 of file BppMenuRenderer.cpp.
| void duds::ui::menu::renderers::BppMenuRenderer::render | ( | duds::ui::graphics::BppImageSptr & | dest, |
| duds::ui::menu::MenuOutputAccess & | mova | ||
| ) |
Renders a menu to the given image.
| dest | The destination image. If its size is different than the last image used, or if this is the first time rendering, size data for the menu items and their parts will be recomputed. |
| mova | Output access to the menu to render. |
| BppMenuLacksStringCache | The renderer is configured to show text, but doesn't have the string cache needed to render the text. |
| BppMenuDestinationTooSmall | Current settings will not fit the menu item(s) into dest. |
Definition at line 188 of file BppMenuRenderer.cpp.
|
inline |
Renders a menu to the given image.
| dest | The destination image. If its size is different than the last image used, or if this is the first time rendering, size data for the menu items and their parts will be recomputed. |
| mov | The MenuOutput of the menu to render. An access object to the menu output is made inside this function. |
| BppMenuLacksStringCache | The renderer is configured to show text, but doesn't have the string cache needed to render the text. |
| BppMenuDestinationTooSmall | Current settings will not fit the menu item(s) into dest. |
Definition at line 541 of file BppMenuRenderer.hpp.
|
inline |
Renders a menu of the given size.
| dim | The size of the image that will hold the rendered menu. If the size is different than the last size used, or if this is the first time rendering, size data for the menu items and their parts will be recomputed. |
| mova | Output access to the menu to render. |
| BppMenuLacksStringCache | The renderer is configured to show text, but doesn't have the string cache needed to render the text. |
| BppMenuDestinationTooSmall | Current settings will not fit the menu item(s) into dest. |
Definition at line 562 of file BppMenuRenderer.hpp.
|
inline |
Renders a menu of the given size.
| dim | The size of the image that will hold the rendered menu. If the size is different than the last size used, or if this is the first time rendering, size data for the menu items and their parts will be recomputed. |
| mov | The MenuOutput of the menu to render. An access object to the menu output is made inside this function. |
| BppMenuLacksStringCache | The renderer is configured to show text, but doesn't have the string cache needed to render the text. |
| BppMenuDestinationTooSmall | Current settings will not fit the menu item(s) into dest. |
Definition at line 585 of file BppMenuRenderer.hpp.
|
inline |
Returns the currently set icon used to indicate item selection.
This shows the user which option they are poised to chose.
Definition at line 320 of file BppMenuRenderer.hpp.
|
inline |
Changes the optional selection icon used to inform the user what item they have selected and are poised to chose.
Definition at line 327 of file BppMenuRenderer.hpp.
|
inline |
Returns the string cache currently used to render menu item text.
Definition at line 409 of file BppMenuRenderer.hpp.
|
inline |
Changes the string cache used to render menu item text.
Definition at line 415 of file BppMenuRenderer.hpp.
|
inline |
Returns the icon used to signify a toggle state in the off position.
Definition at line 348 of file BppMenuRenderer.hpp.
|
inline |
Changes the option icon used to signify a toggle state in the off position.
Definition at line 355 of file BppMenuRenderer.hpp.
|
inline |
Returns the icon used to signify a toggle state in the on position.
Definition at line 362 of file BppMenuRenderer.hpp.
|
inline |
Changes the option icon used to signify a toggle state in the on position.
Definition at line 369 of file BppMenuRenderer.hpp.
|
inline |
Returns the margin in pixels between a menu item's label text and its value text.
Definition at line 456 of file BppMenuRenderer.hpp.
|
inline |
Changes the margin in pixels between a menu item's label text and its value text.
This margin is only used if the value width is non-zero.
| m | The new margin size. |
Definition at line 465 of file BppMenuRenderer.hpp.
|
inline |
Returns the width in pixels of the value column.
Definition at line 440 of file BppMenuRenderer.hpp.
|
inline |
Changes the width in pixels of the value column.
| w | The new width of the pixels column. If zero, the column will be omitted. |
Definition at line 448 of file BppMenuRenderer.hpp.
|
private |
Pre-rendered strings for menu text.
Definition at line 202 of file BppMenuRenderer.hpp.
Referenced by recalculateDimensions(), and render().
|
staticprivate |
When set, indicates that internal dimension values have been calculated.
This avoids the need to recalculate them every time the menu is rendered.
Definition at line 173 of file BppMenuRenderer.hpp.
Referenced by addScrollBar(), iconDimensions(), maxVisible(), recalculateDimensions(), removeScrollBar(), and render().
|
private |
Destination dimensions; used to tell when to recompute dimensions of parts of the menu.
Definition at line 215 of file BppMenuRenderer.hpp.
Referenced by recalculateDimensions(), and render().
|
private |
Icon used to denote a disabled menu item.
Definition at line 190 of file BppMenuRenderer.hpp.
Referenced by recalculateDimensions(), and render().
|
static |
Only show icons, not text, for the menu items.
This will prevent values, as well as text naming a menu item, from being shown.
Definition at line 163 of file BppMenuRenderer.hpp.
Referenced by recalculateDimensions(), and render().
|
private |
Option flags that modify how the menu is rendered.
Definition at line 225 of file BppMenuRenderer.hpp.
Referenced by addScrollBar(), iconDimensions(), maxVisible(), recalculateDimensions(), removeScrollBar(), and render().
|
private |
The number of pixels to show of a partially visible menu item.
Definition at line 266 of file BppMenuRenderer.hpp.
Referenced by recalculateDimensions(), and render().
|
static |
Items are arranged horizontally instead of vertically.
Definition at line 148 of file BppMenuRenderer.hpp.
Referenced by maxVisible(), recalculateDimensions(), and render().
|
private |
The size of a menu item's icon.
Definition at line 220 of file BppMenuRenderer.hpp.
Referenced by iconDimensions(), recalculateDimensions(), and render().
|
private |
Space in pixels to have between icons and text.
Definition at line 250 of file BppMenuRenderer.hpp.
Referenced by iconDimensions(), recalculateDimensions(), and render().
|
staticprivate |
The second byte (the one next to the least significant byte) is reserved for internal flags.
Definition at line 178 of file BppMenuRenderer.hpp.
|
static |
The selected item will be rendered inverted.
Definition at line 152 of file BppMenuRenderer.hpp.
Referenced by render().
|
private |
Computed dimensions of a complete menu item.
Definition at line 206 of file BppMenuRenderer.hpp.
Referenced by recalculateDimensions(), and render().
|
private |
The margin in pixels between menu items.
Definition at line 246 of file BppMenuRenderer.hpp.
Referenced by recalculateDimensions(), and render().
|
private |
Number of items to display.
Definition at line 258 of file BppMenuRenderer.hpp.
Referenced by maxVisible(), recalculateDimensions(), and render().
|
private |
Optional position indicator to show user location within the menu.
Definition at line 182 of file BppMenuRenderer.hpp.
Referenced by addScrollBar(), recalculateDimensions(), removeScrollBar(), and render().
|
static |
Mask that defines where the ScrollBarPlacement value is put in the configuration flags.
Definition at line 139 of file BppMenuRenderer.hpp.
Referenced by addScrollBar(), recalculateDimensions(), and render().
|
static |
True to always show the scroll bar.
If not set, the scroll bar will not be shown if the menu fits within the destination image.
Definition at line 144 of file BppMenuRenderer.hpp.
Referenced by render().
|
staticprivate |
Indicates that the scroll bar was rendered on the previous render call.
Definition at line 168 of file BppMenuRenderer.hpp.
Referenced by recalculateDimensions(), removeScrollBar(), and render().
|
private |
Space in pixels to have between label or value text and the scroll bar.
Definition at line 254 of file BppMenuRenderer.hpp.
Referenced by addScrollBar(), recalculateDimensions(), removeScrollBar(), and render().
|
private |
Thw width of the scroll bar in pixels.
Definition at line 262 of file BppMenuRenderer.hpp.
Referenced by addScrollBar(), recalculateDimensions(), removeScrollBar(), and render().
|
private |
The maximum width of the selection icon and the disabled icon.
Definition at line 229 of file BppMenuRenderer.hpp.
Referenced by recalculateDimensions(), and render().
|
private |
Icon used to denote a selected menu item.
Definition at line 186 of file BppMenuRenderer.hpp.
Referenced by recalculateDimensions(), and render().
|
private |
The size of a menu item's text.
Definition at line 210 of file BppMenuRenderer.hpp.
Referenced by recalculateDimensions(), and render().
|
private |
The maximum width of the toggle icons.
Definition at line 233 of file BppMenuRenderer.hpp.
Referenced by recalculateDimensions(), and render().
|
private |
Icon used to denote a menu item in its toggled off state.
Definition at line 194 of file BppMenuRenderer.hpp.
Referenced by recalculateDimensions(), and render().
|
private |
Icon used to denote a menu item in its toggled on state.
Definition at line 198 of file BppMenuRenderer.hpp.
Referenced by recalculateDimensions(), and render().
|
private |
The margin in pixels between the label and value columns,.
Definition at line 242 of file BppMenuRenderer.hpp.
Referenced by recalculateDimensions(), and render().
|
static |
Right justify value text when values are placed in a column separate from the item label.
If the value column width is zero or not provided, this flag will have no effect.
Definition at line 158 of file BppMenuRenderer.hpp.
Referenced by render().
|
private |
The width of the value column.
If zero, the value will be combined with the item label and will not have its own column.
Definition at line 238 of file BppMenuRenderer.hpp.
Referenced by recalculateDimensions(), and render().