2014-07-17 22:50:14 -05:00
|
|
|
// +build !windows,!darwin
|
2014-07-16 20:30:19 -05:00
|
|
|
|
|
|
|
// 23 february 2014
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
|
|
|
// #include "gtk_unix.h"
|
|
|
|
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
|
|
|
|
)
|
|
|
|
|
2014-07-28 13:00:01 -05:00
|
|
|
func (c *container) beginResize() (d *sizing) {
|
2014-07-16 20:30:19 -05:00
|
|
|
d = new(sizing)
|
2014-07-28 13:00:01 -05:00
|
|
|
if spaced {
|
2014-07-25 21:13:09 -05:00
|
|
|
d.xmargin = gtkXMargin
|
|
|
|
d.ymargin = gtkYMargin
|
|
|
|
d.xpadding = gtkXPadding
|
|
|
|
d.ypadding = gtkYPadding
|
|
|
|
}
|
2014-07-16 20:30:19 -05:00
|
|
|
return d
|
|
|
|
}
|
|
|
|
|
2014-07-25 18:44:32 -05:00
|
|
|
func (c *container) translateAllocationCoords(allocations []*allocation, winwidth, winheight int) {
|
2014-07-16 20:30:19 -05:00
|
|
|
// no need for coordinate conversion with gtk+
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *widgetbase) allocate(x int, y int, width int, height int, d *sizing) []*allocation {
|
|
|
|
return []*allocation{&allocation{
|
|
|
|
x: x,
|
|
|
|
y: y,
|
|
|
|
width: width,
|
|
|
|
height: height,
|
|
|
|
this: w,
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *widgetbase) commitResize(c *allocation, d *sizing) {
|
2014-07-18 18:36:29 -05:00
|
|
|
// as we resize on size-allocate, we have to also use size-allocate on our children
|
|
|
|
// this is fine anyway; in fact, this allows us to move without knowing what the container is!
|
|
|
|
// this is what GtkBox does anyway
|
|
|
|
// thanks to tristan in irc.gimp.net/#gtk+
|
|
|
|
|
|
|
|
var r C.GtkAllocation
|
|
|
|
|
|
|
|
r.x = C.int(c.x)
|
|
|
|
r.y = C.int(c.y)
|
|
|
|
r.width = C.int(c.width)
|
|
|
|
r.height = C.int(c.height)
|
|
|
|
C.gtk_widget_size_allocate(w.widget, &r)
|
2014-07-16 20:30:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (w *widgetbase) getAuxResizeInfo(d *sizing) {
|
|
|
|
//TODO
|
|
|
|
// d.shouldVAlignTop = (s.ctype == c_listbox) || (s.ctype == c_area)
|
|
|
|
d.shouldVAlignTop = false
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 (w *widgetbase) preferredSize(d *sizing) (width int, height int) {
|
|
|
|
//TODO
|
|
|
|
/*
|
|
|
|
if s.ctype == c_area {
|
|
|
|
return s.areawidth, s.areaheight
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
var r C.GtkRequisition
|
|
|
|
|
|
|
|
C.gtk_widget_get_preferred_size(w.widget, nil, &r)
|
|
|
|
return int(r.width), int(r.height)
|
|
|
|
}
|