DUDS
Distributed Update of Data from Something
PriorityGridLayout.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 PRIORITYGRIDLAYOUT_HPP
11 #define PRIORITYGRIDLAYOUT_HPP
12 
15 
16 namespace duds { namespace ui { namespace graphics {
17 
70  struct PanelStatus {
91  int sizeStep;
96  bool hidden;
101  const GridSizeStep &currentStep() const {
102  return config.sizes[sizeStep];
103  }
111  return config.flags | config.sizes[sizeStep].flags;
112  }
113  PanelStatus() = default;
114  PanelStatus(const PanelSptr &pspt, const GridLayoutConfig &conf);
115  PanelStatus(const PanelSptr &pspt, GridLayoutConfig &&conf);
116  };
120  typedef std::map<unsigned int, PanelStatus> GridConfig;
125  GridConfig configs;
130  struct RowData {
135  typedef std::pair<unsigned int, PanelStatus*> KeyPanel;
140  std::vector<KeyPanel> panels;
148  int widthExpand = 0;
152  bool heightExpand = false;
162  bool minCols(int mc) noexcept;
165  KeyPanel &operator [] (int c);
166  };
170  typedef std::vector<RowData> RowVec;
174  std::vector<std::int16_t> rowMaxHeight;
179  ImageLocation offset = { 0, 0 };
192  static bool minRows(RowVec &rv, int ms);
199  static unsigned int panelAt(RowVec &rv, const GridLocation &gl) noexcept;
200 public:
206  void renderOffset(const ImageLocation &off) {
207  offset = off;
208  }
213  const ImageLocation &renderOffset() const {
214  return offset;
215  }
222  fill = dim;
223  }
227  const ImageDimensions &renderFill() const {
228  return fill;
229  }
241  void maxRowHeight(int row, std::int16_t height);
247  std::int16_t maxRowHeight(int row) const;
263  bool add(
264  const PanelSptr &panel,
265  const GridLayoutConfig &config,
266  unsigned int pri
267  );
285  bool add(
286  const PanelSptr &panel,
287  const GridSizeStep &config,
288  unsigned int pri
289  );
300  unsigned int add(const PanelSptr &panel, const GridLayoutConfig &config);
313  unsigned int add(const PanelSptr &panel, const GridSizeStep &config);
326  void addOrReplace(
327  const PanelSptr &panel,
328  const GridLayoutConfig &config,
329  unsigned int pri
330  );
345  void addOrReplace(
346  const PanelSptr &panel,
347  const GridSizeStep &config,
348  unsigned int pri
349  );
358  void remove(unsigned int pri);
370  void remove(const PanelSptr &panel);
384  GridLayoutConfig &panelConfig(unsigned int pri);
390  const GridLayoutConfig &panelConfig(unsigned int pri) const;
397  int layout();
417  void render(BppImage *dest);
421  void render(BppImage &dest) {
422  render(&dest);
423  }
427  void render(const BppImageSptr &dest) {
428  render(dest.get());
429  }
435  ImageDimensions layoutDimensions(unsigned int pri) const;
441  ImageLocation layoutLocation(unsigned int pri) const;
451  bool layoutPosition(
454  unsigned int pri
455  ) const;
456 };
457 
458 } } }
459 
460 #endif // #ifndef PRIORITYGRIDLAYOUT_HPP
Stores a location within an image.
Definition: BppImage.hpp:33
std::vector< KeyPanel > panels
The panels in column order, left to right.
Internal data structure used to store a Panel, its configuration, and current layout status...
std::map< unsigned int, PanelStatus > GridConfig
The type that maps panel priorities to panel data.
void render(BppImage &dest)
Renders all visible panels to the provided image.
GridLayoutConfig & panelConfig(unsigned int pri)
Returns the layout configuration for the specified panel.
ImageLocation loc
The location on the target image as determined by layout().
void maxRowHeight(int row, std::int16_t height)
Sets the maximum height of a row.
A single size-step used by a PriorityGridLayout to place a Panel.
GridLayoutConfig::Flags flags() const
Returns the configuration flags to use for rendering.
bool hidden
True to indicate that the panel will not be rendered.
const ImageLocation & renderOffset() const
Returns the upper left corner of the destination image that will receive the panel images rendered th...
void renderOffset(const ImageLocation &off)
Change the upper left corner of the destination image that will receive the panel images rendered thr...
int sizeStep
The index of the size-step to use for rendering the panel as selected by layout().
A way to place Panel objects dynamically with a priority mechanism to allow panels to be resized and ...
The location of a panel in a PriorityGridLayout.
static unsigned int panelAt(RowVec &rv, const GridLocation &gl) noexcept
Returns the priority key for the panel at the given location, or zero if there is no panel...
Flags flags
The configuration flags used for the panel for all of its size-steps.
Stores the dimensions of an image.
Definition: BppImage.hpp:125
ImageLocation layoutLocation(unsigned int pri) const
Returns the location assigned to the panel at priority pri by layout(), or { 0, 0 }...
ImageLocation offset
The upper right location of the destination image where the topmost row and leftmost column will be p...
std::vector< RowData > RowVec
Type used inside layout() to store data on all the rows.
std::shared_ptr< BppImage > BppImageSptr
Definition: BppImage.hpp:1777
std::pair< unsigned int, PanelStatus * > KeyPanel
Stores a panel priority key and a pointer to the associated PanelStatus object inside configs...
bool add(const PanelSptr &panel, const GridLayoutConfig &config, unsigned int pri)
Adds a panel in an unused priority spot, or fail to add if the spot is already used.
void render(const BppImageSptr &dest)
Renders all visible panels to the provided image.
GridLayoutConfig config
The panel&#39;s layout configuration.
GridSizeSteps sizes
The size-steps for the panel.
const ImageDimensions & renderFill() const
Returns the area filled by the layout.
GridConfig configs
The mapping of Panel objects by priority key.
static bool minRows(RowVec &rv, int ms)
Ensures a minimum number of rows in rv, and returns true if at least that many rows already existed...
bool layoutPosition(ImageDimensions &dim, ImageLocation &loc, unsigned int pri) const
Provides the dimensions and location assigned to the panel at priority pri by layout() ...
void render(BppImage *dest)
Renders all visible panels to the provided image.
void renderFill(const ImageDimensions &dim)
Changes the area filled by the layout.
ImageDimensions layoutDimensions(unsigned int pri) const
Returns the dimensions assigned to the panel at priority pri by layout(), or { 0, 0 }...
General graphics related code.
Definition: HD44780.hpp:15
ImageDimensions dim
The maximum dimensions allocated to the panel by layout().
Informs a PriorityGridLayout object where to place and how large to make Panel objects.
int layout()
Places all panels into general positions.
std::vector< std::int16_t > rowMaxHeight
Maximum heights for rows.
std::shared_ptr< Panel > PanelSptr
A shared pointer to a Panel.
Definition: Panel.hpp:107
void addOrReplace(const PanelSptr &panel, const GridLayoutConfig &config, unsigned int pri)
Adds a panel or replaces an existing panel at the given priority spot.
Internal data structure used by layout() to store information on each row that is only needed to plac...
const GridSizeStep & currentStep() const
Returns the size-step selected by layout().
An image that uses a single bit to represent the state of each pixel; a black or white picture...
Definition: BppImage.hpp:321
ImageDimensions fill
The area to fill in the destination image.