Finished proposed new sizing system.

This commit is contained in:
Pietro Gagliardi 2014-06-25 20:32:19 -04:00
parent 42fe563d1c
commit cf1da0218c
1 changed files with 82 additions and 21 deletions

103
newsizing
View File

@ -1,14 +1,25 @@
type sysSizeData struct { type sysSizeData struct {
// for size calculations
// all platforms
margin int // windows: calculated
spacing int // gtk+, cocoa: constants
// windows // windows
baseX int baseX int
baseY int baseY int
// possibly also the HDWP
// gtk, mac os x: nothing // gtk, mac os x: nothing
// for the actual resizing
// windows
// possibly also the HDWP
// gtk
shouldVAlignTop bool
// mac os x
// neighbor control alignment rect/baseline info
} }
func (s *sysData) beginResize() *sysSizeData { func (s *sysData) beginResize() *sysSizeData {
// windows: get baseX/baseY for window // windows: get baseX/baseY for window and compute margin and spacing
// gtk, mac: return nothing // gtk, mac: return zero
} }
func (s *sysData) endResize(d *sysSizeData) { func (s *sysData) endResize(d *sysSizeData) {
@ -27,35 +38,85 @@ type allocation struct {
func (s *sysData) translateAllocationCoords(allocations []*allocation, winwidth, winheight int) { func (s *sysData) translateAllocationCoords(allocations []*allocation, winwidth, winheight int) {
// windows, gtk: nothing // windows, gtk: nothing
// mac // mac
for _, allocation := range allocations { for _, a := range allocations {
// winheight - y because (0,0) is the bottom-left corner of the window and not the top-left corner // winheight - y because (0,0) is the bottom-left corner of the window and not the top-left corner
// (winheight - y) - height because (x, y) is the bottom-left corner of the control and not the top-left // (winheight - y) - height because (x, y) is the bottom-left corner of the control and not the top-left
allocation.y = (winheight - allocation.y) - allocation.height a.y = (winheight - a.y) - a.height
} }
} }
func (s *sysData) resizeWindow(width, height int) { func (s *sysData) resizeWindow(width, height int) {
d := s.startResize() d := s.beginResize()
allocations := s.resize(0, 0, width, height, d) allocations := s.allocate(0, 0, width, height, d)
s.translateAllocationCoords(allocations, width, height) s.translateAllocationCoords(allocations, width, height)
for _, c := range s.allocations { for _, c := range s.allocations {
c.this.doResize(c, d) c.this.doResize(c, d)
} }
s.finishResize(d) s.endResize(d)
} }
main widget sizing function // setSize() becomes allocate()
get preferred size of all subwidgets // each allocate on a non-layout control should just return a one-element slice
windows: uses dialog base units // each doResize and getAuxResizeInfo on a control should just defer to sysData
produce map of which controls are next to which controls type Control interface {
properly space controls // ...
windows: uses dialog base units allocate(x int, y int, width int, height int, d *sysSizeData) []*allocation
return list of size allocations back to window sizer preferredSize(d *sysSizeData) (width, height int)
doResize(c *allocation, d *sysSizeData)
getAuxResizeInfo(d *sysSizeData)
}
each doResize on a control should just defer to sysData.doResize() // vertical stack: no concept of neighbor, but not too hard to add a vertical neighbor
// horizontal stack:
var current *allocation
// ...
as := s.controls[i].allocate(...)
if current != nil {
current.neighbor = as[0].self
}
current = as[0]
// append all of as
// grid:
// same as above, except current is set to nil on each new row
// adding a vertical neighbor would require storing an extra list
each widget adjustment // windows
mac: neighboring control baselines are aligned for labels func (s *sysData) doResize(c *allocation, d *sysSizeData) {
gtk: vertical alignment of text changed to top if neighboring control is multi-line if s.ctype == c_label {
TODO - should it be center-aligned vertically or not // add additional offset of 4 dialog units
windows: none }
// resize
}
func (s *sysData) getAuxResizeInfo(d *sysSizeData) {
// do nothing
}
// gtk+
func (s *sysData) doResize(c *allocation, d *sysSizeData) {
if s.ctype == c_label && !s.alternate && c.neighbor != nil {
c.neighbor.getAuxResizeInfo(d)
if d.shouldVAlignTop {
// TODO should it be center-aligned to the first line or not
gtk_misc_set_align(s.widget, 0, 0)
} else {
gtk_misc_set_align(s.widget, 0, 0.5)
}
}
// resize
}
func (s *sysData) getAuxResizeInfo(d *sysSizeData) {
d.shouldVAlignTop = (s.ctype == c_listbox) || (s.ctype == c_area)
}
// cocoa
func (s *sysData) doResize(c *allocation, d *sysSizeData) {
if s.ctype == c_label && !s.alternate && c.neighbor != nil {
c.neighbor.getAuxResizeInfo(d)
// get this control's alignment rect and baseline
// align
}
// resize
}
func (s *sysData) getAuxResizeInfo(d *sysSizeData) {
// get this control's alignment rect and baseline
}