summaryrefslogtreecommitdiff
path: root/newctrl/simplegrid.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-10-17 13:08:54 -0400
committerPietro Gagliardi <[email protected]>2014-10-17 13:08:54 -0400
commit48be573b22173e09cb195ea71f55fee288481431 (patch)
tree085739f02930bf8a770c92954042e76bb09858d7 /newctrl/simplegrid.go
parentbdadfe232d16b3d6ae00f817d1c7789c768ea42f (diff)
Implemented Padded in SImpleGrid.
Diffstat (limited to 'newctrl/simplegrid.go')
-rw-r--r--newctrl/simplegrid.go39
1 files changed, 33 insertions, 6 deletions
diff --git a/newctrl/simplegrid.go b/newctrl/simplegrid.go
index 3bf6215..4d6c51d 100644
--- a/newctrl/simplegrid.go
+++ b/newctrl/simplegrid.go
@@ -26,6 +26,11 @@ type SimpleGrid interface {
// Only one control can be stretchy per SimpleGrid; calling SetStretchy multiple times merely changes which control is stretchy (preserving the previous filling value).
// It panics if the given coordinate is invalid.
SetStretchy(row int, column int)
+
+ // Padded and SetPadded get and set whether the controls of the SimpleGrid have padding between them.
+ // The size of the padding is platform-dependent.
+ Padded() bool
+ SetPadded(padded bool)
}
type simpleGrid struct {
@@ -36,6 +41,7 @@ type simpleGrid struct {
widths, heights [][]int // caches to avoid reallocating each time
rowheights, colwidths []int
container *container
+ padded bool
}
// NewSimpleGrid creates a new SimpleGrid with the given Controls.
@@ -106,6 +112,14 @@ func (g *simpleGrid) SetStretchy(row int, column int) {
g.filling[g.stretchyrow][g.stretchycol] = true
}
+func (g *simpleGrid) Padded() bool {
+ return g.padded
+}
+
+func (g *simpleGrid) SetPadded(padded bool) {
+ g.padded = padded
+}
+
func (g *simpleGrid) setParent(parent *controlParent) {
g.container.setParent(parent)
}
@@ -122,9 +136,16 @@ func (g *simpleGrid) resize(x int, y int, width int, height int, d *sizing) {
if len(g.controls) == 0 {
return
}
+ // -1) get this SimpleGrid's padding
+ xpadding := d.xpadding
+ ypadding := d.ypadding
+ if !g.padded {
+ xpadding = 0
+ ypadding = 0
+ }
// 0) inset the available rect by the needed padding and reset x/y for children
- width -= (len(g.colwidths) - 1) * d.xpadding
- height -= (len(g.rowheights) - 1) * d.ypadding
+ width -= (len(g.colwidths) - 1) * xpadding
+ height -= (len(g.rowheights) - 1) * ypadding
// TODO get the correct client rect
x = 0
y = 0
@@ -171,10 +192,10 @@ func (g *simpleGrid) resize(x int, y int, width int, height int, d *sizing) {
h = g.rowheights[row]
}
c.resize(x, y, w, h, d)
- x += g.colwidths[col] + d.xpadding
+ x += g.colwidths[col] + xpadding
}
x = startx
- y += g.rowheights[row] + d.ypadding
+ y += g.rowheights[row] + ypadding
}
}
@@ -187,8 +208,14 @@ func (g *simpleGrid) preferredSize(d *sizing) (width int, height int) {
return b
}
- width -= (len(g.colwidths) - 1) * d.xpadding
- height -= (len(g.rowheights) - 1) * d.ypadding
+ xpadding := d.xpadding
+ ypadding := d.ypadding
+ if !g.padded {
+ xpadding = 0
+ ypadding = 0
+ }
+ width -= (len(g.colwidths) - 1) * xpadding
+ height -= (len(g.rowheights) - 1) * ypadding
// 1) clear data structures
for i := range g.rowheights {
g.rowheights[i] = 0