Skip to content

Commit

Permalink
Changed window resizes so that the actual Control.setRect() functions…
Browse files Browse the repository at this point in the history
… appended to an array of requests that the resize() function set all at once instead of having each done individually. This will be necessary for what I think will be a solution to the deadlocks. It doesn't work right now; I'm assuming it's allocating too much memory. I know how to fix this, but I'm committing what I have so far to be safe.
  • Loading branch information
andlabs committed Mar 18, 2014
1 parent c078266 commit 1922708
Show file tree
Hide file tree
Showing 15 changed files with 98 additions and 39 deletions.
10 changes: 8 additions & 2 deletions area.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,14 @@ func (a *Area) make(window *sysData) error {
return nil
}

func (a *Area) setRect(x int, y int, width int, height int, winheight int) error {
return a.sysData.setRect(x, y, width, height, winheight)
func (a *Area) setRect(x int, y int, width int, height int) []resizerequest {
return []resizerequest{resizerequest{
sysData: a.sysData,
x: x,
y: y,
width: width,
height: height,
}}
}

func (a *Area) preferredSize() (width int, height int) {
Expand Down
10 changes: 8 additions & 2 deletions button.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,14 @@ func (b *Button) make(window *sysData) error {
return nil
}

func (b *Button) setRect(x int, y int, width int, height int, winheight int) error {
return b.sysData.setRect(x, y, width, height, winheight)
func (b *Button) setRect(x int, y int, width int, height int) []resizerequest {
return []resizerequest{resizerequest{
sysData: b.sysData,
x: x,
y: y,
width: width,
height: height,
}}
}

func (b *Button) preferredSize() (width int, height int) {
Expand Down
9 changes: 6 additions & 3 deletions callbacks_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ 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
err := s.resize(0, 0, width, height, 0)
if err != nil {
panic("child resize failed: " + err.Error())
resizeList := s.resize(0, 0, width, height)
for _, s := range resizeList {
err := s.sysData.setRect(s.x, s.y, s.width, s.height, 0)
if err != nil {
panic("child resize failed: " + err.Error())
}
}
}
// 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
Expand Down
10 changes: 8 additions & 2 deletions checkbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,14 @@ func (c *Checkbox) make(window *sysData) error {
return nil
}

func (c *Checkbox) setRect(x int, y int, width int, height int, winheight int) error {
return c.sysData.setRect(x, y, width, height, winheight)
func (c *Checkbox) setRect(x int, y int, width int, height int) []resizerequest {
return []resizerequest{resizerequest{
sysData: c.sysData,
x: x,
y: y,
width: width,
height: height,
}}
}

func (c *Checkbox) preferredSize() (width int, height int) {
Expand Down
10 changes: 8 additions & 2 deletions combobox.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,14 @@ func (c *Combobox) make(window *sysData) (err error) {
return nil
}

func (c *Combobox) setRect(x int, y int, width int, height int, winheight int) error {
return c.sysData.setRect(x, y, width, height, winheight)
func (c *Combobox) setRect(x int, y int, width int, height int) []resizerequest {
return []resizerequest{resizerequest{
sysData: c.sysData,
x: x,
y: y,
width: width,
height: height,
}}
}

func (c *Combobox) preferredSize() (width int, height int) {
Expand Down
2 changes: 1 addition & 1 deletion control.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, winheight int) error
setRect(x int, y int, width int, height int) []resizerequest
preferredSize() (width int, height int)
}
9 changes: 6 additions & 3 deletions delegate_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,12 @@ 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
err := sysData.resize(int(r.x), int(r.y), int(r.width), int(r.height), int(r.height))
if err != nil {
panic("child resize failed: " + err.Error())
resizeList := sysData.resize(int(r.x), int(r.y), int(r.width), int(r.height))
for _, s := range resizeList {
err := s.sysData.setRect(s.x, s.y, s.width, s.height, int(r.height))
if err != nil {
panic("child resize failed: " + err.Error())
}
}
}
C.objc_msgSend_noargs(win, _display) // redraw everything; TODO only if resize() was called?
Expand Down
9 changes: 3 additions & 6 deletions grid.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, winheight int) error {
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
Expand Down Expand Up @@ -171,16 +171,13 @@ func (g *Grid) setRect(x int, y int, width int, height int, winheight int) error
w = g.colwidths[col]
h = g.rowheights[row]
}
err := c.setRect(x, y, w, h, winheight)
if err != nil {
return fmt.Errorf("error setting size of control (%d,%d) in Grid.setRect(): %v", row, col, err)
}
rr = append(rr, c.setRect(x, y, w, h)...)
x += g.colwidths[col]
}
x = startx
y += g.rowheights[row]
}
return nil
return rr
}

// filling and stretchy are ignored for preferred size calculation
Expand Down
10 changes: 8 additions & 2 deletions label.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,14 @@ func (l *Label) make(window *sysData) error {
return nil
}

func (l *Label) setRect(x int, y int, width int, height int, winheight int) error {
return l.sysData.setRect(x, y, width, height, winheight)
func (l *Label) setRect(x int, y int, width int, height int) []resizerequest {
return []resizerequest{resizerequest{
sysData: l.sysData,
x: x,
y: y,
width: width,
height: height,
}}
}

func (l *Label) preferredSize() (width int, height int) {
Expand Down
10 changes: 8 additions & 2 deletions lineedit.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,14 @@ func (l *LineEdit) make(window *sysData) error {
return nil
}

func (l *LineEdit) setRect(x int, y int, width int, height int, winheight int) error {
return l.sysData.setRect(x, y, width, height, winheight)
func (l *LineEdit) setRect(x int, y int, width int, height int) []resizerequest {
return []resizerequest{resizerequest{
sysData: l.sysData,
x: x,
y: y,
width: width,
height: height,
}}
}

func (l *LineEdit) preferredSize() (width int, height int) {
Expand Down
10 changes: 8 additions & 2 deletions listbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,14 @@ func (l *Listbox) make(window *sysData) (err error) {
return nil
}

func (l *Listbox) setRect(x int, y int, width int, height int, winheight int) error {
return l.sysData.setRect(x, y, width, height, winheight)
func (l *Listbox) setRect(x int, y int, width int, height int) []resizerequest {
return []resizerequest{resizerequest{
sysData: l.sysData,
x: x,
y: y,
width: width,
height: height,
}}
}

func (l *Listbox) preferredSize() (width int, height int) {
Expand Down
10 changes: 8 additions & 2 deletions progressbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,14 @@ func (p *ProgressBar) make(window *sysData) error {
return nil
}

func (p *ProgressBar) setRect(x int, y int, width int, height int, winheight int) error {
return p.sysData.setRect(x, y, width, height, winheight)
func (p *ProgressBar) setRect(x int, y int, width int, height int) []resizerequest {
return []resizerequest{resizerequest{
sysData: p.sysData,
x: x,
y: y,
width: width,
height: height,
}}
}

func (p *ProgressBar) preferredSize() (width int, height int) {
Expand Down
9 changes: 3 additions & 6 deletions stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (s *Stack) make(window *sysData) error {
return nil
}

func (s *Stack) setRect(x int, y int, width int, height int, winheight int) error {
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
Expand Down Expand Up @@ -120,17 +120,14 @@ func (s *Stack) setRect(x int, y int, width int, height int, winheight int) erro
}
// 3) now actually place controls
for i, c := range s.controls {
err := c.setRect(x, y, s.width[i], s.height[i], winheight)
if err != nil {
return fmt.Errorf("error setting size of control %d in Stack.setRect(): %v", i, err)
}
rr = append(rr, c.setRect(x, y, s.width[i], s.height[i])...)
if s.orientation == horizontal {
x += s.width[i]
} else {
y += s.height[i]
}
}
return nil
return rr
}

// 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).
Expand Down
9 changes: 6 additions & 3 deletions stdwndclass_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ 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
err = s.resize(int(r.Left), int(r.Top), int(r.Right), int(r.Bottom), 0)
if err != nil {
panic("child resize failed: " + err.Error())
resizeList := s.resize(int(r.Left), int(r.Top), int(r.Right), int(r.Bottom))
for _, s := range resizeList {
err = s.sysData.setRect(s.x, s.y, s.width, s.height, 0)
if err != nil {
panic("child resize failed: " + err.Error())
}
}
}
return 0
Expand Down
10 changes: 9 additions & 1 deletion sysdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func newEvent() chan struct{} {
type cSysData struct {
ctype int
event chan struct{}
resize func(x int, y int, width int, height int, winheight int) error
resize func(x int, y int, width int, height int) []resizerequest
alternate bool // editable for Combobox, multi-select for listbox, password for lineedit
handler AreaHandler // for Areas
}
Expand Down Expand Up @@ -109,3 +109,11 @@ func mksysdata(ctype int) *sysData {
},
}
}

type resizerequest struct {
sysData *sysData
x int
y int
width int
height int
}

0 comments on commit 1922708

Please sign in to comment.