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) {
|
func tabResized(data unsafe.Pointer, width C.intptr_t, height C.intptr_t) {
|
||||||
t := (*tab)(unsafe.Pointer(data))
|
t := (*tab)(unsafe.Pointer(data))
|
||||||
for _, c := range t.containers {
|
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
|
//export layoutResizing
|
||||||
func layoutResizing(wid *C.GtkWidget, r *C.GdkRectangle, data C.gpointer) {
|
func layoutResizing(wid *C.GtkWidget, r *C.GdkRectangle, data C.gpointer) {
|
||||||
c := (*container)(unsafe.Pointer(data))
|
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"
|
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
|
TODO
|
||||||
- make sure all tabs cannot be deselected (that is, make sure the current tab can never have index -1)
|
- 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 {
|
type tab struct {
|
||||||
*widgetbase
|
*widgetbase
|
||||||
tabs []Control
|
tabs []*container
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTab() Tab {
|
func newTab() Tab {
|
||||||
|
@ -38,14 +38,16 @@ func newTab() Tab {
|
||||||
func (t *tab) setParent(win C.HWND) {
|
func (t *tab) setParent(win C.HWND) {
|
||||||
t.widgetbase.setParent(win)
|
t.widgetbase.setParent(win)
|
||||||
for _, c := range t.tabs {
|
for _, c := range t.tabs {
|
||||||
c.setParent(win)
|
c.child.setParent(win)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *tab) Append(name string, control Control) {
|
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 {
|
if t.parent != nil {
|
||||||
control.setParent(t.parent)
|
c.child.setParent(t.parent)
|
||||||
}
|
}
|
||||||
C.tabAppend(t.hwnd, toUTF16(name))
|
C.tabAppend(t.hwnd, toUTF16(name))
|
||||||
}
|
}
|
||||||
|
@ -53,31 +55,31 @@ func (t *tab) Append(name string, control Control) {
|
||||||
//export tabChanging
|
//export tabChanging
|
||||||
func tabChanging(data unsafe.Pointer, current C.LRESULT) {
|
func tabChanging(data unsafe.Pointer, current C.LRESULT) {
|
||||||
t := (*tab)(data)
|
t := (*tab)(data)
|
||||||
t.tabs[int(current)].containerHide()
|
t.tabs[int(current)].child.containerHide()
|
||||||
}
|
}
|
||||||
|
|
||||||
//export tabChanged
|
//export tabChanged
|
||||||
func tabChanged(data unsafe.Pointer, new C.LRESULT) {
|
func tabChanged(data unsafe.Pointer, new C.LRESULT) {
|
||||||
t := (*tab)(data)
|
t := (*tab)(data)
|
||||||
t.tabs[int(new)].containerShow()
|
t.tabs[int(new)].child.containerShow()
|
||||||
}
|
}
|
||||||
|
|
||||||
// a tab control contains other controls; size appropriately
|
// a tab control contains other controls; size appropriately
|
||||||
func (t *tab) allocate(x int, y int, width int, height int, d *sizing) []*allocation {
|
func (t *tab) allocate(x int, y int, width int, height int, d *sizing) []*allocation {
|
||||||
var r C.RECT
|
var r C.RECT
|
||||||
|
|
||||||
// first, append the tab control itself
|
// figure out what the rect for each child is...
|
||||||
a := t.widgetbase.allocate(x, y, width, height, d)
|
r.left = C.LONG(x) // load structure with the window's rect
|
||||||
// now figure out what the rect for each child is
|
|
||||||
r.left = C.LONG(x) // load rect with existing values
|
|
||||||
r.top = C.LONG(y)
|
r.top = C.LONG(y)
|
||||||
r.right = C.LONG(x + width)
|
r.right = C.LONG(x + width)
|
||||||
r.bottom = C.LONG(y + height)
|
r.bottom = C.LONG(y + height)
|
||||||
C.tabGetContentRect(t.hwnd, &r)
|
C.tabGetContentRect(t.hwnd, &r)
|
||||||
// and allocate
|
// 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 {
|
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
|
// set to true to apply spacing to all windows
|
||||||
var spaced bool = false
|
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
|
if c.child == nil { // no children; nothing to do
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
d := c.beginResize()
|
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)
|
c.translateAllocationCoords(allocations, width, height)
|
||||||
// move in reverse so as to approximate right->left order so neighbors make sense
|
// move in reverse so as to approximate right->left order so neighbors make sense
|
||||||
for i := len(allocations) - 1; i >= 0; i-- {
|
for i := len(allocations) - 1; i >= 0; i-- {
|
||||||
|
|
|
@ -77,6 +77,7 @@ func windowClosing(xw unsafe.Pointer) C.BOOL {
|
||||||
//export windowResized
|
//export windowResized
|
||||||
func windowResized(xw unsafe.Pointer, width C.uintptr_t, height C.uintptr_t) {
|
func windowResized(xw unsafe.Pointer, width C.uintptr_t, height C.uintptr_t) {
|
||||||
w := (*window)(unsafe.Pointer(xw))
|
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)
|
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
|
//export windowResizing
|
||||||
func windowResizing(wid *C.GtkWidget, r *C.GdkRectangle, data C.gpointer) {
|
func windowResizing(wid *C.GtkWidget, r *C.GdkRectangle, data C.gpointer) {
|
||||||
w := (*window)(unsafe.Pointer(data))
|
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)
|
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
|
//export windowResize
|
||||||
func windowResize(data unsafe.Pointer, r *C.RECT) {
|
func windowResize(data unsafe.Pointer, r *C.RECT) {
|
||||||
w := (*window)(data)
|
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
|
//export windowClosing
|
||||||
|
|
Loading…
Reference in New Issue