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)
|
getAuxResizeInfo(*sizing)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) doresize(width, height int) {
|
// on Windows, this is only embedded by window, as all other containers cannot have their own children
|
||||||
if w.child == nil { // no children; nothing to do
|
// 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
|
return
|
||||||
}
|
}
|
||||||
d := w.beginResize()
|
d := c.beginResize()
|
||||||
allocations := w.child.allocate(0, 0, width, height, d)
|
c.continueResize(width, height, d)
|
||||||
w.translateAllocationCoords(allocations, width, height)
|
}
|
||||||
|
|
||||||
|
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
|
// move in reverse so as to approximate right->left order so neighbors make sense
|
||||||
for i := len(allocations) - 1; i >= 0; i-- {
|
for i := len(allocations) - 1; i >= 0; i-- {
|
||||||
allocations[i].this.commitResize(allocations[i], d)
|
allocations[i].this.commitResize(allocations[i], d)
|
||||||
}
|
}
|
||||||
w.endResize(d)
|
c.endResize(d)
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ const (
|
||||||
paddingDialogUnits = 4
|
paddingDialogUnits = 4
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// only windows are containers, so only windows get beginResize()
|
||||||
func (w *window) beginResize() (d *sizing) {
|
func (w *window) beginResize() (d *sizing) {
|
||||||
d = new(sizing)
|
d = new(sizing)
|
||||||
|
|
||||||
|
@ -43,11 +44,11 @@ func (w *window) beginResize() (d *sizing) {
|
||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) endResize(d *sizing) {
|
func (c *container) endResize(d *sizing) {
|
||||||
// redraw
|
// redraw
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) translateAllocationCoords(allocations []*allocation, winwidth, winheight int) {
|
func (c *container) translateAllocationCoords(allocations []*allocation, winwidth, winheight int) {
|
||||||
// no translation needed on windows
|
// no translation needed on windows
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,14 +12,12 @@ import (
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
type window struct {
|
type window struct {
|
||||||
|
*container
|
||||||
|
|
||||||
hwnd C.HWND
|
hwnd C.HWND
|
||||||
shownbefore bool
|
shownbefore bool
|
||||||
|
|
||||||
child Control
|
|
||||||
|
|
||||||
closing *event
|
closing *event
|
||||||
|
|
||||||
spaced bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const windowclassname = ""
|
const windowclassname = ""
|
||||||
|
@ -42,8 +40,10 @@ type controlParent interface {
|
||||||
func newWindow(title string, width int, height int, control Control) *window {
|
func newWindow(title string, width int, height int, control Control) *window {
|
||||||
w := &window{
|
w := &window{
|
||||||
// hwnd set in WM_CREATE handler
|
// 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))
|
hwnd := C.newWindow(toUTF16(title), C.int(width), C.int(height), unsafe.Pointer(w))
|
||||||
if hwnd != w.hwnd {
|
if hwnd != w.hwnd {
|
||||||
panic(fmt.Errorf("inconsistency: hwnd returned by CreateWindowEx() (%p) and hwnd stored in window (%p) differ", 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
|
//export windowResize
|
||||||
func windowResize(data unsafe.Pointer, r *C.RECT) {
|
func windowResize(data unsafe.Pointer, r *C.RECT) {
|
||||||
w := (*window)(data)
|
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
|
//export windowClosing
|
||||||
|
|
Loading…
Reference in New Issue