Split out the common resizing code into its own function so that it's all in one place. This will also affect what happens if I switch to DeferWindowPos() on Windows.

This commit is contained in:
Pietro Gagliardi 2014-04-07 14:32:25 -04:00
parent 00acf74177
commit 3bf215ae4e
4 changed files with 17 additions and 27 deletions

View File

@ -41,14 +41,7 @@ func our_window_configure_event_callback(widget *C.GtkWidget, event *C.GdkEvent,
if s.container != nil && s.resize != nil { // wait for init
width, height := gtk_window_get_size(s.widget)
// top-left is (0,0) so no need for winheight
s.resizes = s.resizes[0:0] // set len to 0 without changing cap
s.resize(0, 0, width, height, &s.resizes)
for _, s := range s.resizes {
err := s.sysData.setRect(s.x, s.y, s.width, s.height, 0)
if err != nil {
panic("child resize failed: " + err.Error())
}
}
s.doResize(0, 0, width, height, 0)
}
// returning false indicates that we continue processing events related to configure-event; if we choose not to, then after some controls have been added, the layout fails completely and everything stays in the starting position/size
// TODO make sure this is the case

View File

@ -78,17 +78,8 @@ func appDelegate_windowDidResize(self C.id, sel C.SEL, notification C.id) {
s := getSysData(win)
wincv := C.objc_msgSend_noargs(win, _contentView) // we want the content view's size, not the window's; selector defined in sysdata_darwin.go
r := C.objc_msgSend_stret_rect_noargs(wincv, _frame)
if s.resize != nil {
// winheight is used here because (0,0) is the bottom-left corner, not the top-left corner
s.resizes = s.resizes[0:0] // set len to 0 without changing cap
s.resize(0, 0, int(r.width), int(r.height), &s.resizes)
for _, s := range s.resizes {
err := s.sysData.setRect(s.x, s.y, s.width, s.height, int(r.height))
if err != nil {
panic("child resize failed: " + err.Error())
}
}
}
// winheight is used here because (0,0) is the bottom-left corner, not the top-left corner
s.doResize(0, 0, int(r.width), int(r.height), int(r.height))
C.objc_msgSend_noargs(win, _display) // redraw everything; TODO only if resize() was called?
}

View File

@ -53,15 +53,8 @@ func stdWndProc(s *sysData) func(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam
panic("GetClientRect failed: " + err.Error())
}
// top-left corner is (0,0) so no need for winheight
s.resizes = s.resizes[0:0] // set len to 0 without changing cap
s.resize(int(r.Left), int(r.Top), int(r.Right), int(r.Bottom), &s.resizes)
s.doResize(int(r.Left), int(r.Top), int(r.Right), int(r.Bottom), 0)
// TODO use the Defer movement functions here?
for _, s := range s.resizes {
err = s.sysData.setRect(s.x, s.y, s.width, s.height, 0)
if err != nil {
panic("child resize failed: " + err.Error())
}
}
}
return 0
case _WM_CLOSE:

View File

@ -87,3 +87,16 @@ type resizerequest struct {
width int
height int
}
func (s *sysData) doResize(x int, y int, width int, height int, winheight int) {
if s.resize != nil {
s.resizes = s.resizes[0:0] // set len to 0 without changing cap
s.resize(x, y, width, height, &s.resizes)
for _, s := range s.resizes {
err := s.sysData.setRect(s.x, s.y, s.width, s.height, winheight)
if err != nil {
panic("child resize failed: " + err.Error())
}
}
}
}