diff options
| author | Pietro Gagliardi <[email protected]> | 2014-08-02 01:14:09 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-08-02 01:14:09 -0400 |
| commit | 99b6b47a4963a84eab6aa0a941b7da5253399975 (patch) | |
| tree | 56c236ac5681b16dfa06865c99dafc061ef8bd4d /redo/sizer_unix.go | |
| parent | 0356d0fd7046071c1320db7340a14df54c79cb0f (diff) | |
Migrated the GTK+ backend to the new sizer system.
Diffstat (limited to 'redo/sizer_unix.go')
| -rw-r--r-- | redo/sizer_unix.go | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/redo/sizer_unix.go b/redo/sizer_unix.go new file mode 100644 index 0000000..4a3c7b4 --- /dev/null +++ b/redo/sizer_unix.go @@ -0,0 +1,84 @@ +// +build !windows,!darwin + +// 23 february 2014 + +package ui + +import ( + "unsafe" +"fmt" +) + +// #include "gtk_unix.h" +// extern void layoutResizing(GtkWidget *, GdkRectangle *, gpointer); +import "C" + +type sizing struct { + sizingbase + + // for size calculations + // gtk+ needs nothing + + // for the actual resizing + shouldVAlignTop bool +} + +const ( + gtkXMargin = 12 + gtkYMargin = 12 + gtkXPadding = 12 + gtkYPadding = 6 +) + +func (s *sizer) beginResize() (d *sizing) { + d = new(sizing) + if spaced { + d.xmargin = gtkXMargin + d.ymargin = gtkYMargin + d.xpadding = gtkXPadding + d.ypadding = gtkYPadding + } + return d +} + +func (s *sizer) translateAllocationCoords(allocations []*allocation, winwidth, winheight int) { + // no need for coordinate conversion with gtk+ +} + +// layout maintains the widget hierarchy by containing all of a sizer's children in a single layout widget +type layout struct { + *sizer + layoutwidget *C.GtkWidget + layoutcontainer *C.GtkContainer + layout *C.GtkLayout +} + +func newLayout(child Control) *layout { + widget := C.gtk_layout_new(nil, nil) + l := &layout{ + sizer: new(sizer), + layoutwidget: widget, + layoutcontainer: (*C.GtkContainer)(unsafe.Pointer(widget)), + layout: (*C.GtkLayout)(unsafe.Pointer(widget)), + } + l.child = child + l.child.setParent(&controlParent{l.layoutcontainer}) + // we connect to the layout's size-allocate, not to the window's configure-event + // this allows us to handle client-side decoration-based configurations (such as GTK+ on Wayland) properly + // also see commitResize() in sizing_unix.go for additional notes + // thanks to many people in irc.gimp.net/#gtk+ for help (including tristan for suggesting g_signal_connect_after()) + g_signal_connect_after( + C.gpointer(unsafe.Pointer(l.layout)), + "size-allocate", + C.GCallback(C.layoutResizing), + C.gpointer(unsafe.Pointer(l))) + return l +} + +//export layoutResizing +func layoutResizing(wid *C.GtkWidget, r *C.GdkRectangle, data C.gpointer) { + l := (*layout)(unsafe.Pointer(data)) + // the layout's coordinate system is localized, so the origin is (0, 0) + l.resize(0, 0, int(r.width), int(r.height)) +fmt.Printf("new size %d x %d\n", r.width, r.height) +} |
