summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-04-07 14:32:25 -0400
committerPietro Gagliardi <[email protected]>2014-04-07 14:32:25 -0400
commit3bf215ae4edb616c14c4525638cf54425d6e8f36 (patch)
tree3c253a36643b8ab6891545c217d9af906efc3358
parent00acf74177e520c2f961fb478e7674d24c9077c9 (diff)
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.
-rw-r--r--callbacks_unix.go9
-rw-r--r--delegate_darwin.go13
-rw-r--r--stdwndclass_windows.go9
-rw-r--r--sysdata.go13
4 files changed, 17 insertions, 27 deletions
diff --git a/callbacks_unix.go b/callbacks_unix.go
index e34db4c..fde05ce 100644
--- a/callbacks_unix.go
+++ b/callbacks_unix.go
@@ -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
diff --git a/delegate_darwin.go b/delegate_darwin.go
index 53eb361..4c40d39 100644
--- a/delegate_darwin.go
+++ b/delegate_darwin.go
@@ -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?
}
diff --git a/stdwndclass_windows.go b/stdwndclass_windows.go
index 5ce356b..e3368ca 100644
--- a/stdwndclass_windows.go
+++ b/stdwndclass_windows.go
@@ -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:
diff --git a/sysdata.go b/sysdata.go
index 7f43a3e..1507912 100644
--- a/sysdata.go
+++ b/sysdata.go
@@ -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())
+ }
+ }
+ }
+}