From 0b4ed105a94b01dd8aa13c3066e58373811cbc5b Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Mon, 9 Nov 2020 17:24:13 +0000 Subject: [PATCH] bentooo --- internal/app/container_view.go | 24 +++++++++++++++++++----- internal/app/game_view.go | 1 + internal/app/menu_list.go | 1 + internal/app/ui.go | 14 ++++++++++++++ 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/internal/app/container_view.go b/internal/app/container_view.go index f40e38b..3626f4b 100644 --- a/internal/app/container_view.go +++ b/internal/app/container_view.go @@ -33,12 +33,26 @@ func (c *containerView) draw(img canvas, st *state) { } func (c *containerView) scaleFrame(frame math.Rect, bounds math.Rect) math.Rect { - xscale := bounds.Width / c.refWidth - yscale := bounds.Height / c.refHeight + var ( + 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{ - Origin: math.Vec{xscale * frame.Origin.X, yscale * frame.Origin.Y}, - Width: xscale * frame.Width, - Height: yscale * frame.Height, + Origin: math.Vec{ + xscale*frame.Origin.X + xremTaken, + yscale*frame.Origin.Y + yremTaken, + }, + Width: xscale*frame.Width + xinflate, + Height: yscale*frame.Height + yinflate, } } diff --git a/internal/app/game_view.go b/internal/app/game_view.go index 48e8b5d..e5d3672 100644 --- a/internal/app/game_view.go +++ b/internal/app/game_view.go @@ -34,6 +34,7 @@ func (v *gameView) handleEvent(e tcell.Event) change { } func (v *gameView) draw(img canvas, st *state) { + fill(img, tcell.StyleDefault.Background(tcell.NewRGBColor(128, 128, 128))) v.drawHeader(img, st) // fill in background dots first diff --git a/internal/app/menu_list.go b/internal/app/menu_list.go index 753c16c..e9791c9 100644 --- a/internal/app/menu_list.go +++ b/internal/app/menu_list.go @@ -33,6 +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))) for i, choice := range m.choices { if i == m.highlight { writeString(img, "▷ "+choice.name, math.Vec{0, i}, tcell.StyleDefault) diff --git a/internal/app/ui.go b/internal/app/ui.go index d437b28..b4346a0 100644 --- a/internal/app/ui.go +++ b/internal/app/ui.go @@ -49,6 +49,9 @@ func (ui *UI) Run() { ui.Info("saw ctrl+c keyboard input, shutting down") return } + case *tcell.EventResize: + width, height = ui.screen.Size() + b = newBuffer(width, height) } ui.Info("input event: %v", e) wants := ui.root.handleEvent(e) @@ -200,6 +203,17 @@ var inGameView = &containerView{ frame: math.Rect{math.Vec{0, 0}, 4, 4}, 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}, view: &chatView{},