DUDS
Distributed Update of Data from Something
GridLayoutConfig.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 GRIDLAYOUTCONFIG_HPP
11 #define GRIDLAYOUTCONFIG_HPP
12 
15 
16 namespace duds { namespace ui { namespace graphics {
17 
18 struct GridSizeStep;
19 
23 typedef std::vector<GridSizeStep> GridSizeSteps;
24 
41  GridSizeSteps sizes;
51  static constexpr Flags PanelHidden = Flags::Bit(0);
55  static constexpr Flags PanelShown = Flags::Zero();
62  static constexpr Flags PanelWidthExpand = Flags::Bit(1);
71  static constexpr Flags PanelHeightExpand = Flags::Bit(2);
75  static constexpr Flags PanelExpand = PanelWidthExpand | PanelHeightExpand;
80  static constexpr Flags PanelJustifyLeft = Flags::Zero();
84  static constexpr Flags PanelJustifyRight = Flags::Bit(3);
89  static constexpr Flags PanelJustifyUp = Flags::Zero();
93  static constexpr Flags PanelJustifyDown = Flags::Bit(4);
97  static constexpr Flags PanelCenterHoriz = Flags::Bit(5);
101  static constexpr Flags PanelCenterVert = Flags::Bit(6);
105  static constexpr Flags PanelCenter = PanelCenterHoriz | PanelCenterVert;
110  static constexpr Flags PanelPositionHorizMask =
111  PanelJustifyRight | PanelCenterHoriz;
116  static constexpr Flags PanelPositionVertMask =
117  PanelJustifyDown | PanelCenterVert;
121  static constexpr Flags PanelPositionMask =
122  PanelPositionHorizMask | PanelPositionVertMask;
128  Flags flags = Flags::Zero();
133  GridLayoutConfig() = default;
139  GridLayoutConfig(const GridSizeSteps &gss, Flags flg) :
140  sizes(gss), flags(flg) { }
147  GridLayoutConfig(GridSizeSteps &&gss, Flags flg) :
148  sizes(std::move(gss)), flags(flg) { }
153  GridLayoutConfig(const GridSizeSteps &gss) : sizes(gss) { }
159  GridLayoutConfig(GridSizeSteps &&gss) : sizes(std::move(gss)) { }
165  GridLayoutConfig(const GridSizeStep &step);
176  void justifyLeft() {
177  flags &= ~PanelPositionHorizMask;
178  }
183  void justifyRight() {
184  flags.setMasked(PanelJustifyRight, PanelPositionHorizMask);
185  }
190  void centerHoriz() {
191  flags.setMasked(PanelCenterHoriz, PanelPositionHorizMask);
192  }
197  void justifyUp() {
198  flags &= ~PanelPositionVertMask;
199  }
204  void justifyDown() {
205  flags.setMasked(PanelJustifyDown, PanelPositionVertMask);
206  }
211  void centerVert() {
212  flags.setMasked(PanelCenterVert, PanelPositionVertMask);
213  }
218  void center() {
219  flags.setMasked(PanelCenter, PanelPositionMask);
220  }
224  void hide() {
225  flags |= PanelHidden;
226  }
230  void show() {
231  flags &= ~PanelHidden;
232  }
233 };
234 
239 struct GridLocation {
244  std::uint16_t c;
248  std::uint16_t r;
252  GridLocation() = default;
262  template <
263  typename Int0,
264  typename Int1,
265  std::enable_if_t<std::is_integral<Int0>::value, bool> = true,
266  std::enable_if_t<std::is_integral<Int1>::value, bool> = true
267  >
268  constexpr GridLocation(Int0 col, Int1 row) :
269  c((std::int16_t)col), r((std::int16_t)row) { }
273  constexpr bool operator == (const GridLocation &gl) const {
274  return (gl.r == r) && (gl.c == c);
275  }
279  constexpr bool operator != (const GridLocation &gl) const {
280  return (gl.r != r) || (gl.c != c);
281  }
282 };
283 
288 struct GridSizeStep {
312  GridSizeStep() = default;
319  constexpr GridSizeStep(
320  const ImageDimensions &id,
321  const GridLocation &gl,
322  const GridLayoutConfig::Flags flg
323  ) : minDim(id), loc(gl), flags(flg) { }
330  constexpr GridSizeStep(
331  const ImageDimensions &id,
332  const GridLocation &gl
333  ) : minDim(id), loc(gl), flags(GridLayoutConfig::Flags::Zero()) { }
338  void justifyLeft() {
340  }
345  void justifyRight() {
346  flags.setMasked(
349  );
350  }
355  void centerHoriz() {
356  flags.setMasked(
359  );
360  }
365  void justifyUp() {
367  }
372  void justifyDown() {
373  flags.setMasked(
376  );
377  }
382  void centerVert() {
383  flags.setMasked(
386  );
387  }
392  void center() {
393  flags.setMasked(
396  );
397  }
401  void hide() {
403  }
407  void show() {
409  }
410 };
411 
412 } } }
413 
414 #endif // #ifndef GRIDLAYOUTCONFIG_HPP
static constexpr Flags PanelPositionVertMask
Mask of all configuration flags affecting a panel&#39;s vertical positioning.
void justifyRight()
Sets the horizontal positioning flags to indicate the panel should be justified to the right edge...
static constexpr Flags PanelHeightExpand
Request that this panel&#39;s height be expanded past the requested minumum if there is extra space avail...
std::uint16_t r
The row position.
void centerHoriz()
Sets the horizontal positioning flags to indicate the panel should be centered.
std::vector< GridSizeStep > GridSizeSteps
A vector of size-step information for a Panel in a PriorityGridLayout.
static constexpr Flags PanelCenter
Center the panel horizontally and vertically within its grid spot.
constexpr bool operator==(const DigitalPinCap &cap, const DigitalPinCap::Flags &flg)
void hide()
Sets the flag to hide the panel.
void show()
Clear the flag to show the panel.
A single size-step used by a PriorityGridLayout to place a Panel.
static constexpr Flags PanelWidthExpand
Request that this panel&#39;s width be expanded past the requested minumum if there is extra space availa...
GridLayoutConfig::Flags flags
Configuration flags that are OR&#39;d with the flags in GridLayoutConfig to produce the final configurati...
static constexpr BitFlags Zero()
Makes a bit flags container with all flags cleared.
Definition: BitFlags.hpp:133
STL namespace.
void center()
Sets all the positioning flags to indicate the panel should be centered horizontally and vertically...
move_impl move(unsigned int c, unsigned int r)
Display stream manipulator that moves the display cursor to the given location.
void centerVert()
Sets the vertcal positioning flags to indicate the panel should be centered.
The location of a panel in a PriorityGridLayout.
void justifyDown()
Sets the vertcal positioning flags to indicate the panel should be justified to the bottom edge...
Flags flags
The configuration flags used for the panel for all of its size-steps.
static constexpr Flags PanelShown
The panel is shown.
Stores the dimensions of an image.
Definition: BppImage.hpp:125
static constexpr Flags PanelCenterVert
Center the panel vertically within its grid spot.
void justifyUp()
Sets the vertcal positioning flags to indicate the panel should be justified to the top edge...
std::uint16_t c
The column position.
void justifyUp()
Sets the vertcal positioning flags to indicate the panel should be justified to the top edge...
static constexpr BitFlags Bit(int b)
Makes a bit flags container with a single bit set that is specified by digit number rather than value...
Definition: BitFlags.hpp:141
static constexpr Flags PanelJustifyDown
Place the panel&#39;s bottom edge to the far bottom in its grid spot.
static constexpr Flags PanelJustifyLeft
Place the panel&#39;s left edge to the far left in its grid spot.
constexpr bool operator!=(const DigitalPinCap &cap, const DigitalPinCap::Flags &flg)
constexpr GridSizeStep(const ImageDimensions &id, const GridLocation &gl, const GridLayoutConfig::Flags flg)
Constructs a new GridSizeStep with the given values.
static constexpr Flags PanelHidden
The panel is not showm; this prevents it from being placed in the layout.
void justifyLeft()
Sets the horizontal positioning flags to indicate the panel should be justified to the left edge...
static constexpr Flags PanelJustifyUp
Place the panel&#39;s top edge to the far top in its grid spot.
void center()
Sets all the positioning flags to indicate the panel should be centered horizontally and vertically...
void centerHoriz()
Sets the horizontal positioning flags to indicate the panel should be centered.
void justifyDown()
Sets the vertcal positioning flags to indicate the panel should be justified to the bottom edge...
GridLayoutConfig(const GridSizeSteps &gss, Flags flg)
Constructs a new grid layout.
GridSizeSteps sizes
The size-steps for the panel.
void centerVert()
Sets the vertcal positioning flags to indicate the panel should be centered.
ImageDimensions minDim
The minimum size required for the Panel for this size-step.
GridLayoutConfig(GridSizeSteps &&gss)
Constructs a new grid layout.
GridLayoutConfig(const GridSizeSteps &gss)
Constructs a new grid layout.
constexpr GridSizeStep(const ImageDimensions &id, const GridLocation &gl)
Constructs a new GridSizeStep with the given values, and cleared (0) configuration flags...
duds::general::BitFlags< struct GridLayoutConfigFlags > Flags
The type for configuration flags that adjust how the panel is placed.
static constexpr Flags PanelJustifyRight
Place the panel&#39;s right edge to the far right in its grid spot.
GridLayoutConfig()=default
Makes a new configuration that lacks any size-steps and has the default flags.
void justifyLeft()
Sets the horizontal positioning flags to indicate the panel should be justified to the left edge...
void show()
Clear the flag to show the panel.
General graphics related code.
Definition: HD44780.hpp:15
Informs a PriorityGridLayout object where to place and how large to make Panel objects.
static constexpr Flags PanelExpand
Request both width and height expansion.
void justifyRight()
Sets the horizontal positioning flags to indicate the panel should be justified to the right edge...
static constexpr Flags PanelPositionMask
Mask of all configuration flags affecting panel position.
GridLocation loc
The location within the grid to place the Panel.
GridLayoutConfig(GridSizeSteps &&gss, Flags flg)
Constructs a new grid layout.
void hide()
Sets the flag to hide the panel.
static constexpr Flags PanelPositionHorizMask
Mask of all configuration flags affecting a panel&#39;s horizontal positioning.
constexpr GridLocation(Int0 col, Int1 row)
Construct with the given location.
static constexpr Flags PanelCenterHoriz
Center the panel horizontally within its grid spot.
BitFlags setMasked(const BitFlags &bf, const BitFlags &mask)
Changes only the bits in a masked range.
Definition: BitFlags.hpp:278