Adjusted sizing data to act as the base container type; this is needed for proper resizing on both GTK+ and Mac OS X.
This commit is contained in:
parent
4680e35300
commit
010c97d686
|
@ -33,16 +33,31 @@ type controlSizing interface {
|
|||
getAuxResizeInfo(*sizing)
|
||||
}
|
||||
|
||||
func (w *window) doresize(width, height int) {
|
||||
if w.child == nil { // no children; nothing to do
|
||||
// on Windows, this is only embedded by window, as all other containers cannot have their own children
|
||||
// on GTK+ and Mac OS X, one is embedded by window and all containers; the containers call container.continueResize()
|
||||
type container struct {
|
||||
child Control
|
||||
spaced bool
|
||||
beginResize func() (d *sizing)
|
||||
}
|
||||
|
||||
func (c *container) resize(width, height int) {
|
||||
if c.child == nil { // no children; nothing to do
|
||||
return
|
||||
}
|
||||
d := w.beginResize()
|
||||
allocations := w.child.allocate(0, 0, width, height, d)
|
||||
w.translateAllocationCoords(allocations, width, height)
|
||||
d := c.beginResize()
|
||||
c.continueResize(width, height, d)
|
||||
}
|
||||
|
||||
func (c *container) continueResize(width, height int, d *sizing) {
|
||||
if c.child == nil { // no children; nothing to do
|
||||
return
|
||||
}
|
||||
allocations := c.child.allocate(0, 0, width, height, d)
|
||||
c.translateAllocationCoords(allocations, width, height)
|
||||
// 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)
|
||||
}
|
||||
w.endResize(d)
|
||||
c.endResize(d)
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ const (
|
|||
paddingDialogUnits = 4
|
||||
)
|
||||
|
||||
// only windows are containers, so only windows get beginResize()
|
||||
func (w *window) beginResize() (d *sizing) {
|
||||
d = new(sizing)
|
||||
|
||||
|
@ -43,11 +44,11 @@ func (w *window) beginResize() (d *sizing) {
|
|||
return d
|
||||
}
|
||||
|
||||
func (w *window) endResize(d *sizing) {
|
||||
func (c *container) endResize(d *sizing) {
|
||||
// redraw
|
||||
}
|
||||
|
||||
func (w *window) translateAllocationCoords(allocations []*allocation, winwidth, winheight int) {
|
||||
func (c *container) translateAllocationCoords(allocations []*allocation, winwidth, winheight int) {
|
||||
// no translation needed on windows
|
||||
}
|
||||
|
||||
|
|
|
@ -12,14 +12,12 @@ import (
|
|||
import "C"
|
||||
|
||||
type window struct {
|
||||
*container
|
||||
|
||||
hwnd C.HWND
|
||||
shownbefore bool
|
||||
|
||||
child Control
|
||||
|
||||
closing *event
|
||||
|
||||
spaced bool
|
||||
}
|
||||
|
||||
const windowclassname = ""
|
||||
|
@ -42,8 +40,10 @@ type controlParent interface {
|
|||
func newWindow(title string, width int, height int, control Control) *window {
|
||||
w := &window{
|
||||
// hwnd set in WM_CREATE handler
|
||||
closing: newEvent(),
|
||||
closing: newEvent(),
|
||||
container: new(container),
|
||||
}
|
||||
w.container.beginResize = w.beginResize
|
||||
hwnd := C.newWindow(toUTF16(title), C.int(width), C.int(height), unsafe.Pointer(w))
|
||||
if hwnd != w.hwnd {
|
||||
panic(fmt.Errorf("inconsistency: hwnd returned by CreateWindowEx() (%p) and hwnd stored in window (%p) differ", hwnd, w.hwnd))
|
||||
|
@ -97,7 +97,7 @@ func storeWindowHWND(data unsafe.Pointer, hwnd C.HWND) {
|
|||
//export windowResize
|
||||
func windowResize(data unsafe.Pointer, r *C.RECT) {
|
||||
w := (*window)(data)
|
||||
w.doresize(int(r.right - r.left), int(r.bottom - r.top))
|
||||
w.resize(int(r.right - r.left), int(r.bottom - r.top))
|
||||
}
|
||||
|
||||
//export windowClosing
|
||||
|
|
Loading…
Reference in New Issue