Laxkit  0.0.7.1
Public Member Functions | Public Attributes
Laxkit::SquishyBox Class Reference

A box with x,y,w,h, prefered w/h, and allowable shrink and expand values for w/h. More...

Inheritance diagram for Laxkit::SquishyBox:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 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 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 (int xx, int yy, int ww, int hh)
 Sync the box to x,y,w,h.
virtual void sync ()
 Sync the box to the already set values of 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

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

Detailed Description

A box with x,y,w,h, prefered w/h, and allowable shrink and expand values for w/h.

Usually, you will set the preferred width, shrink, grow, align, and gap, and the box sync() process will automatically compute the x,y, and actual width and height.

Say a box's preferred width is 5, and it has a shrink of 3 and a grow of 4, then the squish zone, or the acceptable actual width, of the box is somewhere in the range [2,9] (from 2 to 9 inclusive).

Also keeps track of preferred per-box vertical and horizontal alignment within any extra space that results when the box must fit in a space that is outside its squish zone. This is particularly meant for aligning in extra space in a table cell, or when laying out rows valign is used, when laying out columns, halign is used. The typical values for v/halign range 0 to 100. 100 means top align, 0 means bottom, 50 centers, everything else does the proportional thing. A super-duper feature that is not implemented would be to have aligning to a baseline.

The base SquishyBox only has metric information. ListBox is a box, with a list of internal boxes. This list can be either a horizontal or vertical list (flags has BOX_HORIZONTAL (the default) or BOX_VERTICAL), with descriptive options held in flags. More complicated arrangements are made with other derived classes, notably RowColBox and TableBox.

This is a moderately adaptible structure to hold info to lay out windows and icons nicely. It is simplification of the box-glue-penalty format of TeX. Penalties are restricted to nothing special (==0), force line break (<0), and never line break (>0). The glue and box are also roughly combined into this class, such that one would always have box(w1)-(no break)-glue(w2,s,g), and the glue's width, shrink and grow are always used. In TeX, the glue acts like the space between words, but here, the boxes all kind of but up against each other. So anyway.

The horizontal and vertical metric information is stored in the m array, with the horizontal values first (x,w,pw,ws,wg,halign,hgap), followed by the vertical values (y,h,ph,hs,hg,valign,vgap). The penalty is stored in fpen (penalty in the flow direction) and lpen (penalty in the line direction).

To sum up:

  m, holds horizontal and vertical metric information
  pad  = analogous to a window border: space around the box. say pad==5, and the box's x,y,w,h are
         (0,0,10,20), then the box+pad fills a rectangle (x,y,w,h)=(-5,-5,20,30)
  padinset = space within the box to inset child boxes
  fpen = penalty in the flow direction: 0=nothing, <0 force break, >0 never break
  lpen = would be penalty in direction of the next line
 

The following all go in SquishyBox::flags:

// For laying out, for instance LRTB == Left to Right, Top to Bottom
// Note that only LRTB and TBLR are implemented in ArrangeRowCol().
// These correspond to LAX_LRTB, etc. note that they take up
// only the leftmost 3 bits of flags.
#define BOX_LRTB (0)
#define BOX_LRBT (1)
#define BOX_RLTB (2)
#define BOX_RLBT (3)
#define BOX_TBLR (4)
#define BOX_TBRL (5)
#define BOX_BTLR (6)
#define BOX_BTRL (7)
#define BOX_FLOW_MASK (0x7)
#define BOX_HORIZONTAL (1<<3)
#define BOX_VERTICAL (1<<4)
***what are these:
#define BOX_WRAP_TO_X_EXTENT (1<<5)
#define BOX_WRAP_TO_Y_EXTENT (1<<6)
#define BOX_WRAP_TO_EXTENT (3<<5)
// if laying out x, make y,h value sync with target->h
#define BOX_SET_Y_TOO (1<<7)
// if laying out y, make x,w value sync with target->w
#define BOX_SET_X_TOO (1<<8)
#define BOX_SET_METRICS (1<<7|1<<8)
// |11223344| <-- with any of the left/center/right/justify, always acts as justify
#define BOX_STRETCH_TO_FILL_X (1<<9)
#define BOX_STRETCH_TO_FILL_Y (1<<10)
#define BOX_STRETCH_MASK (1<<9|1<<10)
// Space with left/right/center/justify
// |1 2 3 4 |
// | 1 2 3 4 |
// | 1 2 3 4|
// |1 2 3 4|
#define BOX_SPACE_TO_FILL_X (1<<11)
#define BOX_SPACE_TO_FILL_Y (1<<12)
#define BOX_SPACE_JUSTIFY (1<<13)
#define BOX_SPACE_MASK (1<<11|1<<12|1<<13)
// overall alignment of the laid out boxes
// |1 2 3 4 |
// | 1 2 3 4 |
// | 1 2 3 4|
#define BOX_ALIGN_MASK (63<<14)
#define BOX_HALIGN_SHIFT 14
#define BOX_HALIGN_MASK (7<<14)
#define BOX_LEFT (1<<14)
#define BOX_HCENTER (1<<15)
#define BOX_RIGHT (1<<16)
#define BOX_VALIGN_SHIFT 17
#define BOX_VALIGN_MASK (7<<17)
#define BOX_TOP (1<<17)
#define BOX_VCENTER (1<<18)
#define BOX_BOTTOM (1<<19)
#define BOX_CENTER (1<<15|1<<18)
#define BOX_STRETCH_IN_ROW (1<<20)
#define BOX_STRETCH_IN_COL (1<<21)
// Windows (rather than boxes) set positions according to their own origin,
// so don't add on the x and y positions.
#define BOX_DONT_PROPAGATE_POS (1<<22)
//whether to use this box in calculations or not
#define BOX_HIDDEN (1<<23)

