summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-03-17 21:09:03 -0400
committerPietro Gagliardi <[email protected]>2014-03-17 21:09:03 -0400
commit64d5eb541eb28e1a7e81adca66a72155d16033b4 (patch)
tree7db7c7ee787afc02823833340c3a2d0068807117
parentc1807033733654db480e782acebdccda9eababc6 (diff)
Changed the new resizing code so that it uses the same allocated slice per window instead of making a new one to store all the resize requests each time.
-rw-r--r--area.go6
-rw-r--r--button.go6
-rw-r--r--callbacks_unix.go5
-rw-r--r--checkbox.go6
-rw-r--r--combobox.go6
-rw-r--r--control.go2
-rw-r--r--delegate_darwin.go5
-rw-r--r--grid.go6
-rw-r--r--label.go6
-rw-r--r--lineedit.go6
-rw-r--r--listbox.go6
-rw-r--r--progressbar.go6
-rw-r--r--stack.go8
-rw-r--r--stdwndclass_windows.go5
-rw-r--r--sysdata.go9
15 files changed, 48 insertions, 40 deletions
diff --git a/area.go b/area.go
index b63bfe3..f7aecdd 100644
--- a/area.go
+++ b/area.go
@@ -121,14 +121,14 @@ func (a *Area) make(window *sysData) error {
return nil
}
-func (a *Area) setRect(x int, y int, width int, height int) []resizerequest {
- return []resizerequest{resizerequest{
+func (a *Area) setRect(x int, y int, width int, height int, rr *[]resizerequest) {
+ *rr = append(*rr, resizerequest{
sysData: a.sysData,
x: x,
y: y,
width: width,
height: height,
- }}
+ })
}
func (a *Area) preferredSize() (width int, height int) {
diff --git a/button.go b/button.go
index b5e02a6..380fdd1 100644
--- a/button.go
+++ b/button.go
@@ -61,14 +61,14 @@ func (b *Button) make(window *sysData) error {
return nil
}
-func (b *Button) setRect(x int, y int, width int, height int) []resizerequest {
- return []resizerequest{resizerequest{
+func (b *Button) setRect(x int, y int, width int, height int, rr *[]resizerequest) {
+ *rr = append(*rr, resizerequest{
sysData: b.sysData,
x: x,
y: y,
width: width,
height: height,
- }}
+ })
}
func (b *Button) preferredSize() (width int, height int) {
diff --git a/callbacks_unix.go b/callbacks_unix.go
index 68fb0ef..1efe723 100644
--- a/callbacks_unix.go
+++ b/callbacks_unix.go
@@ -42,8 +42,9 @@ 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
- resizeList := s.resize(0, 0, width, height)
- for _, s := range resizeList {
+ 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())
diff --git a/checkbox.go b/checkbox.go
index 2ca81cd..c5f0217 100644
--- a/checkbox.go
+++ b/checkbox.go
@@ -68,14 +68,14 @@ func (c *Checkbox) make(window *sysData) error {
return nil
}
-func (c *Checkbox) setRect(x int, y int, width int, height int) []resizerequest {
- return []resizerequest{resizerequest{
+func (c *Checkbox) setRect(x int, y int, width int, height int, rr *[]resizerequest) {
+ *rr = append(*rr, resizerequest{
sysData: c.sysData,
x: x,
y: y,
width: width,
height: height,
- }}
+ })
}
func (c *Checkbox) preferredSize() (width int, height int) {
diff --git a/combobox.go b/combobox.go
index ae2edfd..2b50a72 100644
--- a/combobox.go
+++ b/combobox.go
@@ -143,14 +143,14 @@ func (c *Combobox) make(window *sysData) (err error) {
return nil
}
-func (c *Combobox) setRect(x int, y int, width int, height int) []resizerequest {
- return []resizerequest{resizerequest{
+func (c *Combobox) setRect(x int, y int, width int, height int, rr *[]resizerequest) {
+ *rr = append(*rr, resizerequest{
sysData: c.sysData,
x: x,
y: y,
width: width,
height: height,
- }}
+ })
}
func (c *Combobox) preferredSize() (width int, height int) {
diff --git a/control.go b/control.go
index 2a44b02..f035ebb 100644
--- a/control.go
+++ b/control.go
@@ -9,6 +9,6 @@ import (
// A Control represents an UI control. Note that Control contains unexported members; this has the consequence that you can't build custom controls that interface directly with the system-specific code (fo rinstance, to import an unsupported control), or at least not without some hackery. If you want to make your own controls, embed Area and provide its necessities.
type Control interface {
make(window *sysData) error
- setRect(x int, y int, width int, height int) []resizerequest
+ setRect(x int, y int, width int, height int, rr *[]resizerequest)
preferredSize() (width int, height int)
}
diff --git a/delegate_darwin.go b/delegate_darwin.go
index 5999941..a1c835d 100644
--- a/delegate_darwin.go
+++ b/delegate_darwin.go
@@ -90,8 +90,9 @@ func appDelegate_windowDidResize(self C.id, sel C.SEL, notification C.id) {
r := C.objc_msgSend_stret_rect_noargs(wincv, _frame)
if sysData.resize != nil {
// winheight is used here because (0,0) is the bottom-left corner, not the top-left corner
- resizeList := sysData.resize(int(r.x), int(r.y), int(r.width), int(r.height))
- for _, s := range resizeList {
+ 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, int(r.height))
if err != nil {
panic("child resize failed: " + err.Error())
diff --git a/grid.go b/grid.go
index 064dcab..c38ecf4 100644
--- a/grid.go
+++ b/grid.go
@@ -120,7 +120,7 @@ func (g *Grid) make(window *sysData) error {
return nil
}
-func (g *Grid) setRect(x int, y int, width int, height int) (rr []resizerequest) {
+func (g *Grid) setRect(x int, y int, width int, height int, rr *[]resizerequest) {
max := func(a int, b int) int {
if a > b {
return a
@@ -171,13 +171,13 @@ func (g *Grid) setRect(x int, y int, width int, height int) (rr []resizerequest)
w = g.colwidths[col]
h = g.rowheights[row]
}
- rr = append(rr, c.setRect(x, y, w, h)...)
+ c.setRect(x, y, w, h, rr)
x += g.colwidths[col]
}
x = startx
y += g.rowheights[row]
}
- return rr
+ return
}
// filling and stretchy are ignored for preferred size calculation
diff --git a/label.go b/label.go
index 36bdb3f..6d6fc9d 100644
--- a/label.go
+++ b/label.go
@@ -55,14 +55,14 @@ func (l *Label) make(window *sysData) error {
return nil
}
-func (l *Label) setRect(x int, y int, width int, height int) []resizerequest {
- return []resizerequest{resizerequest{
+func (l *Label) setRect(x int, y int, width int, height int, rr *[]resizerequest) {
+ *rr = append(*rr, resizerequest{
sysData: l.sysData,
x: x,
y: y,
width: width,
height: height,
- }}
+ })
}
func (l *Label) preferredSize() (width int, height int) {
diff --git a/lineedit.go b/lineedit.go
index 71f4529..4ad6889 100644
--- a/lineedit.go
+++ b/lineedit.go
@@ -67,14 +67,14 @@ func (l *LineEdit) make(window *sysData) error {
return nil
}
-func (l *LineEdit) setRect(x int, y int, width int, height int) []resizerequest {
- return []resizerequest{resizerequest{
+func (l *LineEdit) setRect(x int, y int, width int, height int, rr *[]resizerequest) {
+ *rr = append(*rr, resizerequest{
sysData: l.sysData,
x: x,
y: y,
width: width,
height: height,
- }}
+ })
}
func (l *LineEdit) preferredSize() (width int, height int) {
diff --git a/listbox.go b/listbox.go
index fae3582..764bfad 100644
--- a/listbox.go
+++ b/listbox.go
@@ -144,14 +144,14 @@ func (l *Listbox) make(window *sysData) (err error) {
return nil
}
-func (l *Listbox) setRect(x int, y int, width int, height int) []resizerequest {
- return []resizerequest{resizerequest{
+func (l *Listbox) setRect(x int, y int, width int, height int, rr *[]resizerequest) {
+ *rr = append(*rr, resizerequest{
sysData: l.sysData,
x: x,
y: y,
width: width,
height: height,
- }}
+ })
}
func (l *Listbox) preferredSize() (width int, height int) {
diff --git a/progressbar.go b/progressbar.go
index bbc7f1b..80debdc 100644
--- a/progressbar.go
+++ b/progressbar.go
@@ -55,14 +55,14 @@ func (p *ProgressBar) make(window *sysData) error {
return nil
}
-func (p *ProgressBar) setRect(x int, y int, width int, height int) []resizerequest {
- return []resizerequest{resizerequest{
+func (p *ProgressBar) setRect(x int, y int, width int, height int, rr *[]resizerequest) {
+ *rr = append(*rr, resizerequest{
sysData: p.sysData,
x: x,
y: y,
width: width,
height: height,
- }}
+ })
}
func (p *ProgressBar) preferredSize() (width int, height int) {
diff --git a/stack.go b/stack.go
index 2820ef7..86ae551 100644
--- a/stack.go
+++ b/stack.go
@@ -77,11 +77,11 @@ func (s *Stack) make(window *sysData) error {
return nil
}
-func (s *Stack) setRect(x int, y int, width int, height int) (rr []resizerequest) {
+func (s *Stack) setRect(x int, y int, width int, height int, rr *[]resizerequest) {
var stretchywid, stretchyht int
if len(s.controls) == 0 { // do nothing if there's nothing to do
- return nil
+ return
}
// 1) get height and width of non-stretchy controls; figure out how much space is alloted to stretchy controls
stretchywid = width
@@ -120,14 +120,14 @@ func (s *Stack) setRect(x int, y int, width int, height int) (rr []resizerequest
}
// 3) now actually place controls
for i, c := range s.controls {
- rr = append(rr, c.setRect(x, y, s.width[i], s.height[i])...)
+ c.setRect(x, y, s.width[i], s.height[i], rr)
if s.orientation == horizontal {
x += s.width[i]
} else {
y += s.height[i]
}
}
- return rr
+ return
}
// The preferred size of a Stack is the sum of the preferred sizes of non-stretchy controls + (the number of stretchy controls * the largest preferred size among all stretchy controls).
diff --git a/stdwndclass_windows.go b/stdwndclass_windows.go
index 54cec7d..ea443de 100644
--- a/stdwndclass_windows.go
+++ b/stdwndclass_windows.go
@@ -53,8 +53,9 @@ 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
- resizeList := s.resize(int(r.Left), int(r.Top), int(r.Right), int(r.Bottom))
- for _, s := range resizeList {
+ 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())
diff --git a/sysdata.go b/sysdata.go
index cdf6a14..c010ab6 100644
--- a/sysdata.go
+++ b/sysdata.go
@@ -17,7 +17,8 @@ func newEvent() chan struct{} {
type cSysData struct {
ctype int
event chan struct{}
- resize func(x int, y int, width int, height int) []resizerequest
+ resize func(x int, y int, width int, height int, rr *[]resizerequest)
+ resizes []resizerequest
alternate bool // editable for Combobox, multi-select for listbox, password for lineedit
handler AreaHandler // for Areas
}
@@ -103,11 +104,15 @@ const (
)
func mksysdata(ctype int) *sysData {
- return &sysData{
+ s := &sysData{
cSysData: cSysData{
ctype: ctype,
},
}
+ if ctype == c_window { // make resizes non-nil so it can be passed in
+ s.resizes = make([]resizerequest, 0, 0)
+ }
+ return s
}
type resizerequest struct {