Laxkit
0.0.7.1
|
A SquishyBox containing either a horizontal or vertical list of boxes. More...
Public Member Functions | |
ListBox (unsigned int flag=0) | |
Create box as either BOX_VERTICAL or BOX_HORIZONTAL. Other flag values are ignored. | |
ListBox (unsigned int nflags, int nx, int nw, int npw, int nws, int nwg, int nhalign, int nhgap, int ny, int nh, int nph, int nhs, int nhg, int nvalign, int nvgap) | |
virtual void | Push (SquishyBox *box, char islocal=0, int where=-1) |
Push box onto list with islocal. Create list if it doesn't exist. | |
virtual int | Pop (int which=-1) |
Remove item with index which from list. | |
virtual void | Flush () |
Flush list. | |
virtual int | WrapToExtent () |
Sets this->pw,s,g/ph,s,g to be the sum of the metrics of the boxes in list. | |
virtual void | sync () |
Sync the box to the already set values of x,y,w,h. | |
virtual int | arrangeBoxes (int distributetoo=0) |
Arrange the list stack as appropriate. | |
virtual int | distributeBoxes (int setmetrics=0) |
Sets x,y,w,h of the child boxes in list, and tells them to sync(). | |
virtual int | figureDimensions (ListBox *target, int *nextrow=NULL, SquishyBox **boxes=NULL, int n=0, double *squishx=NULL, double *squishy=NULL) |
Finds pw,s,g/ph,s,g based on the boxes in list. | |
Public Member Functions inherited from Laxkit::SquishyBox | |
SquishyBox (unsigned int nflags, int nx, int nw, int npw, int nws, int nwg, int nhalign, int nhgap, int ny, int nh, int nph, int nhs, int nhg, int nvalign, int nvgap) | |
SquishyBox Constructor. | |
virtual int | hideBox (int yeshide) |
hideBox(0) makes the box visible, otherwise, make it hidden. Returns state after call. | |
virtual int | hidden () |
Return whether the box is hidden or not. | |
virtual void | sync (int xx, int yy, int ww, int hh) |
Sync the box to x,y,w,h. | |
virtual int | x () |
virtual int | w () |
virtual int | pw () |
virtual int | ws () |
virtual int | wg () |
virtual int | halign () |
virtual int | hgap () |
virtual int | y () |
virtual int | h () |
virtual int | ph () |
virtual int | hs () |
virtual int | hg () |
virtual int | valign () |
virtual int | vgap () |
virtual int | x (int val) |
virtual int | w (int val) |
virtual int | pw (int val) |
virtual int | ws (int val) |
virtual int | wg (int val) |
virtual int | halign (int val) |
virtual int | hgap (int val) |
virtual int | y (int val) |
virtual int | h (int val) |
virtual int | ph (int val) |
virtual int | hs (int val) |
virtual int | hg (int val) |
virtual int | valign (int val) |
virtual int | vgap (int val) |
virtual int | fpenalty () |
virtual int | fpenalty (int val) |
virtual int | lpenalty () |
virtual int | lpenalty (int val) |
Public Attributes | |
PtrStack< SquishyBox > | list |
Public Attributes inherited from Laxkit::SquishyBox | |
int | m [14] |
int | pad |
Pad placed around a box, which can be where a bevel or window border would go. | |
int | padinset |
Pad to inset the child boxes. | |
int | fpen |
The penalty in the flow direction. | |
int | lpen |
The penalty perpendicular to the flow direction. | |
unsigned long | flags |
A SquishyBox containing either a horizontal or vertical list of boxes.
Arrange the list stack as appropriate.
Any derived classes must make this function configure list to be something appropriate, meaning list should contain the boxes that make a horizontal (or vertical) list. This function is typically called from sync(), which itself is normally called from a resize event.
The default ListBox is just a plain list, and therefore is inherently already arranged properly, and nothing is done to list.
Often, it is much more efficient to assign actual x,y,w,h values to boxes at the same time that the list stack is organized, so you may optionally assign those values when distributetoo is nonzero, which calls distributeBoxes(0).
Reimplemented in Laxkit::RowColBox.
References distributeBoxes().
Referenced by sync().
Sets x,y,w,h of the child boxes in list, and tells them to sync().
The default for SquishyBox is to layout ALL the boxes in list, based on the definite, and already set x,y,w,h of *this. It lays out ALL the boxes in list, whether they squish nicely or not.
If setmetrics!=0 then this->pw,s,g/ph,s,g are set to the pw,s,g/ph,s,g found from the child boxes (via figureDimensions(this,...,&squishx,&squishy)). This would be done to wrap this box around the extents of its children, for instance. Otherwise, leave this->pw,s,g/ph,s,g alone, and the metrics derived from the child boxes are computed but not stored (figureDimensions(NULL,...,&squishx,&squishy)). They are just used to determine the squish values.
This function assumes that the children already have their pw,s,g/ph,s,g (but not the x,y,w,h) set at desired values. First the squish factor is computed based on the preferred numbers, then the children's x,y,w,h are set, then each child's sync() is called.
If BOX_DONT_PROPAGATE_POS is not set, then this->x,y is added onto the newly found box->x,y. This means that when laying out massive complicated arrangements in a single window, say, then each box would have coordinates of the overall window, not just relative to its immediate parent box. This is important because the actual boxes the user uses might be contained in intermediary boxes, but this would mean window boxes offset their children incorrectly, since they use their own upper left corner as the origin, rather than a parent's origin. Thus, SquishyBoxes that are also windows should have BOX_DONT_PROPAGATE_POS set.
If there is a NULL in list, then the distributing stops at that NULL.
Returns 0 success, 1 error.
Reimplemented in Laxkit::RowColBox.
References Laxkit::PtrStack< T >::e, figureDimensions(), Laxkit::SquishyBox::hidden(), Laxkit::PtrStack< T >::n, Laxkit::SquishyBox::pad, Laxkit::SquishyBox::padinset, and Laxkit::SquishyBox::sync().
Referenced by arrangeBoxes().
|
virtual |
Finds pw,s,g/ph,s,g based on the boxes in list.
To wrap *this to the metrics found from the boxes, call with target=this. Note that this only overwrites pw,s,g/ph,s,g. It does NOT change actual w,h, UNLESS target->w or h is equal to BOX_SHOULD_WRAP or flags&BOX_WRAP_TO_X_EXTENT (or Y_EXTENT), in which case they are set to the computed preferred w and/or h.
If squish(x or y) is not NULL, then it is set to the value that would convert the newly found pw,s,g/ph,s,g to the actual w,h. Of course, this needs w,h to already be set to desired values. If they are not wrapped as above, then the calling code must have set these values. Please note that the newly found pw,s,g/ph,s,g do not necessarily have anything to do with those of this, or those previously held in target->m. They refer only to the sums of elements of boxes.
The squish values computed are what is multiplied to boxes' metrics so that the list fits to the actual target->w,h.
If target is NULL, the pw,s,g/ph,s,g are not stored anywhere, and this->flags are used. In that case, this function might still be useful just to get the squish values, which get based on fitting into this->w,h.
If target is not NULL, then target->flags are used, and the pw,s,g/ph,s,g are put into target, and the squish values are used to fit to target->w,h.
If boxes is not null, then use that for the list of boxes assumed to have n boxes. Otherwise, use target->list.e/n, or if target is NULL, use this->list.e/n. Interprets boxes as a either a vertical or horizontal list, according to whether BOX_VERTICAL is in flags or not.
If nextrow is NULL, this uses ALL the boxes in list. It does not stop where a line is filled. If nextrow is not NULL, then it does stop when a line is full, which requires that the target->w or h is set to a desired value already, and nextrow is set to what would be the starting box of the next line.
If an element of boxes is NULL, then the figuring stops right there, and nextrow is set to point to the first non-NULL box after that NULL, or n if there aren't any.
*** this must eventually be modified to use all the LRTB, LRBT, ...
****** implement pad and penalty!!
References Laxkit::PtrStack< T >::e, Laxkit::SquishyBox::hidden(), ListBox(), Laxkit::PtrStack< T >::n, Laxkit::SquishyBox::pad, and Laxkit::SquishyBox::padinset.
Referenced by Laxkit::RowColBox::arrangeBoxes(), distributeBoxes(), and WrapToExtent().
Remove item with index which from list.
Default is to pop the top of the stack.
Returns 1 for item removed, or 0 for which out of bounds.
Reimplemented in Laxkit::RowColBox.
References Laxkit::PtrStack< T >::remove().
|
virtual |
Push box onto list with islocal. Create list if it doesn't exist.
If box==NULL, then this is later on interpreted as a line break.
If islocal==0 then ListBox will not delete the box when Pop() is called. If islocal==1, then do call delete on the box when popped.
where is the index to push onto the list stack.
Reimplemented in Laxkit::RowColBox.
References Laxkit::PtrStack< T >::push().
Referenced by Laxkit::StackFrame::AddWin(), and Laxkit::RowColBox::arrangeBoxes().
|
virtual |
Sync the box to the already set values of x,y,w,h.
This is meant to be called only when a definite x,y,w,h have already been assigned for this box, such as by its parent box, and *this must set the x,y,w,h of the child boxes, then tell all child boxes to sync their child boxes, etc.
All this default function does is call arrangeBoxes(1). The 1 tells arrangeBoxes() that the contained boxes should be distributed too.
Normally, derived classes need only redefine arrangeBoxes() and/or distributeBoxes(), and not sync().
It goes:
sync(0,0,w,h) //typically after a window resize event -> sync() -> arrangeboxes(1) -> distributeBoxes(0)
Reimplemented from Laxkit::SquishyBox.
Reimplemented in Laxkit::BoxSelector.
References arrangeBoxes().
Referenced by Laxkit::RowFrame::Sync(), and Laxkit::StackFrame::WrapToExtent().
|
virtual |
Sets this->pw,s,g/ph,s,g to be the sum of the metrics of the boxes in list.
Note that it does NOT set this->x,y,w,h.
Simply calls figureDimensions(this).
Returns 0 success, nonzero error.
Reimplemented from Laxkit::SquishyBox.
Reimplemented in Laxkit::StackFrame.
References figureDimensions().