Changed Control.setParent() to take the same argument type on all platforms; this is needed for re-adding Stack and Grid. This argument type is defined by each platform.
This commit is contained in:
parent
f4bb7360d4
commit
9daab20fce
|
@ -30,7 +30,7 @@ func (t *tab) Append(name string, control Control) {
|
|||
defer C.free(unsafe.Pointer(cname))
|
||||
tabview := C.tabAppend(t.id, cname)
|
||||
c.child = control
|
||||
c.child.setParent(tabview)
|
||||
c.child.setParent(&controlParent{tabview})
|
||||
}
|
||||
|
||||
func (t *tab) allocate(x int, y int, width int, height int, d *sizing) []*allocation {
|
||||
|
|
|
@ -42,7 +42,7 @@ func (t *tab) Append(name string, control Control) {
|
|||
c := new(container)
|
||||
t.containers = append(t.containers, c)
|
||||
c.child = control
|
||||
c.child.setParent((*C.GtkContainer)(unsafe.Pointer(layout)))
|
||||
c.child.setParent(&controlParent{(*C.GtkContainer)(unsafe.Pointer(layout))})
|
||||
g_signal_connect_after(
|
||||
C.gpointer(unsafe.Pointer(layout)),
|
||||
"size-allocate",
|
||||
|
|
|
@ -34,10 +34,10 @@ func newTab() Tab {
|
|||
return t
|
||||
}
|
||||
|
||||
func (t *tab) setParent(win C.HWND) {
|
||||
t.widgetbase.setParent(win)
|
||||
func (t *tab) setParent(p *controlParent) {
|
||||
t.widgetbase.setParent(p)
|
||||
for _, c := range t.tabs {
|
||||
c.child.setParent(win)
|
||||
c.child.setParent(p)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ func (t *tab) Append(name string, control Control) {
|
|||
t.tabs = append(t.tabs, c)
|
||||
c.child = control
|
||||
if t.parent != nil {
|
||||
c.child.setParent(t.parent)
|
||||
c.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
|
||||
if len(t.tabs) != 1 {
|
||||
|
|
|
@ -5,7 +5,7 @@ package ui
|
|||
// Control represents a control.
|
||||
// All Controls have event handlers that take a single argument (the Doer active during the event) and return nothing.
|
||||
type Control interface {
|
||||
controlParent // platform-specific
|
||||
setParent(p *controlParent) // controlParent defined per-platform
|
||||
// TODO enable/disable (public)
|
||||
// TODO show/hide (public)
|
||||
containerShow() // for Windows, where all controls need ot belong to an overlapped window, not to a container control; these respect programmer settings
|
||||
|
|
|
@ -21,9 +21,13 @@ func newWidget(id C.id) *widgetbase {
|
|||
|
||||
// these few methods are embedded by all the various Controls since they all will do the same thing
|
||||
|
||||
func (w *widgetbase) setParent(parent C.id) {
|
||||
type controlParent struct {
|
||||
id C.id
|
||||
}
|
||||
|
||||
func (w *widgetbase) setParent(parent *controlParent) {
|
||||
// redrawing the new window handled by C.parent()
|
||||
C.parent(w.id, parent)
|
||||
C.parent(w.id, parent.id)
|
||||
}
|
||||
|
||||
func (w *widgetbase) containerShow() {
|
||||
|
|
|
@ -28,8 +28,12 @@ func newWidget(w *C.GtkWidget) *widgetbase {
|
|||
|
||||
// these few methods are embedded by all the various Controls since they all will do the same thing
|
||||
|
||||
func (w *widgetbase) setParent(c *C.GtkContainer) {
|
||||
C.gtk_container_add(c, w.widget)
|
||||
type controlParent struct {
|
||||
c *C.GtkContainer
|
||||
}
|
||||
|
||||
func (w *widgetbase) setParent(c *controlParent) {
|
||||
C.gtk_container_add(c.c, w.widget)
|
||||
// make sure the new widget is shown
|
||||
C.gtk_widget_show_all(w.widget)
|
||||
}
|
||||
|
|
|
@ -22,9 +22,13 @@ func newWidget(class C.LPCWSTR, style C.DWORD, extstyle C.DWORD) *widgetbase {
|
|||
|
||||
// these few methods are embedded by all the various Controls since they all will do the same thing
|
||||
|
||||
func (w *widgetbase) setParent(win C.HWND) {
|
||||
C.controlSetParent(w.hwnd, win)
|
||||
w.parent = win
|
||||
type controlParent struct {
|
||||
hwnd C.HWND
|
||||
}
|
||||
|
||||
func (w *widgetbase) setParent(win *controlParent) {
|
||||
C.controlSetParent(w.hwnd, win.hwnd)
|
||||
w.parent = win.hwnd
|
||||
}
|
||||
|
||||
func (w *widgetbase) containerShow() {
|
||||
|
|
|
@ -18,10 +18,6 @@ type window struct {
|
|||
*container
|
||||
}
|
||||
|
||||
type controlParent interface {
|
||||
setParent(C.id)
|
||||
}
|
||||
|
||||
func newWindow(title string, width int, height int, control Control) *window {
|
||||
id := C.newWindow(C.intptr_t(width), C.intptr_t(height))
|
||||
ctitle := C.CString(title)
|
||||
|
@ -34,7 +30,7 @@ func newWindow(title string, width int, height int, control Control) *window {
|
|||
}
|
||||
C.windowSetDelegate(id, unsafe.Pointer(w))
|
||||
w.child = control
|
||||
w.child.setParent(C.windowContentView(w.id))
|
||||
w.child.setParent(&controlParent{C.windowContentView(w.id)})
|
||||
return w
|
||||
}
|
||||
|
||||
|
|
|
@ -29,10 +29,6 @@ type window struct {
|
|||
*container
|
||||
}
|
||||
|
||||
type controlParent interface {
|
||||
setParent(*C.GtkContainer)
|
||||
}
|
||||
|
||||
func newWindow(title string, width int, height int, control Control) *window {
|
||||
widget := C.gtk_window_new(C.GTK_WINDOW_TOPLEVEL)
|
||||
ctitle := togstr(title)
|
||||
|
@ -67,7 +63,7 @@ func newWindow(title string, width int, height int, control Control) *window {
|
|||
C.gtk_window_resize(w.window, C.gint(width), C.gint(height))
|
||||
C.gtk_container_add(w.wc, layoutw)
|
||||
w.child = control
|
||||
w.child.setParent(w.layoutc)
|
||||
w.child.setParent(&controlParent{w.layoutc})
|
||||
return w
|
||||
}
|
||||
|
||||
|
|
|
@ -33,10 +33,6 @@ func makeWindowWindowClass() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
type controlParent interface {
|
||||
setParent(C.HWND)
|
||||
}
|
||||
|
||||
func newWindow(title string, width int, height int, control Control) *window {
|
||||
w := &window{
|
||||
// hwnd set in WM_CREATE handler
|
||||
|
@ -53,7 +49,7 @@ func newWindow(title string, width int, height int, control Control) *window {
|
|||
panic(fmt.Errorf("error setting tab background texture on Window; HRESULT: 0x%X", hresult))
|
||||
}
|
||||
w.child = control
|
||||
w.child.setParent(w.hwnd)
|
||||
w.child.setParent(&controlParent{w.hwnd})
|
||||
return w
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue