borderrrrs for views

master
Jordan Orelli 4 years ago
parent 0b4ed105a9
commit 4b58ed886f

@ -0,0 +1,32 @@
package app
import (
"github.com/gdamore/tcell/v2"
"github.com/jordanorelli/astro-domu/internal/math"
)
type borderedView struct {
inner view
}
func (b borderedView) handleEvent(e tcell.Event) change {
return b.inner.handleEvent(e)
}
func (b borderedView) draw(img canvas, st *state) {
bounds := img.bounds()
img.setTile(0, 0, tile{r: '┌'})
img.setTile(bounds.Width-1, 0, tile{r: '┐'})
img.setTile(0, bounds.Height-1, tile{r: '└'})
img.setTile(bounds.Width-1, bounds.Height-1, tile{r: '┘'})
for x := 1; x < bounds.Width-1; x++ {
img.setTile(x, 0, tile{r: '─'})
img.setTile(x, bounds.Height-1, tile{r: '─'})
}
for y := 1; y < bounds.Height-1; y++ {
img.setTile(0, y, tile{r: '│'})
img.setTile(bounds.Width-1, y, tile{r: '│'})
}
b.inner.draw(cut(img, math.Rect{math.Vec{1, 1}, bounds.Width - 2, bounds.Height - 2}), st)
}

@ -33,7 +33,7 @@ func (m *menuList) handleEvent(e tcell.Event) change {
}
func (m *menuList) draw(img canvas, _ *state) {
fill(img, tcell.StyleDefault.Background(tcell.NewRGBColor(64, 32, 32)))
// fill(img, tcell.StyleDefault.Background(tcell.NewRGBColor(64, 32, 32)))
for i, choice := range m.choices {
if i == m.highlight {
writeString(img, "▷ "+choice.name, math.Vec{0, i}, tcell.StyleDefault)

@ -201,22 +201,24 @@ var inGameView = &containerView{
children: []*node{
{
frame: math.Rect{math.Vec{0, 0}, 4, 4},
view: &gameView{},
view: borderedView{&gameView{}},
},
{
frame: math.Rect{math.Vec{4, 0}, 4, 4},
view: &menuList{
choices: []menuItem{
menuItem{name: "chocolate"},
menuItem{name: "vanilla"},
menuItem{name: "strawberry"},
menuItem{name: "banana"},
view: borderedView{
&menuList{
choices: []menuItem{
menuItem{name: "chocolate"},
menuItem{name: "vanilla"},
menuItem{name: "strawberry"},
menuItem{name: "banana"},
},
},
},
},
{
frame: math.Rect{math.Vec{0, 4}, 8, 4},
view: &chatView{},
view: borderedView{inner: &chatView{}},
},
},
}

Loading…
Cancel
Save