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-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-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-08-04 16:46:08 -05:00
func ( c * container ) resize ( x , y , width , height int ) {
2014-07-25 18:28:34 -05:00
if c . child == nil { // no children; nothing to do
return
}
2014-07-28 13:00:01 -05:00
d := c . beginResize ( )
2014-07-28 14:02:27 -05:00
allocations := c . child . allocate ( x + d . xmargin , y + 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 )
}
}