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.
This commit is contained in:
parent
c180703373
commit
64d5eb541e
6
area.go
6
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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
|
|
6
grid.go
6
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
|
||||
|
|
6
label.go
6
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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
8
stack.go
8
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).
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue