Migrated the Windows backend to use sizer.
This commit is contained in:
parent
e9b2f9f478
commit
0356d0fd70
|
@ -19,7 +19,7 @@ TODO
|
||||||
|
|
||||||
type tab struct {
|
type tab struct {
|
||||||
*controlbase
|
*controlbase
|
||||||
tabs []*container
|
tabs []*sizer
|
||||||
supersetParent func(p *controlParent)
|
supersetParent func(p *controlParent)
|
||||||
superallocate func(x int, y int, width int, height int, d *sizing) []*allocation
|
superallocate func(x int, y int, width int, height int, d *sizing) []*allocation
|
||||||
}
|
}
|
||||||
|
@ -48,15 +48,15 @@ func (t *tab) tabsetParent(p *controlParent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *tab) Append(name string, control Control) {
|
func (t *tab) Append(name string, control Control) {
|
||||||
c := new(container)
|
s := new(sizer)
|
||||||
t.tabs = append(t.tabs, c)
|
t.tabs = append(t.tabs, s)
|
||||||
c.child = control
|
s.child = control
|
||||||
if t.parent != nil {
|
if t.parent != nil {
|
||||||
c.child.setParent(&controlParent{t.parent})
|
s.child.setParent(&controlParent{t.parent})
|
||||||
}
|
}
|
||||||
// initially hide tab 1..n controls; if we don't, they'll appear over other tabs, resulting in weird behavior
|
// initially hide tab 1..n controls; if we don't, they'll appear over other tabs, resulting in weird behavior
|
||||||
if len(t.tabs) != 1 {
|
if len(t.tabs) != 1 {
|
||||||
c.child.containerHide()
|
s.child.containerHide()
|
||||||
}
|
}
|
||||||
C.tabAppend(t.hwnd, toUTF16(name))
|
C.tabAppend(t.hwnd, toUTF16(name))
|
||||||
}
|
}
|
||||||
|
@ -74,6 +74,7 @@ func tabChanged(data unsafe.Pointer, new C.LRESULT) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// a tab control contains other controls; size appropriately
|
// a tab control contains other controls; size appropriately
|
||||||
|
// TODO change this to commitResize()
|
||||||
func (t *tab) taballocate(x int, y int, width int, height int, d *sizing) []*allocation {
|
func (t *tab) taballocate(x int, y int, width int, height int, d *sizing) []*allocation {
|
||||||
var r C.RECT
|
var r C.RECT
|
||||||
|
|
||||||
|
@ -85,9 +86,9 @@ func (t *tab) taballocate(x int, y int, width int, height int, d *sizing) []*all
|
||||||
C.tabGetContentRect(t.hwnd, &r)
|
C.tabGetContentRect(t.hwnd, &r)
|
||||||
// and allocate
|
// and allocate
|
||||||
// don't allocate to just the current tab; allocate to all tabs!
|
// don't allocate to just the current tab; allocate to all tabs!
|
||||||
for _, c := range t.tabs {
|
for _, s := range t.tabs {
|
||||||
// because each widget is actually a child of the Window, the origin is the one we calculated above
|
// because each widget is actually a child of the Window, the origin is the one we calculated above
|
||||||
c.resize(int(r.left), int(r.top), int(r.right - r.left), int(r.bottom - r.top))
|
s.resize(int(r.left), int(r.top), int(r.right - r.left), int(r.bottom - r.top))
|
||||||
}
|
}
|
||||||
// and now allocate the tab control itself
|
// and now allocate the tab control itself
|
||||||
return t.superallocate(x, y, width, height, d)
|
return t.superallocate(x, y, width, height, d)
|
||||||
|
|
|
@ -41,7 +41,7 @@ const (
|
||||||
paddingDialogUnits = 4
|
paddingDialogUnits = 4
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *container) beginResize() (d *sizing) {
|
func (s *sizer) beginResize() (d *sizing) {
|
||||||
d = new(sizing)
|
d = new(sizing)
|
||||||
|
|
||||||
d.baseX = C.baseX
|
d.baseX = C.baseX
|
||||||
|
@ -57,7 +57,7 @@ func (c *container) beginResize() (d *sizing) {
|
||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *container) translateAllocationCoords(allocations []*allocation, winwidth, winheight int) {
|
func (s *sizer) translateAllocationCoords(allocations []*allocation, winwidth, winheight int) {
|
||||||
// no translation needed on windows
|
// no translation needed on windows
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
#include "winapi_windows.h"
|
#include "winapi_windows.h"
|
||||||
#include "_cgo_export.h"
|
#include "_cgo_export.h"
|
||||||
|
|
||||||
|
/* TODO rename to sizer_windows.c and move all but the first function to control_windows.c */
|
||||||
|
|
||||||
BOOL baseUnitsCalculated = FALSE;
|
BOOL baseUnitsCalculated = FALSE;
|
||||||
int baseX;
|
int baseX;
|
||||||
int baseY;
|
int baseY;
|
||||||
|
|
|
@ -17,7 +17,7 @@ type window struct {
|
||||||
|
|
||||||
closing *event
|
closing *event
|
||||||
|
|
||||||
*container
|
*sizer
|
||||||
}
|
}
|
||||||
|
|
||||||
const windowclassname = ""
|
const windowclassname = ""
|
||||||
|
@ -37,7 +37,7 @@ func newWindow(title string, width int, height int, control Control) *window {
|
||||||
w := &window{
|
w := &window{
|
||||||
// hwnd set in WM_CREATE handler
|
// hwnd set in WM_CREATE handler
|
||||||
closing: newEvent(),
|
closing: newEvent(),
|
||||||
container: new(container),
|
sizer: new(sizer),
|
||||||
}
|
}
|
||||||
hwnd := C.newWindow(toUTF16(title), C.int(width), C.int(height), unsafe.Pointer(w))
|
hwnd := C.newWindow(toUTF16(title), C.int(width), C.int(height), unsafe.Pointer(w))
|
||||||
if hwnd != w.hwnd {
|
if hwnd != w.hwnd {
|
||||||
|
|
Loading…
Reference in New Issue