17 if (panels.size() <= mc) {
18 panels.resize(mc + 1, std::pair<unsigned int, PanelStatus*>(0,
nullptr));
30 if (rv.size() <= ms) {
39 if (
minRows(rv, gl.r + 1) && rv[gl.r].minCols(gl.c + 1)) {
40 return rv[gl.r].panels[gl.c].first;
49 ) : panel(pspt), config(conf), hidden(true) { }
78 std::pair<GridConfig::iterator, bool> res =
82 panel->added(
this, pri);
100 std::pair<GridConfig::iterator, bool> res =
104 panel->added(
this, pri);
122 GridConfig::const_reverse_iterator last =
configs.crbegin();
123 pri = last->first + 1;
137 GridConfig::const_reverse_iterator last =
configs.crbegin();
138 pri = last->first + 1;
154 panel->added(
this, pri);
171 panel->added(
this, pri);
179 GridConfig::iterator iter =
configs.find(pri);
181 iter->second.panel->removing(
this, pri);
187 GridConfig::iterator iter = std::find_if(
191 return i.second.panel ==
panel;
195 iter->second.panel->removing(
this, iter->first);
201 GridConfig::iterator iter =
configs.find(pri);
205 return iter->second.config;
209 GridConfig::const_iterator iter =
configs.find(pri);
213 return iter->second.config;
224 int heightExpand = 0;
228 pstat.second.sizeStep = 0;
230 pstat.second.hidden = (pstat.second.sizeStep < 0) ||
231 pstat.second.config.sizes.empty() ||
234 if (pstat.second.hidden) {
242 for (; pstat.second.sizeStep < pstat.second.config.sizes.size();
243 ++pstat.second.sizeStep
246 if (pstat.second.config.sizes[pstat.second.sizeStep].flags &
252 gl = pstat.second.currentStep().loc;
257 if (row != &(rdat[gl.
r])) {
262 maxarea.
h = std::min(
268 if (maxarea.
fits(pstat.second.config.sizes[pstat.second.sizeStep].minDim)) {
277 assert(maxarea.
fits(pstat.second.config.sizes[pstat.second.sizeStep].minDim));
278 assert(gl == pstat.second.config.sizes[pstat.second.sizeStep].loc);
284 pstat.second.config.sizes[pstat.second.sizeStep].minDim;
286 row->
used.
w += pstat.second.dim.w;
288 row->
used.
h = std::max(row->
used.
h, pstat.second.dim.h);
306 pstat.second.hidden =
true;
312 addnlH = (
fill.
h - total.
h) / heightExpand;
313 extraH = (
fill.
h - total.
h) % heightExpand;
314 assert((total.
h + addnlH + extraH) ==
fill.
h);
318 for (
int idx = 0; idx < rdat.size(); ++idx) {
321 int eh = addnlH + row.
used.
h;
329 total.
h += mh - row.
used.
h;
340 addnlH = (
fill.
h - total.
h) / heightExpand;
341 extraH = (
fill.
h - total.
h) % heightExpand;
342 assert((total.
h + addnlH + extraH) ==
fill.
h);
349 for (
int idx = 0; idx < rdat.size(); ++idx) {
352 assert(heightExpand);
353 row.
used.
h += addnlH;
360 if (row.
used.
h > mh) {
362 if (--heightExpand) {
363 addnlH += (row.
used.
h - mh) / heightExpand;
368 int additonal = 0, extra = 0;
378 for (
int col = 0; col < row.
panels.size(); ++col) {
380 assert((kp.first && kp.second) || (!kp.first && !kp.second));
384 assert(!kp.second->hidden);
386 kp.second->dim.h = row.
used.
h;
392 kp.second->dim.w += additonal;
394 if (extra && (kp.first < row.
panels[pref].first)) {
402 row.
panels[pref].second->dim.w += extra;
407 for (
auto &row : rdat) {
409 for (
auto &col : row.panels) {
412 col.second->loc.x = total.
w;
413 col.second->loc.y = total.
h;
414 total.
w += col.second->dim.w;
417 assert(total.
w == row.used.w);
418 assert(total.
w <=
fill.
w);
419 total.
h += row.used.h;
421 assert(total.
h <=
fill.
h);
440 if (!pstat.second.hidden) {
446 img = pstat.second.panel->render(
450 pstat.second.sizeStep
452 }
catch (boost::exception &be) {
460 dim.
w + margin.
l + margin.
r,
461 dim.
h + margin.
t + margin.
b 464 if (!pstat.second.dim.fits(dimIncMar)) {
481 if (pstat.second.dim.w != dimIncMar.
w) {
483 loc.
x += pstat.second.dim.w - dimIncMar.
w;
485 loc.
x += (pstat.second.dim.w - dimIncMar.
w) / 2;
489 if (pstat.second.dim.h != dimIncMar.
h) {
491 loc.
y += pstat.second.dim.h - dimIncMar.
h;
493 loc.
y += (pstat.second.dim.h - dimIncMar.
h) / 2;
497 dest->
write(img, loc, off, dim);
504 GridConfig::const_iterator iter =
configs.find(pri);
508 return iter->second.dim;
512 GridConfig::const_iterator iter =
configs.find(pri);
516 return iter->second.loc;
524 GridConfig::const_iterator iter =
configs.find(pri);
528 dim = iter->second.dim;
529 loc = iter->second.loc;
const ImageDimensions & dimensions() const
Returns the dimensions of the image.
static constexpr Flags PanelHeightExpand
Request that this panel's height be expanded past the requested minumum if there is extra space avail...
Stores a location within an image.
std::vector< KeyPanel > panels
The panels in column order, left to right.
std::uint16_t r
The row position.
std::int16_t y
Vertical coordinate.
std::uint16_t l
Left margin size.
std::int16_t x
Horizontal coordinate.
std::uint16_t r
Right margin size.
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.
static constexpr Flags PanelWidthExpand
Request that this panel's width be expanded past the requested minumum if there is extra space availa...
GridLayoutConfig::Flags flags() const
Returns the configuration flags to use for rendering.
bool hidden
True to indicate that the panel will not be rendered.
PanelSptr panel
The Panel object.
std::uint16_t b
Bottom margin size.
move_impl move(unsigned int c, unsigned int r)
Display stream manipulator that moves the display cursor to the given location.
KeyPanel & operator[](int c)
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...
int widthExpand
Number of panels requesting width expansion.
Stores the dimensions of an image.
static constexpr Flags PanelCenterVert
Center the panel vertically within its grid spot.
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::uint16_t c
The column position.
std::vector< RowData > RowVec
Type used inside layout() to store data on all the rows.
std::uint16_t t
Top margin size.
An attempt was made to add a panel using an invalid priority value.
boost::error_info< struct Info_ImageDimensions, ImageDimensions > ImageErrorSourceDimensions
Image dimensions for a source image relevant to the error.
static constexpr Flags PanelJustifyDown
Place the panel's bottom edge to the far bottom in its grid spot.
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 write(const BppImage *const src, const ImageLocation &destLoc, const ImageLocation &srcLoc, const ImageDimensions &srcSize, Direction srcDir=HorizInc, Operation op=OpSet)
Writes the specified portion of the source into this image.
static constexpr Flags PanelHidden
The panel is not showm; this prevents it from being placed in the layout.
GridLayoutConfig config
The panel's layout configuration.
A problem with image bounds, such as the use of a location beyond the image's dimensions.
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.
static constexpr Flags PanelJustifyRight
Place the panel's right edge to the far right in its grid spot.
constexpr BitsType flags() const
Returns the value stored in the object.
ImageDimensions layoutDimensions(unsigned int pri) const
Returns the dimensions assigned to the panel at priority pri by layout(), or { 0, 0 }...
void remove(unsigned int pri)
Removes the panel in the given priority spot.
General graphics related code.
constexpr bool withinBounds(const ImageLocation &loc) const
Returns true if the given location is within the bounds specified by this object. ...
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.
boost::error_info< struct Info_ImageLocation, ImageLocation > ImageErrorLocation
An image location relevant to the error.
int layout()
Places all panels into general positions.
boost::error_info< struct Info_PanelSizeStep, int > PanelSizeStep
Identifies a Panel's selected size-step in errors.
std::vector< std::int16_t > rowMaxHeight
Maximum heights for rows.
std::shared_ptr< Panel > PanelSptr
A shared pointer to a Panel.
boost::error_info< struct Info_PanelPriority, int > PanelPriority
Identifies a Panel object's layout priority in errors.
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...
Defines the size of a margin bordering a panel; the size of the margin is included in computations fo...
#define DUDS_THROW_EXCEPTION(x)
Works like BOOST_THROW_EXCEPTION, but includes a stack trace if DUDS_ERRORS_VERBOSE is defined...
An image that uses a single bit to represent the state of each pixel; a black or white picture...
A panel identified by priority key could not be found.
boost::error_info< struct Info_FrameDimensions, ImageDimensions > ImageErrorTargetDimensions
Image dimensions for a target image relevant to the error.
constexpr bool fits(const ImageDimensions &id) const
Returns true if the given dimensions are not larger than this object's dimensions.
bool minCols(int mc) noexcept
Ensures the minimum number of allocated columns includes the given index.
bool heightExpand
True when a panel requests height expansion.
ImageDimensions used
Minimum used area of the panels.
static constexpr Flags PanelCenterHoriz
Center the panel horizontally within its grid spot.
ImageDimensions fill
The area to fill in the destination image.