diff --git a/README.md b/README.md index b253346..f453637 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,10 @@ Go 1.3 is required. Note that vanilla 1.3 has a bug in Mac OS X cgo; the next re prevlib.tar contains the previous version of the library as it stood when I restarted; don't bother using it. +# Updates + +**31 August 2014**
Grid is now renamed SimpleGrid in preparation for implementing a more [GtkGrid](https://developer.gnome.org/gtk3/unstable/GtkGrid.html)-like Grid. Mind the change. + # Screenshots The example widget gallery on GTK+ in the Adwaita theme (3.13/master): diff --git a/future b/future index fd40ac3..fe9a89c 100644 --- a/future +++ b/future @@ -51,7 +51,7 @@ TextField figure out numerics because you CAN paste into numeric boxes on Windows and GTK+ has no built-in number validator as far as I know will likely just use Invalid() -Stack, Grid +Stack, SimpleGrid, Grid method calls should trigger re-layout of windows default buttons figure out how they interact with Areas (especially on GTK+, where GtkEntry somehow has special handling for this) diff --git a/grid.go b/grid.go index 6a91318..142bc40 100644 --- a/grid.go +++ b/grid.go @@ -6,31 +6,31 @@ import ( "fmt" ) -// A Grid arranges Controls in a two-dimensional grid. +// A SimpleGrid arranges Controls in a two-dimensional grid. // The height of each row and the width of each column is the maximum preferred height and width (respectively) of all the controls in that row or column (respectively). // Controls are aligned to the top left corner of each cell. -// All Controls in a Grid maintain their preferred sizes by default; if a Control is marked as being "filling", it will be sized to fill its cell. +// All Controls in a SimpleGrid maintain their preferred sizes by default; if a Control is marked as being "filling", it will be sized to fill its cell. // Even if a Control is marked as filling, its preferred size is used to calculate cell sizes. -// 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). +// One Control can be marked as "stretchy": when the Window containing the SimpleGrid 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. +// All cooridnates in a SimpleGrid are given in (row,column) form with (0,0) being the top-left cell. // // As a special rule, to ensure proper appearance, non-standalone Labels are automatically made filling. -type Grid interface { +type SimpleGrid interface { Control - // SetFilling marks the given Control of the Grid as filling its cell instead of staying at its preferred size. + // SetFilling marks the given Control of the SimpleGrid as filling its cell instead of staying at its preferred size. // It panics if the given coordinate is invalid. SetFilling(row int, column int) - // SetStretchy marks the given Control of the Grid as stretchy. + // SetStretchy marks the given Control of the SimpleGrid as stretchy. // Stretchy implies filling. - // Only one control can be stretchy per Grid; calling SetStretchy multiple times merely changes which control is stretchy (preserving the previous filling value). + // 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) } -type grid struct { +type simpleGrid struct { controls [][]Control filling [][]bool stretchyrow, stretchycol int @@ -39,17 +39,17 @@ type grid struct { rowheights, colwidths []int } -// NewGrid creates a new Grid with the given Controls. -// NewGrid needs to know the number of Controls in a row (alternatively, the number of columns); it will determine the number in a column from the number of Controls given. -// NewGrid panics if not given a full grid of Controls. +// NewSimpleGrid creates a new SimpleGrid with the given Controls. +// NewSimpleGrid needs to know the number of Controls in a row (alternatively, the number of columns); it will determine the number in a column from the number of Controls given. +// NewSimpleGrid panics if not given a full grid of Controls. // Example: -// grid := NewGrid(3, +// grid := NewSimpleGrid(3, // control00, control01, control02, // control10, control11, control12, // control20, control21, control22) -func NewGrid(nPerRow int, controls ...Control) Grid { +func NewSimpleGrid(nPerRow int, controls ...Control) SimpleGrid { if len(controls)%nPerRow != 0 { - panic(fmt.Errorf("incomplete grid given to NewGrid() (not enough controls to evenly divide %d controls into rows of %d controls each)", len(controls), nPerRow)) + panic(fmt.Errorf("incomplete simpleGrid given to NewSimpleGrid() (not enough controls to evenly divide %d controls into rows of %d controls each)", len(controls), nPerRow)) } nRows := len(controls) / nPerRow cc := make([][]Control, nRows) @@ -70,7 +70,7 @@ func NewGrid(nPerRow int, controls ...Control) Grid { i++ } } - return &grid{ + return &simpleGrid{ controls: cc, filling: cf, stretchyrow: -1, @@ -82,16 +82,16 @@ func NewGrid(nPerRow int, controls ...Control) Grid { } } -func (g *grid) SetFilling(row int, column int) { +func (g *simpleGrid) SetFilling(row int, column int) { if row < 0 || column < 0 || row > len(g.filling) || column > len(g.filling[row]) { - panic(fmt.Errorf("coordinate (%d,%d) out of range passed to Grid.SetFilling()", row, column)) + panic(fmt.Errorf("coordinate (%d,%d) out of range passed to SimpleGrid.SetFilling()", row, column)) } g.filling[row][column] = true } -func (g *grid) SetStretchy(row int, column int) { +func (g *simpleGrid) SetStretchy(row int, column int) { if row < 0 || column < 0 || row > len(g.filling) || column > len(g.filling[row]) { - panic(fmt.Errorf("coordinate (%d,%d) out of range passed to Grid.SetStretchy()", row, column)) + panic(fmt.Errorf("coordinate (%d,%d) out of range passed to SimpleGrid.SetStretchy()", row, column)) } if g.stretchyrow != -1 || g.stretchycol != -1 { g.filling[g.stretchyrow][g.stretchycol] = g.stretchyfill @@ -102,7 +102,7 @@ func (g *grid) SetStretchy(row int, column int) { g.filling[g.stretchyrow][g.stretchycol] = true } -func (g *grid) setParent(parent *controlParent) { +func (g *simpleGrid) setParent(parent *controlParent) { for _, col := range g.controls { for _, c := range col { c.setParent(parent) @@ -110,7 +110,7 @@ func (g *grid) setParent(parent *controlParent) { } } -func (g *grid) allocate(x int, y int, width int, height int, d *sizing) (allocations []*allocation) { +func (g *simpleGrid) allocate(x int, y int, width int, height int, d *sizing) (allocations []*allocation) { max := func(a int, b int) int { if a > b { return a @@ -188,7 +188,7 @@ func (g *grid) allocate(x int, y int, width int, height int, d *sizing) (allocat } // filling and stretchy are ignored for preferred size calculation -func (g *grid) preferredSize(d *sizing) (width int, height int) { +func (g *simpleGrid) preferredSize(d *sizing) (width int, height int) { max := func(a int, b int) int { if a > b { return a @@ -225,10 +225,10 @@ func (g *grid) preferredSize(d *sizing) (width int, height int) { return width, height } -func (g *grid) commitResize(c *allocation, d *sizing) { +func (g *simpleGrid) commitResize(c *allocation, d *sizing) { // this is to satisfy Control; nothing to do here } -func (g *grid) getAuxResizeInfo(d *sizing) { +func (g *simpleGrid) getAuxResizeInfo(d *sizing) { // this is to satisfy Control; nothing to do here } diff --git a/stack.go b/stack.go index 0bd587a..6d9a5ce 100644 --- a/stack.go +++ b/stack.go @@ -198,7 +198,7 @@ func (s *stack) getAuxResizeInfo(d *sizing) { // // For a Stack, Space can be used to insert spaces in the beginning or middle of Stacks (Stacks by nature handle spaces at the end themselves). In order for this to work properly, make the Space stretchy. // -// For a Grid, Space can be used to have an empty cell. A stretchy Grid cell with a Space can be used to anchor the perimeter of a Grid to the respective Window edges without making one of the other controls stretchy instead (leaving empty space in the Window otherwise). Otherwise, you do not need to do anything special for the Space to work (though remember that an entire row or column of Spaces will appear as having height or width zero, respectively, unless one is marked as stretchy). +// For a SimpleGrid, Space can be used to have an empty cell. A stretchy Grid cell with a Space can be used to anchor the perimeter of a Grid to the respective Window edges without making one of the other controls stretchy instead (leaving empty space in the Window otherwise). Otherwise, you do not need to do anything special for the Space to work (though remember that an entire row or column of Spaces will appear as having height or width zero, respectively, unless one is marked as stretchy). // // The value returned from Space() may or may not be unique. func Space() Control { diff --git a/window.go b/window.go index d700d14..dc98c1f 100644 --- a/window.go +++ b/window.go @@ -3,7 +3,7 @@ package ui // Window represents a top-level window on screen that contains other Controls. -// Windows in package ui can only contain one control; the Stack and Grid layout Controls allow you to pack multiple Controls in a Window. +// Windows in package ui can only contain one control; the Stack, Grid, and SimpleGrid layout Controls allow you to pack multiple Controls in a Window. // Note that a Window is not itself a Control. type Window interface { // Title and SetTitle get and set the Window's title, respectively. diff --git a/zz_test.go b/zz_test.go index 16af837..729e253 100644 --- a/zz_test.go +++ b/zz_test.go @@ -48,7 +48,7 @@ type testwin struct { icontbl Table group2 Group group Group - grid Grid + simpleGrid SimpleGrid nt Tab a Area spw Stack @@ -171,14 +171,14 @@ func (tw *testwin) make(done chan struct{}) { tw.t.Append("Filled Group", tw.group2) tw.group = NewGroup("Group", NewVerticalStack(NewCheckbox("Checkbox in Group"))) tw.t.Append("Group", tw.group) - tw.grid = NewGrid(3, + tw.simpleGrid = NewSimpleGrid(3, NewLabel("0,0"), NewTextField(), NewLabel("0,2"), NewButton("1,0"), NewButton("1,1"), NewButton("1,2"), NewLabel("2,0"), NewTextField(), NewStandaloneLabel("2,2")) - tw.grid.SetFilling(2, 1) - tw.grid.SetFilling(1, 2) - tw.grid.SetStretchy(1, 1) - tw.t.Append("Grid", tw.grid) + tw.simpleGrid.SetFilling(2, 1) + tw.simpleGrid.SetFilling(1, 2) + tw.simpleGrid.SetStretchy(1, 1) + tw.t.Append("Simple Grid", tw.simpleGrid) tw.t.Append("Blank Tab", NewTab()) tw.nt = NewTab() tw.nt.Append("Tab 1", Space())