Fixed the proper recursive application of spaced on Windows tabs by having container.resize() also take the origin coordinates as arguments.
This commit is contained in:
parent
13bcf728ba
commit
286704bedd
|
@ -42,6 +42,7 @@ func (t *tab) allocate(x int, y int, width int, height int, d *sizing) []*alloca
|
|||
func tabResized(data unsafe.Pointer, width C.intptr_t, height C.intptr_t) {
|
||||
t := (*tab)(unsafe.Pointer(data))
|
||||
for _, c := range t.containers {
|
||||
c.resize(int(width), int(height))
|
||||
// the tab area's coordinate system is localized, so the origin is (0, 0)
|
||||
c.resize(0, 0, int(width), int(height))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,5 +66,6 @@ func (t *tab) allocate(x int, y int, width int, height int, d *sizing) []*alloca
|
|||
//export layoutResizing
|
||||
func layoutResizing(wid *C.GtkWidget, r *C.GdkRectangle, data C.gpointer) {
|
||||
c := (*container)(unsafe.Pointer(data))
|
||||
c.resize(int(r.width), int(r.height))
|
||||
// the layout's coordinate system is localized, so the origin is (0, 0)
|
||||
c.resize(0, 0, int(r.width), int(r.height))
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
import "C"
|
||||
|
||||
/*
|
||||
On Windows, container controls are just regular controls; their children have to be children of the parent window, and changing the contents of a switching container (such as a tab control) must be done manually. Mind the odd code here.
|
||||
On Windows, container controls are just regular controls; their children have to be children of the parent window, and changing the contents of a switching container (such as a tab control) must be done manually.
|
||||
|
||||
TODO
|
||||
- make sure all tabs cannot be deselected (that is, make sure the current tab can never have index -1)
|
||||
|
@ -20,7 +20,7 @@ TODO
|
|||
|
||||
type tab struct {
|
||||
*widgetbase
|
||||
tabs []Control
|
||||
tabs []*container
|
||||
}
|
||||
|
||||
func newTab() Tab {
|
||||
|
@ -38,14 +38,16 @@ func newTab() Tab {
|
|||
func (t *tab) setParent(win C.HWND) {
|
||||
t.widgetbase.setParent(win)
|
||||
for _, c := range t.tabs {
|
||||
c.setParent(win)
|
||||
c.child.setParent(win)
|
||||
}
|
||||
}
|
||||
|
||||
func (t *tab) Append(name string, control Control) {
|
||||
t.tabs = append(t.tabs, control)
|
||||
c := new(container)
|
||||
t.tabs = append(t.tabs, c)
|
||||
c.child = control
|
||||
if t.parent != nil {
|
||||
control.setParent(t.parent)
|
||||
c.child.setParent(t.parent)
|
||||
}
|
||||
C.tabAppend(t.hwnd, toUTF16(name))
|
||||
}
|
||||
|
@ -53,31 +55,31 @@ func (t *tab) Append(name string, control Control) {
|
|||
//export tabChanging
|
||||
func tabChanging(data unsafe.Pointer, current C.LRESULT) {
|
||||
t := (*tab)(data)
|
||||
t.tabs[int(current)].containerHide()
|
||||
t.tabs[int(current)].child.containerHide()
|
||||
}
|
||||
|
||||
//export tabChanged
|
||||
func tabChanged(data unsafe.Pointer, new C.LRESULT) {
|
||||
t := (*tab)(data)
|
||||
t.tabs[int(new)].containerShow()
|
||||
t.tabs[int(new)].child.containerShow()
|
||||
}
|
||||
|
||||
// a tab control contains other controls; size appropriately
|
||||
func (t *tab) allocate(x int, y int, width int, height int, d *sizing) []*allocation {
|
||||
var r C.RECT
|
||||
|
||||
// first, append the tab control itself
|
||||
a := t.widgetbase.allocate(x, y, width, height, d)
|
||||
// now figure out what the rect for each child is
|
||||
r.left = C.LONG(x) // load rect with existing values
|
||||
// figure out what the rect for each child is...
|
||||
r.left = C.LONG(x) // load structure with the window's rect
|
||||
r.top = C.LONG(y)
|
||||
r.right = C.LONG(x + width)
|
||||
r.bottom = C.LONG(y + height)
|
||||
C.tabGetContentRect(t.hwnd, &r)
|
||||
// and allocate
|
||||
// don't allocate to just hte current tab; allocate to all tabs!
|
||||
// don't allocate to just the current tab; allocate to all tabs!
|
||||
for _, c := range t.tabs {
|
||||
a = append(a, c.allocate(int(r.left), int(r.top), int(r.right - r.left), int(r.bottom - r.top), d)...)
|
||||
// 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))
|
||||
}
|
||||
return a
|
||||
// and now allocate the tab control itself
|
||||
return t.widgetbase.allocate(x, y, width, height, d)
|
||||
}
|
||||
|
|
|
@ -34,12 +34,12 @@ type container struct {
|
|||
// set to true to apply spacing to all windows
|
||||
var spaced bool = false
|
||||
|
||||
func (c *container) resize(width, height int) {
|
||||
func (c *container) resize(x, y, width, height int) {
|
||||
if c.child == nil { // no children; nothing to do
|
||||
return
|
||||
}
|
||||
d := c.beginResize()
|
||||
allocations := c.child.allocate(0 + d.xmargin, 0 + d.ymargin, width - (2 * d.xmargin), height - (2 * d.ymargin), d)
|
||||
allocations := c.child.allocate(x + d.xmargin, y + d.ymargin, width - (2 * d.xmargin), height - (2 * d.ymargin), d)
|
||||
c.translateAllocationCoords(allocations, width, height)
|
||||
// move in reverse so as to approximate right->left order so neighbors make sense
|
||||
for i := len(allocations) - 1; i >= 0; i-- {
|
||||
|
|
|
@ -77,6 +77,7 @@ func windowClosing(xw unsafe.Pointer) C.BOOL {
|
|||
//export windowResized
|
||||
func windowResized(xw unsafe.Pointer, width C.uintptr_t, height C.uintptr_t) {
|
||||
w := (*window)(unsafe.Pointer(xw))
|
||||
w.resize(int(width), int(height))
|
||||
// the origin of the window's content area is always (0, 0)
|
||||
w.resize(0, 0, int(width), int(height))
|
||||
fmt.Printf("new size %d x %d\n", width, height)
|
||||
}
|
||||
|
|
|
@ -110,6 +110,7 @@ func windowClosing(wid *C.GtkWidget, e *C.GdkEvent, data C.gpointer) C.gboolean
|
|||
//export windowResizing
|
||||
func windowResizing(wid *C.GtkWidget, r *C.GdkRectangle, data C.gpointer) {
|
||||
w := (*window)(unsafe.Pointer(data))
|
||||
w.resize(int(r.width), int(r.height))
|
||||
// the origin of the window's content area is always (0, 0)
|
||||
w.resize(0, 0, int(r.width), int(r.height))
|
||||
fmt.Printf("new size %d x %d\n", r.width, r.height)
|
||||
}
|
||||
|
|
|
@ -96,7 +96,8 @@ func storeWindowHWND(data unsafe.Pointer, hwnd C.HWND) {
|
|||
//export windowResize
|
||||
func windowResize(data unsafe.Pointer, r *C.RECT) {
|
||||
w := (*window)(data)
|
||||
w.resize(int(r.right - r.left), int(r.bottom - r.top))
|
||||
// the origin of the window's content area is always (0, 0), but let's use the values from the RECT just to be safe
|
||||
w.resize(int(r.left), int(r.top), int(r.right - r.left), int(r.bottom - r.top))
|
||||
}
|
||||
|
||||
//export windowClosing
|
||||
|
|
Loading…
Reference in New Issue