Implemented Tab on GTK+. I really don't like the way sizing works now...
This commit is contained in:
parent
3d5e8feba4
commit
c676a2d9b7
|
@ -0,0 +1,62 @@
|
||||||
|
// 25 july 2014
|
||||||
|
|
||||||
|
package ui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
// #include "gtk_unix.h"
|
||||||
|
// extern void layoutResizing(GtkWidget *, GdkRectangle *, gpointer);
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
type tab struct {
|
||||||
|
*widgetbase
|
||||||
|
notebook *C.GtkNotebook
|
||||||
|
|
||||||
|
containers []*container
|
||||||
|
layoutws []*C.GtkWidget
|
||||||
|
layoutcs []*C.GtkContainer
|
||||||
|
layouts []*C.GtkLayout
|
||||||
|
}
|
||||||
|
|
||||||
|
func newTab() Tab {
|
||||||
|
widget := C.gtk_notebook_new()
|
||||||
|
t := &tab{
|
||||||
|
widgetbase: newWidget(widget),
|
||||||
|
notebook: (*C.GtkNotebook)(unsafe.Pointer(widget)),
|
||||||
|
}
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *tab) Append(name string, control Control) {
|
||||||
|
// TODO isolate and standardize
|
||||||
|
layout := C.gtk_layout_new(nil, nil)
|
||||||
|
t.layoutws = append(t.layoutws, layout)
|
||||||
|
t.layoutcs = append(t.layoutcs, (*C.GtkContainer)(unsafe.Pointer(layout)))
|
||||||
|
t.layouts = append(t.layouts, (*C.GtkLayout)(unsafe.Pointer(layout)))
|
||||||
|
c := new(container)
|
||||||
|
c.beginResize = beginResize
|
||||||
|
t.containers = append(t.containers, c)
|
||||||
|
c.child = control
|
||||||
|
c.child.setParent((*C.GtkContainer)(unsafe.Pointer(layout)))
|
||||||
|
g_signal_connect_after(
|
||||||
|
C.gpointer(unsafe.Pointer(layout)),
|
||||||
|
"size-allocate",
|
||||||
|
C.GCallback(C.layoutResizing),
|
||||||
|
C.gpointer(unsafe.Pointer(c)))
|
||||||
|
cname := togstr(name)
|
||||||
|
defer freegstr(cname)
|
||||||
|
tab := C.gtk_notebook_append_page(t.notebook,
|
||||||
|
layout,
|
||||||
|
C.gtk_label_new(cname))
|
||||||
|
if tab == -1 {
|
||||||
|
panic("gtk_notebook_append_page() failed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//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))
|
||||||
|
}
|
|
@ -120,7 +120,3 @@ func (c *checkbox) Checked() bool {
|
||||||
func (c *checkbox) SetChecked(checked bool) {
|
func (c *checkbox) SetChecked(checked bool) {
|
||||||
C.gtk_toggle_button_set_active(c.toggle, togbool(checked))
|
C.gtk_toggle_button_set_active(c.toggle, togbool(checked))
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO
|
|
||||||
func newTab() Tab{return newButton("tab")}
|
|
||||||
func(*button)Append(string,Control){}
|
|
||||||
|
|
|
@ -18,14 +18,6 @@ type sizingbase struct {
|
||||||
ypadding int
|
ypadding int
|
||||||
}
|
}
|
||||||
|
|
||||||
// this ensures that all *windows across all platforms contain the necessary functions
|
|
||||||
// if this fails to compile, we have a problem
|
|
||||||
var windowSizeEnsure interface {
|
|
||||||
beginResize() *sizing
|
|
||||||
endResize(*sizing)
|
|
||||||
translateAllocationCoords([]*allocation, int, int)
|
|
||||||
} = &window{}
|
|
||||||
|
|
||||||
type controlSizing interface {
|
type controlSizing interface {
|
||||||
allocate(x int, y int, width int, height int, d *sizing) []*allocation
|
allocate(x int, y int, width int, height int, d *sizing) []*allocation
|
||||||
preferredSize(*sizing) (int, int)
|
preferredSize(*sizing) (int, int)
|
||||||
|
@ -33,8 +25,8 @@ type controlSizing interface {
|
||||||
getAuxResizeInfo(*sizing)
|
getAuxResizeInfo(*sizing)
|
||||||
}
|
}
|
||||||
|
|
||||||
// on Windows, this is only embedded by window, as all other containers cannot have their own children
|
// on Windows, this is only embedded by window, as all other containers cannot have their own children; beginResize() points to an instance method literal (TODO get correct term) from window
|
||||||
// on GTK+ and Mac OS X, one is embedded by window and all containers; the containers call container.continueResize()
|
// on GTK+ and Mac OS X, one is embedded by window and all containers; beginResize() points to a global function (TODO NOT GOOD; ideally the sizing data should be passed across size-allocate requests)
|
||||||
type container struct {
|
type container struct {
|
||||||
child Control
|
child Control
|
||||||
spaced bool
|
spaced bool
|
||||||
|
@ -46,13 +38,6 @@ func (c *container) resize(width, height int) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
d := c.beginResize()
|
d := c.beginResize()
|
||||||
c.continueResize(width, height, d)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *container) continueResize(width, height int, d *sizing) {
|
|
||||||
if c.child == nil { // no children; nothing to do
|
|
||||||
return
|
|
||||||
}
|
|
||||||
allocations := c.child.allocate(0, 0, width, height, d)
|
allocations := c.child.allocate(0, 0, width, height, 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
|
||||||
|
|
|
@ -24,14 +24,15 @@ const (
|
||||||
gtkYPadding = 6
|
gtkYPadding = 6
|
||||||
)
|
)
|
||||||
|
|
||||||
func (w *window) beginResize() (d *sizing) {
|
func beginResize() (d *sizing) {
|
||||||
d = new(sizing)
|
d = new(sizing)
|
||||||
if w.spaced {
|
//TODO
|
||||||
d.xmargin = gtkXMargin
|
// if w.spaced {
|
||||||
d.ymargin = gtkYMargin
|
// d.xmargin = gtkXMargin
|
||||||
d.xpadding = gtkXPadding
|
// d.ymargin = gtkYMargin
|
||||||
d.ypadding = gtkYPadding
|
// d.xpadding = gtkXPadding
|
||||||
}
|
// d.ypadding = gtkYPadding
|
||||||
|
// }
|
||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ func newWindow(title string, width int, height int, control Control) *window {
|
||||||
closing: newEvent(),
|
closing: newEvent(),
|
||||||
container: new(container),
|
container: new(container),
|
||||||
}
|
}
|
||||||
w.container.beginResize = w.beginResize
|
w.container.beginResize = beginResize
|
||||||
C.gtk_window_set_title(w.window, ctitle)
|
C.gtk_window_set_title(w.window, ctitle)
|
||||||
g_signal_connect(
|
g_signal_connect(
|
||||||
C.gpointer(unsafe.Pointer(w.window)),
|
C.gpointer(unsafe.Pointer(w.window)),
|
||||||
|
|
Loading…
Reference in New Issue