DUDS
Distributed Update of Data from Something
BppMenuRenderer.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of the DUDS project. It is subject to the BSD-style
3  * license terms in the LICENSE file found in the top-level directory of this
4  * distribution and at https://github.com/jjackowski/duds/blob/master/LICENSE.
5  * No part of DUDS, including this file, may be copied, modified, propagated,
6  * or distributed except according to the terms contained in the LICENSE file.
7  *
8  * Copyright (C) 2020 Jeff Jackowski
9  */
10 #ifndef BPPMENURENDERER_HPP
11 #define BPPMENURENDERER_HPP
12 
16 
17 namespace duds { namespace ui { namespace menu { namespace renderers {
18 
22 struct BppMenuRendererError : virtual std::exception, virtual boost::exception { };
23 
29 
34 
39 
121 public:
129  ScrollTop
130  };
139  static constexpr Flags ScrollBarMask = Flags(3);
144  static constexpr Flags ScrollBarNeverHides = Flags::Bit(2);
148  static constexpr Flags HorizontalList = Flags::Bit(3);
152  static constexpr Flags InvertSelected = Flags::Bit(4);
158  static constexpr Flags ValueRightJustified = Flags::Bit(5);
163  static constexpr Flags DoNotShowText = Flags::Bit(6);
164 private:
168  static constexpr Flags ScrollBarShown = Flags::Bit(14);
173  static constexpr Flags Calculated = Flags::Bit(15);
178  static constexpr Flags InternalMask = Flags(0xFF00);
182  std::unique_ptr<duds::ui::graphics::BppPositionIndicator> posInd;
225  Flags flgs;
229  std::uint16_t selDisWidth = 0;
233  std::uint16_t toggleWidth = 0;
238  std::uint16_t valWidth = 0;
242  std::uint16_t valMg = 0;
246  std::uint16_t itemMg = 0;
250  std::uint16_t iconTxMg = 0;
254  std::uint16_t scrollMg = 0;
258  std::uint16_t items = 0;
262  std::uint16_t scrollWidth;
266  std::uint16_t fracshow;
274  void recalculateDimensions(duds::ui::graphics::ImageDimensions fitDim);
275 public:
282  BppMenuRenderer(Flags cfg = Flags::Zero()) : flgs(cfg & ~InternalMask) { }
290  Flags cfg = Flags::Zero()
291  ) : cache(cachePtr), flgs(cfg & ~InternalMask) { }
301  int vmItems,
302  Flags cfg = Flags::Zero()
303  ) : cache(cachePtr), items(vmItems), flgs(cfg & ~InternalMask) { }
307  Flags flags() const {
308  return flgs;
309  }
313  void flags(Flags cfg) {
314  flgs = cfg & ~InternalMask;
315  }
321  return selIcon;
322  }
328  selIcon = img;
329  flgs.clear(Calculated);
330  }
335  return disIcon;
336  }
342  disIcon = img;
343  flgs.clear(Calculated);
344  }
349  return togOffIcon;
350  }
356  togOffIcon = img;
357  flgs.clear(Calculated);
358  }
363  return togOnIcon;
364  }
370  togOnIcon = img;
371  flgs.clear(Calculated);
372  }
378  return iconDim;
379  }
388  void iconDimensions(const duds::ui::graphics::ImageDimensions &dim);
393  std::uint16_t iconTextMargin() const {
394  return iconTxMg;
395  }
402  void iconTextMargin(std::uint16_t itm) {
403  iconTxMg = itm;
404  flgs.clear(Calculated);
405  }
410  return cache;
411  }
416  cache = sc;
417  flgs.clear(Calculated);
418  }
428  std::uint16_t maxVisible() const {
429  return items;
430  }
436  void maxVisible(std::uint16_t i);
440  std::uint16_t valueWidth() const {
441  return valWidth;
442  }
448  void valueWidth(std::uint16_t w) {
449  valWidth = w;
450  flgs.clear(Calculated);
451  }
456  std::uint16_t valueMargin() const {
457  return valMg;
458  }
465  void valueMargin(std::uint16_t m) {
466  valMg = m;
467  flgs.clear(Calculated);
468  }
472  std::uint16_t itemMargin() const {
473  return itemMg;
474  }
479  void itemMargin(std::uint16_t im) {
480  itemMg = im;
481  flgs.clear(Calculated);
482  }
494  void addScrollBar(
495  std::uint16_t width = 1,
496  std::uint16_t margin = 1,
497  std::uint16_t minsize = 4,
498  ScrollBarPlacement place = ScrollRight
499  );
503  void removeScrollBar();
507  bool hasScrollBar() const {
508  return scrollWidth != 0;
509  }
523  void render(
526  );
541  void render(
544  ) {
545  duds::ui::menu::MenuOutputAccess mova(mov, items);
546  render(dest, mova);
547  }
565  ) {
567  render(img, mova);
568  return img;
569  }
588  ) {
589  duds::ui::menu::MenuOutputAccess mova(mov, items);
590  return render(dim, mova);
591  }
592 };
593 
594 } } } }
595 
596 #endif // #ifndef BPPMENURENDERER_HPP
std::shared_ptr< BppStringCache > BppStringCacheSptr
A std::shared_ptr to a BppStringCache object.
BppMenuRenderer(const duds::ui::graphics::BppStringCacheSptr &cachePtr, Flags cfg=Flags::Zero())
Constructs a new menu renderer.
const duds::ui::graphics::ConstBppImageSptr & disabledIcon() const
Returns the currently configured disabled icon image.
Renders menus to bit-per-pixel images.
void toggledOnIcon(const duds::ui::graphics::ConstBppImageSptr &img)
Changes the option icon used to signify a toggle state in the on position.
std::uint16_t iconTextMargin() const
Returns the size of the margin between icons from menu items and the text label of the item...
void valueWidth(std::uint16_t w)
Changes the width in pixels of the value column.
std::shared_ptr< const BppImage > ConstBppImageSptr
Definition: BppImage.hpp:1778
void stringCache(const duds::ui::graphics::BppStringCacheSptr &sc)
Changes the string cache used to render menu item text.
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 pois...
duds::ui::graphics::ImageDimensions textDim
The size of a menu item&#39;s text.
const duds::ui::graphics::ImageDimensions & iconDimensions() const
Returns the dimensions used for rendering icons stored inside menu items derived from BppIconItem...
void iconTextMargin(std::uint16_t itm)
Sets the size of the margin between icons from menu items and the text label of the item...
duds::ui::graphics::ConstBppImageSptr togOffIcon
Icon used to denote a menu item in its toggled off state.
BitFlags clear()
Clear all bits.
Definition: BitFlags.hpp:245
void render(duds::ui::graphics::BppImageSptr &dest, duds::ui::menu::MenuOutput &mov)
Renders a menu to the given image.
duds::ui::graphics::ConstBppImageSptr togOnIcon
Icon used to denote a menu item in its toggled on state.
void itemMargin(std::uint16_t im)
Changes the margin in pixels placed bewteen each menu item.
Stores the dimensions of an image.
Definition: BppImage.hpp:125
const duds::ui::graphics::ConstBppImageSptr & toggledOffIcon() const
Returns the icon used to signify a toggle state in the off position.
const duds::ui::graphics::ConstBppImageSptr & selectedIcon() const
Returns the currently set icon used to indicate item selection.
void toggledOffIcon(const duds::ui::graphics::ConstBppImageSptr &img)
Changes the option icon used to signify a toggle state in the off position.
bool hasScrollBar() const
Returns true if a scroll bar is in use.
duds::ui::graphics::BppImageSptr render(const duds::ui::graphics::ImageDimensions &dim, duds::ui::menu::MenuOutputAccess &mova)
Renders a menu of the given size.
std::uint16_t scrollWidth
Thw width of the scroll bar in pixels.
BppMenuRenderer(const duds::ui::graphics::BppStringCacheSptr &cachePtr, int vmItems, Flags cfg=Flags::Zero())
Constructs a new menu renderer; best for horizontally oriented menus.
std::uint16_t valueMargin() const
Returns the margin in pixels between a menu item&#39;s label text and its value text. ...
std::shared_ptr< BppImage > BppImageSptr
Definition: BppImage.hpp:1777
void valueMargin(std::uint16_t m)
Changes the margin in pixels between a menu item&#39;s label text and its value text. ...
duds::ui::graphics::ConstBppImageSptr selIcon
Icon used to denote a selected menu item.
std::uint16_t fracshow
The number of pixels to show of a partially visible menu item.
BppMenuRenderer(Flags cfg=Flags::Zero())
Constructs a new menu renderer without a string cache or font.
Base class for errors from the BppMenuRenderer.
duds::ui::graphics::BppStringCacheSptr cache
Pre-rendered strings for menu text.
duds::ui::graphics::BppImageSptr render(const duds::ui::graphics::ImageDimensions &dim, duds::ui::menu::MenuOutput &mov)
Renders a menu of the given size.
std::unique_ptr< duds::ui::graphics::BppPositionIndicator > posInd
Optional position indicator to show user location within the menu.
const duds::ui::graphics::BppStringCacheSptr & stringCache() const
Returns the string cache currently used to render menu item text.
void disabledIcon(const duds::ui::graphics::ConstBppImageSptr &img)
Changes the optional icon used to inform the user that a menu item is currently disabled.
duds::general::BitFlags< struct BppMenuFlags > Flags
A type for configuration flags.
The destination image provided for the menu is too small to render a single menu item.
const duds::ui::graphics::ConstBppImageSptr & toggledOnIcon() const
Returns the icon used to signify a toggle state in the on position.
Flags flgs
Option flags that modify how the menu is rendered.
duds::ui::graphics::ImageDimensions itemDim
Computed dimensions of a complete menu item.
duds::ui::graphics::ConstBppImageSptr disIcon
Icon used to denote a disabled menu item.
static std::shared_ptr< BppImage > make(const ImageDimensions &id)
Convenience function to make a shared pointer to an image using the BppImage(const ImageDimensions &)...
Definition: BppImage.hpp:1018
std::uint16_t valueWidth() const
Returns the width in pixels of the value column.
Compiles a list of visible menu items based on the selected item of a MenuView.
Definition: MenuOutput.hpp:45
The destination image doesn&#39;t exist.
The menu render is configured to render text, but has no string cache.
void flags(Flags cfg)
Changes the configuration flags for this renderer.
Flags flags() const
Returns the configuration flags for this renderer.
Provides access to a MenuOutput for rendering.
ScrollBarPlacement
Values used to control which edge of the menu will host the scroll bar.
std::uint16_t maxVisible() const
Returns the maximum number of visible items to show on the menu; try to avoid calling.
std::uint16_t itemMargin() const
Returns the margin in pixels placed bewteen each menu item.