Constructor & Destructor Documentation

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.

Parameters:
nflagsSee above for BOX_* flags
nxNew x position
nwNew width
npwNew preferred width
nwsNew horizontal shrink
nwgNew horizontal grow
nhalignNew horizontal align, 0=bottom/right, 100=top/left, 50=center, etc.
nhgapNew horizontal gap, ignored at edges
nyNew y position
nhNew height
nphNew preferred height
nhsNew vertical shrink
nhgNew vertical grow
nvalignNew vertical align, 0=bottom/right, 100=top/left, 50=center, etc.
nvgapNew vertical gap, ignored at edges

Member Function Documentation

int Laxkit::SquishyBox::hideBox ( int  yeshide)
virtual

hideBox(0) makes the box visible, otherwise, make it hidden. Returns state after call.

Todo:
must sync or tag needs to sync if necessary...
void Laxkit::SquishyBox::sync ( int  xx,
int  yy,
int  ww,
int  hh 
)
virtual

Sync the box to x,y,w,h.

Currently, this always simply assigns x,y,w,h straight away, then calls sync(). This is just a shortcut to set the x,y,w,h. The end result must always be that it then calls sync().

When a window derived from a SquishyBox is resized, it would then call sync(0,0,win_w,win_h).

Referenced by Laxkit::ListBox::distributeBoxes(), and Laxkit::StackFrame::Sync().

void Laxkit::SquishyBox::sync ( )
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 SquishyBox, such as by its parent box, and *this must rearrange its contents according to the new dimensions.

Default here is to do nothing, since a plain SquishyBox has no contents.

Reimplemented in Laxkit::ListBox, Laxkit::BoxSelector, and Laxkit::WinFrameBox.

int Laxkit::SquishyBox::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.

Default here is simply to return 0, since plain SquishyBox has no contents. Returns 0 success, nonzero error.

Reimplemented in Laxkit::ListBox, and Laxkit::StackFrame.


Member Data Documentation

int Laxkit::SquishyBox::fpen

The penalty in the flow direction.

Currently: 0 = nothing special.
>0 = never break a line after this box
<0 = always break a line after this box

Though in the future, this may change to be a truer response to penalties. You can use BOX_NO_BREAK (currently==1000000) and BOX_MUST_BREAK (currently==-1000000) to be safer against such future changes.

Todo:
***implement me!!
int Laxkit::SquishyBox::lpen

The penalty perpendicular to the flow direction.

This value is currently ignored in the Laxkit.

int Laxkit::SquishyBox::pad
int Laxkit::SquishyBox::padinset

Pad to inset the child boxes.

If a box is 100 wide, and padinset=5, then the boxes are put in a space 90 wide.

Referenced by Laxkit::BoxSelector::BoxSelector(), Laxkit::ListBox::distributeBoxes(), Laxkit::ListBox::figureDimensions(), Laxkit::MessageBox::MessageBox(), Laxkit::RowColBox::newSubBox(), and Laxkit::RowFrame::RowFrame().


The documentation for this class was generated from the following files:

Mon Feb 17 2014 11:52:59, Laxkit