summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--futureplans.md3
-rw-r--r--grid.go15
2 files changed, 11 insertions, 7 deletions
diff --git a/futureplans.md b/futureplans.md
index acc3f55..168858b 100644
--- a/futureplans.md
+++ b/futureplans.md
@@ -5,6 +5,9 @@ general list:
- LineEdit.Typing
- LineEdit.Finished? or will that be a property of dialog boxes?
- Listbox.Selected
+- Grid niceness
+ - ability to have controls span rows and columns
+ - ability to horizontally or vertically align controls within their cells
- Window.SizeToFit() or WIndow.OptimalSize() (use: `Window.SetOptimalSize())`) for sizing a window to the control's interest
- with the current code, will be a bit of a kludge, because preferredSize() assumes it's running on the main thread without locks
- Control.Show()/Control.Hide()
diff --git a/grid.go b/grid.go
index 51cec37..b54aafe 100644
--- a/grid.go
+++ b/grid.go
@@ -15,8 +15,6 @@ import (
// One Control can be marked as "stretchy": when the Window containing the Grid is resized, the cell containing that Control resizes to take any remaining space; its row and column are adjusted accordingly (so other filling controls in the same row and column will fill to the new height and width, respectively).
// A stretchy Control implicitly fills its cell.
// All cooridnates in a Grid are given in (row,column) form with (0,0) being the top-left cell.
-// Unlike other UI toolkit Grids, this Grid does not (yet? TODO) allow Controls to span multiple rows or columns.
-// TODO differnet row/column control alignment
type Grid struct {
lock sync.Mutex
created bool
@@ -100,14 +98,20 @@ func (g *Grid) SetStretchy(row int, column int) {
}
g.stretchyrow = row
g.stretchycol = column
- // TODO if a stretchy row/column already exists, its filling value will not be reverted if necessary
- g.filling[row][column] = true
+ // don't set filling here in case we call SetStretchy() multiple times; the filling is committed in make() below
}
func (g *Grid) make(window *sysData) error {
g.lock.Lock()
defer g.lock.Unlock()
+ // commit filling for the stretchy control now (see SetStretchy() above)
+ if g.stretchyrow != -1 && g.stretchycol != -1 {
+ g.filling[g.stretchyrow][g.stretchycol] = true
+ } else if (g.stretchyrow == -1 && g.stretchycol != -1) || // sanity check
+ (g.stretchyrow != -1 && g.stretchycol == -1) {
+ panic(fmt.Errorf("internal inconsistency in Grid: stretchy (%d,%d) impossible (one component, not both, is -1/no stretchy control) in Grid.make()", g.stretchyrow, g.stretchycol))
+ }
for row, xcol := range g.controls {
for col, c := range xcol {
err := c.make(window)
@@ -159,9 +163,6 @@ func (g *Grid) setRect(x int, y int, width int, height int, rr *[]resizerequest)
}
g.colwidths[g.stretchycol] = width
g.rowheights[g.stretchyrow] = height
- } else if (g.stretchyrow == -1 && g.stretchycol != -1) || // sanity check
- (g.stretchyrow != -1 && g.stretchycol == -1) {
- panic(fmt.Errorf("internal inconsistency in Grid: stretchy (%d,%d) impossible (one component, not both, is -1/no stretchy control)", g.stretchyrow, g.stretchycol))
}
// 4) draw
startx := x