Made the new sizing system work on Windows.
This commit is contained in:
parent
9a3e73b460
commit
1eeadc000a
4
area.go
4
area.go
|
@ -350,8 +350,8 @@ func (a *Area) preferredSize(d *sysSizeData) (width int, height int) {
|
|||
return a.sysData.preferredSize(d)
|
||||
}
|
||||
|
||||
func (a *Area) commitResize(a *allocation, d *sysSizeData) {
|
||||
a.sysData.preferredSize(a, d)
|
||||
func (a *Area) commitResize(c *allocation, d *sysSizeData) {
|
||||
a.sysData.commitResize(c, d)
|
||||
}
|
||||
|
||||
func (a *Area) getAuxResizeInfo(d *sysSizeData) {
|
||||
|
|
|
@ -80,7 +80,7 @@ func (b *Button) preferredSize(d *sysSizeData) (width int, height int) {
|
|||
}
|
||||
|
||||
func (b *Button) commitResize(a *allocation, d *sysSizeData) {
|
||||
b.sysData.preferredSize(a, d)
|
||||
b.sysData.commitResize(a, d)
|
||||
}
|
||||
|
||||
func (b *Button) getAuxResizeInfo(d *sysSizeData) {
|
||||
|
|
|
@ -85,7 +85,7 @@ func (c *Checkbox) preferredSize(d *sysSizeData) (width int, height int) {
|
|||
}
|
||||
|
||||
func (c *Checkbox) commitResize(a *allocation, d *sysSizeData) {
|
||||
c.sysData.preferredSize(a, d)
|
||||
c.sysData.commitResize(a, d)
|
||||
}
|
||||
|
||||
func (c *Checkbox) getAuxResizeInfo(d *sysSizeData) {
|
||||
|
|
|
@ -162,7 +162,7 @@ func (c *Combobox) preferredSize(d *sysSizeData) (width int, height int) {
|
|||
}
|
||||
|
||||
func (c *Combobox) commitResize(a *allocation, d *sysSizeData) {
|
||||
c.sysData.preferredSize(a, d)
|
||||
c.sysData.commitResize(a, d)
|
||||
}
|
||||
|
||||
func (c *Combobox) getAuxResizeInfo(d *sysSizeData) {
|
||||
|
|
|
@ -19,7 +19,7 @@ type cSysSizeData struct {
|
|||
}
|
||||
|
||||
// for verification; see sysdata.go
|
||||
type sysDataSizeFuncs interface {
|
||||
type sysDataSizingFunctions interface {
|
||||
beginResize() *sysSizeData
|
||||
endResize(*sysSizeData)
|
||||
translateAllocationCoords([]*allocation, int, int)
|
||||
|
@ -32,7 +32,7 @@ func (s *sysData) resizeWindow(width, height int) {
|
|||
d := s.beginResize()
|
||||
allocations := s.allocate(0, 0, width, height, d)
|
||||
s.translateAllocationCoords(allocations, width, height)
|
||||
for _, c := range s.allocations {
|
||||
for _, c := range allocations {
|
||||
c.this.commitResize(c, d)
|
||||
}
|
||||
s.endResize(d)
|
||||
|
|
|
@ -21,15 +21,17 @@ type sysSizeData struct {
|
|||
const (
|
||||
marginDialogUnits = 7
|
||||
paddingDialogUnits = 4
|
||||
}
|
||||
)
|
||||
|
||||
func (s *sysData) beginResize() (d *sysSizeData) {
|
||||
d = new(sysSizeData)
|
||||
|
||||
dc := getTextDC(s.hwnd)
|
||||
defer releaseTextDC(dc)
|
||||
defer releaseTextDC(s.hwnd, dc)
|
||||
|
||||
r1, _, err = _getTextMetrics.Call(
|
||||
var tm _TEXTMETRICS
|
||||
|
||||
r1, _, err := _getTextMetrics.Call(
|
||||
uintptr(dc),
|
||||
uintptr(unsafe.Pointer(&tm)))
|
||||
if r1 == 0 { // failure
|
||||
|
@ -66,7 +68,7 @@ func (s *sysData) commitResize(c *allocation, d *sysSizeData) {
|
|||
}
|
||||
c.y += yoff
|
||||
// TODO move this here
|
||||
s.setRect(c.x, c.y, c.width, c.height)
|
||||
s.setRect(c.x, c.y, c.width, c.height, 0)
|
||||
}
|
||||
|
||||
func (s *sysData) getAuxResizeInfo(d *sysSizeData) {
|
||||
|
@ -150,8 +152,6 @@ var (
|
|||
)
|
||||
|
||||
func getTextDC(hwnd _HWND) (dc _HANDLE) {
|
||||
var tm _TEXTMETRICS
|
||||
|
||||
r1, _, err := _getDC.Call(uintptr(hwnd))
|
||||
if r1 == 0 { // failure
|
||||
panic(fmt.Errorf("error getting DC for preferred size calculations: %v", err))
|
||||
|
@ -167,7 +167,7 @@ func getTextDC(hwnd _HWND) (dc _HANDLE) {
|
|||
}
|
||||
|
||||
func releaseTextDC(hwnd _HWND, dc _HANDLE) {
|
||||
r1, _, err = _releaseDC.Call(
|
||||
r1, _, err := _releaseDC.Call(
|
||||
uintptr(hwnd),
|
||||
uintptr(dc))
|
||||
if r1 == 0 { // failure
|
||||
|
@ -179,7 +179,7 @@ func releaseTextDC(hwnd _HWND, dc _HANDLE) {
|
|||
func (s *sysData) preferredSize(d *sysSizeData) (width int, height int) {
|
||||
// the preferred size of an Area is its size
|
||||
if stdDlgSizes[s.ctype].area {
|
||||
return s.areawidth, s.areaheight, 0 // no yoff for areas
|
||||
return s.areawidth, s.areaheight
|
||||
}
|
||||
|
||||
if msg := stdDlgSizes[s.ctype].getsize; msg != 0 {
|
||||
|
@ -191,7 +191,7 @@ func (s *sysData) preferredSize(d *sysSizeData) (width int, height int) {
|
|||
uintptr(0),
|
||||
uintptr(unsafe.Pointer(&size)))
|
||||
if r1 != uintptr(_FALSE) { // success
|
||||
return int(size.cx), int(size.cy), 0 // TODO
|
||||
return int(size.cx), int(size.cy)
|
||||
}
|
||||
// otherwise the message approach failed, so fall back to the regular approach
|
||||
println("message failed; falling back")
|
||||
|
|
2
grid.go
2
grid.go
|
@ -184,7 +184,7 @@ _=ymargin
|
|||
w = g.colwidths[col]
|
||||
h = g.rowheights[row]
|
||||
}
|
||||
as := c.allocation(x, y, w, h, d)
|
||||
as := c.allocate(x, y, w, h, d)
|
||||
if current != nil { // connect first left to first right
|
||||
current.neighbor = c
|
||||
}
|
||||
|
|
2
label.go
2
label.go
|
@ -89,7 +89,7 @@ func (l *Label) preferredSize(d *sysSizeData) (width int, height int) {
|
|||
}
|
||||
|
||||
func (l *Label) commitResize(a *allocation, d *sysSizeData) {
|
||||
l.sysData.preferredSize(a, d)
|
||||
l.sysData.commitResize(a, d)
|
||||
}
|
||||
|
||||
func (l *Label) getAuxResizeInfo(d *sysSizeData) {
|
||||
|
|
|
@ -83,7 +83,7 @@ func (l *LineEdit) preferredSize(d *sysSizeData) (width int, height int) {
|
|||
}
|
||||
|
||||
func (l *LineEdit) commitResize(a *allocation, d *sysSizeData) {
|
||||
l.sysData.preferredSize(a, d)
|
||||
l.sysData.commitResize(a, d)
|
||||
}
|
||||
|
||||
func (l *LineEdit) getAuxResizeInfo(d *sysSizeData) {
|
||||
|
|
|
@ -165,7 +165,7 @@ func (l *Listbox) preferredSize(d *sysSizeData) (width int, height int) {
|
|||
}
|
||||
|
||||
func (l *Listbox) commitResize(a *allocation, d *sysSizeData) {
|
||||
l.sysData.preferredSize(a, d)
|
||||
l.sysData.commitResize(a, d)
|
||||
}
|
||||
|
||||
func (l *Listbox) getAuxResizeInfo(d *sysSizeData) {
|
||||
|
|
|
@ -71,7 +71,7 @@ func (p *ProgressBar) preferredSize(d *sysSizeData) (width int, height int) {
|
|||
}
|
||||
|
||||
func (p *ProgressBar) commitResize(a *allocation, d *sysSizeData) {
|
||||
p.sysData.preferredSize(a, d)
|
||||
p.sysData.commitResize(a, d)
|
||||
}
|
||||
|
||||
func (p *ProgressBar) getAuxResizeInfo(d *sysSizeData) {
|
||||
|
|
|
@ -148,7 +148,7 @@ func stdWndProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESUL
|
|||
_ = mm
|
||||
return 0
|
||||
case _WM_SIZE:
|
||||
if s.resize != nil {
|
||||
if s.allocate != nil {
|
||||
var r _RECT
|
||||
|
||||
r1, _, err := _getClientRect.Call(
|
||||
|
@ -157,8 +157,8 @@ func stdWndProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESUL
|
|||
if r1 == 0 {
|
||||
panic("GetClientRect failed: " + err.Error())
|
||||
}
|
||||
// top-left corner is (0,0) so no need for winheight
|
||||
s.doResize(int(r.left), int(r.top), int(r.right-r.left), int(r.bottom-r.top), 0)
|
||||
// top-left corner of a client rect is (0,0) so no need for left/top
|
||||
s.resizeWindow(int(r.right), int(r.bottom))
|
||||
// TODO use the Defer movement functions here?
|
||||
// TODO redraw window and all children here?
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ func newEvent() chan struct{} {
|
|||
type cSysData struct {
|
||||
ctype int
|
||||
event chan struct{}
|
||||
resize func(x int, y int, width int, height int, rr *[]resizerequest)
|
||||
allocate func(x int, y int, width int, height int, d *sysSizeData) []*allocation
|
||||
spaced bool
|
||||
alternate bool // editable for Combobox, multi-select for listbox, password for lineedit
|
||||
handler AreaHandler // for Areas
|
||||
|
@ -75,8 +75,5 @@ func mksysdata(ctype int) *sysData {
|
|||
ctype: ctype,
|
||||
},
|
||||
}
|
||||
if ctype == c_window { // make resizes non-nil so it can be passed in
|
||||
s.resizes = make([]resizerequest, 0, 0)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ func (w *Window) Create(control Control) {
|
|||
panic(fmt.Errorf("error opening window: %v", err))
|
||||
}
|
||||
if control != nil {
|
||||
w.sysData.resize = control.setRect
|
||||
w.sysData.allocate = control.allocate
|
||||
err = control.make(w.sysData)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("error adding window's control: %v", err))
|
||||
|
|
Loading…
Reference in New Issue