laying stuff out

master
Jordan Orelli 4 years ago
parent 19a753cf99
commit a9efc835c8

@ -21,6 +21,15 @@ func cut(img canvas, bounds math.Rect) canvas {
return &section{img: img, frame: bounds} return &section{img: img, frame: bounds}
} }
func fill(img canvas, style tcell.Style) {
bounds := img.bounds()
for x := 0; x < bounds.Width; x++ {
for y := 0; y < bounds.Height; y++ {
img.setTile(x, y, tile{r: ' ', style: style})
}
}
}
type section struct { type section struct {
img canvas img canvas
frame math.Rect frame math.Rect

@ -51,6 +51,7 @@ func (c *chatView) handleEvent(e tcell.Event) change {
func (c *chatView) draw(img canvas, st *state) { func (c *chatView) draw(img canvas, st *state) {
bounds := img.bounds() bounds := img.bounds()
fill(img, tcell.StyleDefault.Background(tcell.NewRGBColor(32, 32, 32)))
chatHeight := bounds.Height - 1 chatHeight := bounds.Height - 1
for i := 0; i < math.Min(chatHeight, len(c.history)); i++ { for i := 0; i < math.Min(chatHeight, len(c.history)); i++ {
msg := c.history[len(c.history)-1-i] msg := c.history[len(c.history)-1-i]

@ -6,8 +6,10 @@ import (
) )
type containerView struct { type containerView struct {
children []*node refWidth int
focussed int refHeight int
children []*node
focussed int
} }
func (c *containerView) handleEvent(e tcell.Event) change { func (c *containerView) handleEvent(e tcell.Event) change {
@ -23,8 +25,20 @@ func (c *containerView) handleEvent(e tcell.Event) change {
} }
func (c *containerView) draw(img canvas, st *state) { func (c *containerView) draw(img canvas, st *state) {
bounds := img.bounds()
for _, n := range c.children { for _, n := range c.children {
n.draw(cut(img, n.frame), st) n.draw(cut(img, c.scaleFrame(n.frame, bounds)), st)
}
}
func (c *containerView) scaleFrame(frame math.Rect, bounds math.Rect) math.Rect {
xscale := bounds.Width / c.refWidth
yscale := bounds.Height / c.refHeight
return math.Rect{
Origin: math.Vec{xscale * frame.Origin.X, yscale * frame.Origin.Y},
Width: xscale * frame.Width,
Height: yscale * frame.Height,
} }
} }

@ -1,7 +1,6 @@
package app package app
import ( import (
"github.com/jordanorelli/astro-domu/internal/math"
"github.com/jordanorelli/astro-domu/internal/wire" "github.com/jordanorelli/astro-domu/internal/wire"
) )
@ -38,19 +37,5 @@ func (l login) exec(ui *UI) {
// e := room.Entities[p.Avatar] // e := room.Entities[p.Avatar]
ui.state.room = &room ui.state.room = &room
ui.root = &containerView{ ui.root = inGameView
children: []*node{
{
frame: math.Rect{math.Vec{0, 0}, 20, 20},
view: &gameView{
Log: ui.Child("game-view"),
},
},
{
frame: math.Rect{math.Vec{0, 20}, 40, 20},
view: &chatView{},
},
},
}
ui.Info("done logging in, we replaced the root view whaduheck")
} }

@ -191,3 +191,18 @@ var joinForm = &form{
}, },
}, },
} }
var inGameView = &containerView{
refWidth: 8,
refHeight: 8,
children: []*node{
{
frame: math.Rect{math.Vec{0, 0}, 4, 4},
view: &gameView{},
},
{
frame: math.Rect{math.Vec{0, 4}, 8, 4},
view: &chatView{},
},
},
}

@ -30,7 +30,7 @@ func newLog(path string) *blammo.Log {
func main() { func main() {
if len(os.Args) < 2 { if len(os.Args) < 2 {
exit.WithMessage(1, "client or server?") runClient()
} }
switch os.Args[1] { switch os.Args[1] {

Loading…
Cancel
Save