From 45acb35a6d89c2e7c7d2233f3613d04253f88922 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 18 Oct 2014 08:57:53 -0400 Subject: [PATCH] Fixed control positioning on GTK+. This will also "fix" control positioning on Windows; next commit. --- newctrl/container_unix.go | 9 +++++++++ newctrl/grid.go | 2 ++ newctrl/simplegrid.go | 4 +--- newctrl/stack.go | 5 ++--- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/newctrl/container_unix.go b/newctrl/container_unix.go index 4284f21..90bc84b 100644 --- a/newctrl/container_unix.go +++ b/newctrl/container_unix.go @@ -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 diff --git a/newctrl/grid.go b/newctrl/grid.go index 78af1b4..9e68e66 100644 --- a/newctrl/grid.go +++ b/newctrl/grid.go @@ -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 diff --git a/newctrl/simplegrid.go b/newctrl/simplegrid.go index 4d6c51d..aac2586 100644 --- a/newctrl/simplegrid.go +++ b/newctrl/simplegrid.go @@ -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 diff --git a/newctrl/stack.go b/newctrl/stack.go index 164d663..f210ec8 100644 --- a/newctrl/stack.go +++ b/newctrl/stack.go @@ -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