Fixed control positioning on GTK+. This will also "fix" control positioning on Windows; next commit.

This commit is contained in:
Pietro Gagliardi 2014-10-18 08:57:53 -04:00
parent 772f03f4b3
commit 45acb35a6d
4 changed files with 14 additions and 6 deletions

View File

@ -50,6 +50,15 @@ func (c *container) allocation(margined bool) C.GtkAllocation {
return a
}
// we can just return these values as is
// note that allocations of a widget on GTK+ have their origin in the /window/ origin
func (c *container) bounds(d *sizing) (int, int, int, int) {
var a C.GtkAllocation
C.gtk_widget_get_allocation(c.widget, &a)
return int(a.x), int(a.y), int(a.width), int(a.height)
}
const (
gtkXMargin = 12
gtkYMargin = 12

View File

@ -205,6 +205,8 @@ func (g *grid) resize(x int, y int, width int, height int, d *sizing) {
return
}
x, y, width, height = g.container.bounds(d)
// -2) get this Grid's padding
xpadding := d.xpadding
ypadding := d.ypadding

View File

@ -136,6 +136,7 @@ func (g *simpleGrid) resize(x int, y int, width int, height int, d *sizing) {
if len(g.controls) == 0 {
return
}
x, y, width, height = g.container.bounds(d)
// -1) get this SimpleGrid's padding
xpadding := d.xpadding
ypadding := d.ypadding
@ -146,9 +147,6 @@ func (g *simpleGrid) resize(x int, y int, width int, height int, d *sizing) {
// 0) inset the available rect by the needed padding and reset x/y for children
width -= (len(g.colwidths) - 1) * xpadding
height -= (len(g.rowheights) - 1) * ypadding
// TODO get the correct client rect
x = 0
y = 0
// 1) clear data structures
for i := range g.rowheights {
g.rowheights[i] = 0

View File

@ -92,6 +92,7 @@ func (s *stack) resize(x int, y int, width int, height int, d *sizing) {
if len(s.controls) == 0 { // do nothing if there's nothing to do
return
}
x, y, width, height = s.container.bounds(d)
// -1) get this Stack's padding
xpadding := d.xpadding
ypadding := d.ypadding
@ -99,14 +100,12 @@ func (s *stack) resize(x int, y int, width int, height int, d *sizing) {
xpadding = 0
ypadding = 0
}
// 0) inset the available rect by the needed padding and reset the x/y coordinates for the children
// 0) inset the available rect by the needed padding
if s.orientation == horizontal {
width -= (len(s.controls) - 1) * xpadding
} else {
height -= (len(s.controls) - 1) * ypadding
}
x = 0
y = 0
// 1) get height and width of non-stretchy controls; figure out how much space is alloted to stretchy controls
stretchywid = width
stretchyht = height