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}
}
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 {
img canvas
frame math.Rect

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

@ -6,8 +6,10 @@ import (
)
type containerView struct {
children []*node
focussed int
refWidth int
refHeight int
children []*node
focussed int
}
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) {
bounds := img.bounds()
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
import (
"github.com/jordanorelli/astro-domu/internal/math"
"github.com/jordanorelli/astro-domu/internal/wire"
)
@ -38,19 +37,5 @@ func (l login) exec(ui *UI) {
// e := room.Entities[p.Avatar]
ui.state.room = &room
ui.root = &containerView{
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")
ui.root = inGameView
}

@ -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() {
if len(os.Args) < 2 {
exit.WithMessage(1, "client or server?")
runClient()
}
switch os.Args[1] {

Loading…
Cancel
Save