2014-07-16 20:30:19 -05:00
// 25 june 2014
package ui
type allocation struct {
2014-10-02 09:05:53 -05:00
x int
y int
width int
height int
this Control
neighbor Control
2014-07-16 20:30:19 -05:00
}
type sizingbase struct {
2014-10-02 09:05:53 -05:00
xmargin int
ymargintop int
ymarginbottom int
xpadding int
ypadding int
2014-07-16 20:30:19 -05:00
}
type controlSizing interface {
allocate ( x int , y int , width int , height int , d * sizing ) [ ] * allocation
preferredSize ( * sizing ) ( int , int )
commitResize ( * allocation , * sizing )
getAuxResizeInfo ( * sizing )
}
2014-08-04 16:46:08 -05:00
// A container hosts a Control and resizes that Control based on changes in size to the parent Window.
2014-08-15 20:44:35 -05:00
// container is used by Window, Tab, and Group to contain and control their respective Controls.
2014-08-04 16:46:08 -05:00
// Tab and Group use containers for their content; as such, their commitResize() functions should only change the size of the Tab and Group themselves, and have their containers do the real work.
// All containers must embed containerbase.
type containerbase struct {
2014-10-02 09:05:53 -05:00
child Control
2014-07-25 18:28:34 -05:00
}
2014-10-12 10:54:58 -05:00
// set to true to apply spacing to all windows
var spaced bool = false
2014-08-04 16:46:08 -05:00
func ( c * container ) resize ( x , y , width , height int ) {
2014-10-02 09:05:53 -05:00
if c . child == nil { // no children; nothing to do
2014-07-25 18:28:34 -05:00
return
}
2014-07-28 13:00:01 -05:00
d := c . beginResize ( )
2014-10-02 09:05:53 -05:00
allocations := c . child . allocate ( x + d . xmargin , y + d . ymargintop ,
width - ( 2 * d . xmargin ) , height - d . ymargintop - d . ymarginbottom , d )
2014-07-25 18:28:34 -05:00
c . translateAllocationCoords ( allocations , width , height )
2014-07-16 20:30:19 -05:00
// move in reverse so as to approximate right->left order so neighbors make sense
for i := len ( allocations ) - 1 ; i >= 0 ; i -- {
allocations [ i ] . this . commitResize ( allocations [ i ] , d )
}
}