master
Jordan Orelli 4 years ago
parent a9efc835c8
commit 0b4ed105a9

@ -33,12 +33,26 @@ func (c *containerView) draw(img canvas, st *state) {
} }
func (c *containerView) scaleFrame(frame math.Rect, bounds math.Rect) math.Rect { func (c *containerView) scaleFrame(frame math.Rect, bounds math.Rect) math.Rect {
xscale := bounds.Width / c.refWidth var (
yscale := bounds.Height / c.refHeight xscale = bounds.Width / c.refWidth
yscale = bounds.Height / c.refHeight
xrem = bounds.Width % c.refWidth
yrem = bounds.Height % c.refHeight
)
xremTaken := math.Min(frame.Origin.X, xrem)
yremTaken := math.Min(frame.Origin.Y, yrem)
xinflate := math.Max(xrem-xremTaken, 0)
yinflate := math.Max(yrem-yremTaken, 0)
return math.Rect{ return math.Rect{
Origin: math.Vec{xscale * frame.Origin.X, yscale * frame.Origin.Y}, Origin: math.Vec{
Width: xscale * frame.Width, xscale*frame.Origin.X + xremTaken,
Height: yscale * frame.Height, yscale*frame.Origin.Y + yremTaken,
},
Width: xscale*frame.Width + xinflate,
Height: yscale*frame.Height + yinflate,
} }
} }

@ -34,6 +34,7 @@ func (v *gameView) handleEvent(e tcell.Event) change {
} }
func (v *gameView) draw(img canvas, st *state) { func (v *gameView) draw(img canvas, st *state) {
fill(img, tcell.StyleDefault.Background(tcell.NewRGBColor(128, 128, 128)))
v.drawHeader(img, st) v.drawHeader(img, st)
// fill in background dots first // fill in background dots first

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

@ -49,6 +49,9 @@ func (ui *UI) Run() {
ui.Info("saw ctrl+c keyboard input, shutting down") ui.Info("saw ctrl+c keyboard input, shutting down")
return return
} }
case *tcell.EventResize:
width, height = ui.screen.Size()
b = newBuffer(width, height)
} }
ui.Info("input event: %v", e) ui.Info("input event: %v", e)
wants := ui.root.handleEvent(e) wants := ui.root.handleEvent(e)
@ -200,6 +203,17 @@ var inGameView = &containerView{
frame: math.Rect{math.Vec{0, 0}, 4, 4}, frame: math.Rect{math.Vec{0, 0}, 4, 4},
view: &gameView{}, view: &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"},
},
},
},
{ {
frame: math.Rect{math.Vec{0, 4}, 8, 4}, frame: math.Rect{math.Vec{0, 4}, 8, 4},
view: &chatView{}, view: &chatView{},

Loading…
Cancel
Save