From 8a81650b3da7ce00725336df9e03b38e935c5a65 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 2 Jul 2014 22:53:03 -0400 Subject: Moved it all back; the preemptive multitaksing during an event handler kills us on all platforms. Going to have to restrict ALL GUI accss to happening from one t hread, so going to need to drop uitask entirely and have just a start() callback for startup code and a post() function for posting requests to windows (like channel sends but into a perpetual buffer). --- controlsize_unix.go | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 controlsize_unix.go (limited to 'controlsize_unix.go') diff --git a/controlsize_unix.go b/controlsize_unix.go new file mode 100644 index 0000000..5ea7bf7 --- /dev/null +++ b/controlsize_unix.go @@ -0,0 +1,78 @@ +// +build !windows,!darwin,!plan9 + +// 23 february 2014 + +package ui + +type sysSizeData struct { + cSysSizeData + + // for size calculations + // gtk+ needs nothing + + // for the actual resizing + shouldVAlignTop bool +} + +const ( + gtkXMargin = 12 + gtkYMargin = 12 + gtkXPadding = 12 + gtkYPadding = 6 +) + +func (s *sysData) beginResize() (d *sysSizeData) { + d = new(sysSizeData) + if s.spaced { + d.xmargin = gtkXMargin + d.ymargin = gtkYMargin + d.xpadding = gtkXPadding + d.ypadding = gtkYPadding + } + return d +} + +func (s *sysData) endResize(d *sysSizeData) { + // redraw +} + +func (s *sysData) translateAllocationCoords(allocations []*allocation, winwidth, winheight int) { + // no need for coordinate conversion with gtk+ +} + +func (s *sysData) commitResize(c *allocation, d *sysSizeData) { + if s.ctype == c_label && !s.alternate && c.neighbor != nil { + c.neighbor.getAuxResizeInfo(d) + if d.shouldVAlignTop { + // TODO should it be center-aligned to the first line or not + gtk_misc_set_alignment(s.widget, 0, 0) + } else { + gtk_misc_set_alignment(s.widget, 0, 0.5) + } + } + // TODO merge this here + s.setRect(c.x, c.y, c.width, c.height, 0) +} + +func (s *sysData) getAuxResizeInfo(d *sysSizeData) { + d.shouldVAlignTop = (s.ctype == c_listbox) || (s.ctype == c_area) +} + +// GTK+ 3 makes this easy: controls can tell us what their preferred size is! +// ...actually, it tells us two things: the "minimum size" and the "natural size". +// The "minimum size" is the smallest size we /can/ display /anything/. The "natural size" is the smallest size we would /prefer/ to display. +// The difference? Minimum size takes into account things like truncation with ellipses: the minimum size of a label can allot just the ellipses! +// So we use the natural size instead. +// There is a warning about height-for-width controls, but in my tests this isn't an issue. +// For Areas, we manually save the Area size and use that, just to be safe. + +// We don't need to worry about y-offset because label alignment is "vertically center", which GtkLabel does for us. + +func (s *sysData) preferredSize(d *sysSizeData) (width int, height int) { + if s.ctype == c_area { + return s.areawidth, s.areaheight + } + + _, _, width, height = gtk_widget_get_preferred_size(s.widget) + return width, height +} -- cgit v1.2.3