diff --git a/box.go b/box.go index 5780dae..5f0c181 100644 --- a/box.go +++ b/box.go @@ -25,6 +25,7 @@ type Box struct { children []Widget border bool + fill bool title string alignment Alignment @@ -86,6 +87,11 @@ func (b *Box) SetBorder(enabled bool) { b.border = enabled } +// SetFill sets whether or not the box should be filled cells of its style. +func (b *Box) SetFill(enabled bool) { + b.fill = enabled +} + // SetTitle sets the title of the box. func (b *Box) SetTitle(title string) { b.title = title @@ -121,15 +127,15 @@ func (b *Box) Draw(p *Painter) { p.WithStyle(style+".border", func(p *Painter) { p.DrawRect(0, 0, sz.X, sz.Y) }) - p.WithStyle(style, func(p *Painter) { - p.WithMask(image.Rect(0, 0, sz.X-1, 1), func(p *Painter) { - p.DrawText(1, 0, b.title) - }) + p.WithMask(image.Rect(0, 0, sz.X-1, 1), func(p *Painter) { + p.DrawText(1, 0, b.title) }) - p.FillRect(1, 1, sz.X-2, sz.Y-2) + if b.fill { + p.FillRect(1, 1, sz.X-2, sz.Y-2) + } p.Translate(1, 1) defer p.Restore() - } else { + } else if b.fill { p.FillRect(0, 0, sz.X, sz.Y) } diff --git a/box_test.go b/box_test.go index 12a04bd..f01dfc0 100644 --- a/box_test.go +++ b/box_test.go @@ -20,9 +20,9 @@ var drawBoxTests = []struct { }, want: ` ┌────────┐ -│ │ -│ │ -│ │ +│........│ +│........│ +│........│ └────────┘ `, }, @@ -35,9 +35,9 @@ var drawBoxTests = []struct { }, want: ` ┌────────┐ -│test │ -│ │ -│ │ +│test....│ +│........│ +│........│ └────────┘ `, }, @@ -50,9 +50,9 @@ var drawBoxTests = []struct { }, want: ` ┌────────┐ -│testfoo │ -│ │ -│ │ +│testfoo.│ +│........│ +│........│ └────────┘ `, }, @@ -65,9 +65,9 @@ var drawBoxTests = []struct { }, want: ` ┌────────┐ -│ │ -│ │ -│ │ +│........│ +│........│ +│........│ └────────┘ `, }, @@ -80,9 +80,9 @@ var drawBoxTests = []struct { }, want: ` ┌────────┐ -│test │ -│ │ -│ │ +│test....│ +│........│ +│........│ └────────┘ `, }, @@ -95,9 +95,9 @@ var drawBoxTests = []struct { }, want: ` ┌────────┐ -│test │ -│ │ -│foo │ +│test....│ +│........│ +│foo.....│ └────────┘ `, }, @@ -114,9 +114,9 @@ var drawBoxTests = []struct { }, want: ` ┌──────────────────────────────┐ -│ ┌────┐ │ -│ │test│ │ -│ └────┘ │ +│............┌────┐............│ +│............│test│............│ +│............└────┘............│ └──────────────────────────────┘ `, }, @@ -138,12 +138,12 @@ var drawBoxTests = []struct { want: ` ┌──────────────────────────────┐ │┌─────────────┐┌─────────────┐│ -││test ││test ││ -││ ││ ││ -││ ││ ││ -││ ││ ││ -││ ││ ││ -││ ││ ││ +││test.........││test.........││ +││.............││.............││ +││.............││.............││ +││.............││.............││ +││.............││.............││ +││.............││.............││ │└─────────────┘└─────────────┘│ └──────────────────────────────┘ `, @@ -177,22 +177,22 @@ var drawBoxTests = []struct { ┌──────────────────────────────┐ │┌────────────────────────────┐│ ││┌────────────┐┌────────────┐││ -│││test ││test │││ -│││ ││ │││ -│││ ││ │││ -│││ ││ │││ -│││ ││ │││ -│││ ││ │││ +│││test........││test........│││ +│││............││............│││ +│││............││............│││ +│││............││............│││ +│││............││............│││ +│││............││............│││ ││└────────────┘└────────────┘││ │└────────────────────────────┘│ │┌────────────────────────────┐│ ││┌────────────┐┌────────────┐││ -│││test ││test │││ -│││ ││ │││ -│││ ││ │││ -│││ ││ │││ -│││ ││ │││ -│││ ││ │││ +│││test........││test........│││ +│││............││............│││ +│││............││............│││ +│││............││............│││ +│││............││............│││ +│││............││............│││ ││└────────────┘└────────────┘││ │└────────────────────────────┘│ └──────────────────────────────┘ @@ -228,26 +228,26 @@ var drawBoxTests = []struct { want: ` ┌──────────────────────────────┐ │┌────────────────────────────┐│ -││test ││ -││testing ││ -││foo ││ -││bar ││ +││test........................││ +││testing.....................││ +││foo.........................││ +││bar.........................││ │└────────────────────────────┘│ │┌────────────────────────────┐│ -││test ││ -││testing ││ -││foo ││ -││bar ││ -││ ││ -││ ││ +││test........................││ +││testing.....................││ +││foo.........................││ +││bar.........................││ +││............................││ +││............................││ │└────────────────────────────┘│ │┌────────────────────────────┐│ -││foo ││ -││ ││ -││ ││ -││ ││ -││ ││ -││ ││ +││foo.........................││ +││............................││ +││............................││ +││............................││ +││............................││ +││............................││ │└────────────────────────────┘│ └──────────────────────────────┘ `, @@ -262,9 +262,9 @@ var drawBoxTests = []struct { }, want: ` ┌Title───┐ -│test │ -│ │ -│ │ +│test....│ +│........│ +│........│ └────────┘ `, }, @@ -278,9 +278,9 @@ var drawBoxTests = []struct { }, want: ` ┌Very lon┐ -│test │ -│ │ -│ │ +│test....│ +│........│ +│........│ └────────┘ `, }, @@ -319,7 +319,7 @@ var styleBoxTests = []struct { test: "Red horizontal box", setup: func() *Box { b := NewHBox() - b.SetBorder(true) + b.SetFill(true) return b }, theme: func() *Theme { @@ -329,13 +329,6 @@ var styleBoxTests = []struct { }) return t }, - wantContents: ` -┌────────┐ -│ │ -│ │ -│ │ -└────────┘ -`, wantColors: ` 3333333333 3333333333 @@ -352,6 +345,7 @@ var styleBoxTests = []struct { styled.SetStyleName("blue") box := NewVBox(unstyled, styled) box.SetBorder(true) + box.SetFill(true) return box }, theme: func() *Theme { @@ -390,10 +384,12 @@ var styleBoxTests = []struct { { test: "Styled box, labels inherit", setup: func() *Box { - return NewVBox( + b := NewVBox( NewLabel("label 1"), NewLabel("label 2"), ) + b.SetFill(true) + return b }, theme: func() *Theme { t := NewTheme() @@ -423,6 +419,46 @@ label 2 2222222222 2222222222 2222222222 +`, + }, + + { + test: "no fill, labels inherit", + setup: func() *Box { + b := NewVBox( + NewLabel("label 1"), + NewLabel("label 2"), + ) + return b + }, + theme: func() *Theme { + t := NewTheme() + t.SetStyle("box", Style{ + Fg: Color(3), + Bold: DecorationOn, + }) + return t + }, + wantContents: ` +label 1... +.......... +.......... +label 2... +.......... +`, + wantColors: ` +3333333... +.......... +.......... +3333333... +.......... +`, + wantDecorations: ` +2222222... +.......... +.......... +2222222... +.......... `, }, { @@ -433,6 +469,7 @@ label 2 NewLabel("label 2"), ) r.SetBorder(true) + r.SetFill(true) return r }, theme: func() *Theme { @@ -516,14 +553,14 @@ var insertWidgetTests = []struct { index: 0, want: ` ┌──────────────────┐ -│Insertion │ -│ │ -│Test 0 │ -│ │ -│Test 1 │ -│ │ -│Test 2 │ -│ │ +│Insertion.........│ +│..................│ +│Test 0............│ +│..................│ +│Test 1............│ +│..................│ +│Test 2............│ +│..................│ └──────────────────┘ `, }, @@ -532,14 +569,14 @@ var insertWidgetTests = []struct { index: 1, want: ` ┌──────────────────┐ -│Test 0 │ -│ │ -│Insertion │ -│ │ -│Test 1 │ -│ │ -│Test 2 │ -│ │ +│Test 0............│ +│..................│ +│Insertion.........│ +│..................│ +│Test 1............│ +│..................│ +│Test 2............│ +│..................│ └──────────────────┘ `, }, @@ -548,14 +585,14 @@ var insertWidgetTests = []struct { index: 5, want: ` ┌──────────────────┐ -│Test 0 │ -│ │ -│ │ -│Test 1 │ -│ │ -│ │ -│Test 2 │ -│ │ +│Test 0............│ +│..................│ +│..................│ +│Test 1............│ +│..................│ +│..................│ +│Test 2............│ +│..................│ └──────────────────┘ `, }, @@ -564,14 +601,14 @@ var insertWidgetTests = []struct { index: 3, want: ` ┌──────────────────┐ -│Test 0 │ -│ │ -│Test 1 │ -│ │ -│Test 2 │ -│ │ -│Insertion │ -│ │ +│Test 0............│ +│..................│ +│Test 1............│ +│..................│ +│Test 2............│ +│..................│ +│Insertion.........│ +│..................│ └──────────────────┘ `, }, @@ -607,14 +644,14 @@ func TestBox_Insert(t *testing.T) { func TestBox_Prepend(t *testing.T) { want := ` ┌──────────────────┐ -│Prepend │ -│ │ -│Test 0 │ -│ │ -│Test 1 │ -│ │ -│Test 2 │ -│ │ +│Prepend...........│ +│..................│ +│Test 0............│ +│..................│ +│Test 1............│ +│..................│ +│Test 2............│ +│..................│ └──────────────────┘ ` surface := NewTestSurface(20, 10) @@ -641,10 +678,10 @@ func TestBox_Prepend(t *testing.T) { func TestBox_Remove(t *testing.T) { want := ` ┌──────────────────┐ -│Test 0 │ -│ │ -│Test 2 │ -│ │ +│Test 0............│ +│..................│ +│Test 2............│ +│..................│ └──────────────────┘ ` surface := NewTestSurface(20, 6) diff --git a/cjk_test.go b/cjk_test.go index d359311..f90f857 100644 --- a/cjk_test.go +++ b/cjk_test.go @@ -48,8 +48,8 @@ var drawCJKTests = []struct { }, want: ` ┌标题────┐ -│测试 │ -│ │ +│测试....│ +│........│ └────────┘ `, }, @@ -65,7 +65,7 @@ var drawCJKTests = []struct { want: ` ┌────────┐ │テスト │ -│ │ +│........│ └────────┘ `, }, @@ -81,7 +81,7 @@ var drawCJKTests = []struct { want: ` ┌────────┐ │これはテ│ -│ │ +│........│ └────────┘ `, }, diff --git a/entry_test.go b/entry_test.go index 228dd65..75a8a40 100644 --- a/entry_test.go +++ b/entry_test.go @@ -171,8 +171,8 @@ var layoutEntryTests = []struct { want: ` ┌──────────────────┐ │ │ -│ │ -│ │ +│..................│ +│..................│ └──────────────────┘ `, }, @@ -198,8 +198,8 @@ var layoutEntryTests = []struct { want: ` ┌──────────────────┐ │456789foo456789bar│ -│ │ -│ │ +│..................│ +│..................│ └──────────────────┘ `, }, @@ -224,8 +224,8 @@ var layoutEntryTests = []struct { want: ` ┌──────────────────┐ │56789foo3456789bar│ -│ │ -│ │ +│..................│ +│..................│ └──────────────────┘ `, }, @@ -250,8 +250,8 @@ var layoutEntryTests = []struct { want: ` ┌──────────────────┐ │3456789foo56789bar│ -│ │ -│ │ +│..................│ +│..................│ └──────────────────┘ `, }, @@ -275,8 +275,8 @@ var layoutEntryTests = []struct { want: ` ┌──────────────────┐ │foo bar │ -│ │ -│ │ +│..................│ +│..................│ └──────────────────┘ `, }, @@ -299,8 +299,8 @@ var layoutEntryTests = []struct { want: ` ┌──────────────────┐ │foo bar │ -│ │ -│ │ +│..................│ +│..................│ └──────────────────┘ `, }, diff --git a/scroll_area_test.go b/scroll_area_test.go index 6e37a66..d6be126 100644 --- a/scroll_area_test.go +++ b/scroll_area_test.go @@ -24,8 +24,8 @@ var drawScrollAreaTests = []struct { return a }, want: ` -foo ...... -bar ...... +foo....... +bar....... test...... `, }, @@ -42,8 +42,8 @@ test...... return a }, want: ` -foo ...... -bar ...... +foo....... +bar....... `, }, { @@ -60,7 +60,7 @@ bar ...... return a }, want: ` -bar ...... +bar....... test...... `, }, @@ -161,8 +161,8 @@ var drawNestedScrollAreaTests = []struct { │└───────┘│ │┌───────┐│ ││└─────┘││ -││ ││ -││ ││ +││.......││ +││.......││ │└───────┘│ └─────────┘ `, @@ -194,11 +194,11 @@ var drawNestedScrollAreaTests = []struct { want: ` ┌──────────────────┐ │┌───────┐┌───────┐│ -││ ┌─││1234567││ -││ │┌││ ││ -││ ││││ ││ -││ │└││ ││ -││ └─││ ││ +││.....┌─││1234567││ +││.....│┌││.......││ +││.....││││.......││ +││.....│└││.......││ +││.....└─││.......││ │└───────┘└───────┘│ └──────────────────┘ `, diff --git a/table_test.go b/table_test.go index 16bf34d..6049069 100644 --- a/table_test.go +++ b/table_test.go @@ -33,11 +33,11 @@ var drawTableTests = []struct { ┌──────────────────────────────┐ │┌───────────┬──────────┐┌────┐│ ││ABC123 │test ││test││ -││ │ ││ ││ -│├───────────┼──────────┤│ ││ -││DEF456 │testing a ││ ││ -│├───────────┼──────────┤│ ││ -││GHI789 │foo ││ ││ +││ │ ││....││ +│├───────────┼──────────┤│....││ +││DEF456 │testing a ││....││ +│├───────────┼──────────┤│....││ +││GHI789 │foo ││....││ │└───────────┴──────────┘└────┘│ └──────────────────────────────┘ `, @@ -94,12 +94,12 @@ var drawTableTests = []struct { want: ` ┌──────────────────┐ │┌────────┬───────┐│ -││ │ ││ -││ │ ││ -││ │ ││ -││ │ ││ -││ │ ││ -││ │ ││ +││........│.......││ +││........│.......││ +││........│.......││ +││........│.......││ +││........│.......││ +││........│.......││ │└────────┴───────┘│ └──────────────────┘ `,