2014-07-16 20:30:19 -05:00
// 25 june 2014
package ui
type allocation struct {
x int
y int
width int
height int
this Control
neighbor Control
}
type sizingbase struct {
xmargin int
ymargin int
xpadding int
ypadding int
}
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-07-25 19:47:08 -05:00
// on Windows, this is only embedded by window, as all other containers cannot have their own children; beginResize() points to an instance method literal (TODO get correct term) from window
// on GTK+ and Mac OS X, one is embedded by window and all containers; beginResize() points to a global function (TODO NOT GOOD; ideally the sizing data should be passed across size-allocate requests)
2014-07-25 18:28:34 -05:00
type container struct {
2014-07-26 13:11:03 -05:00
child Control
2014-07-25 18:28:34 -05:00
}
2014-07-28 13:00:01 -05:00
// set to true to apply spacing to all windows
var spaced bool = false
2014-07-25 18:28:34 -05:00
func ( c * container ) resize ( width , height int ) {
if c . child == nil { // no children; nothing to do
return
}
2014-07-28 13:00:01 -05:00
d := c . beginResize ( )
2014-07-27 09:42:59 -05:00
allocations := c . child . allocate ( 0 + d . xmargin , 0 + d . ymargin , width - ( 2 * d . xmargin ) , height - ( 2 * d . ymargin ) , 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 )
}
}