Skip to content

Commit

Permalink
pot pos
Browse files Browse the repository at this point in the history
  • Loading branch information
nothub committed Mar 19, 2023
1 parent 55ad006 commit f188fa5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ func main() {

sc.Clear()

// TODO: separate base position search and pot drawing
// -a --align=INT Align tree: center=0 left=1 right=2
opts.pot.draw(sc)
px, py := opts.pot.ulPos(sc)
opts.pot.draw(sc, px, py)

// draw from pot upwards
err := drawTree(sc, opts)
Expand Down
19 changes: 9 additions & 10 deletions pot.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ type Pot struct {
d func(sc *screen, px int, py int)
}

// draw pot and set cursor to tree start pos
func (p Pot) draw(sc *screen) {
px, py := potPos(sc, p.w, p.h)
// upper left corner of pot on screen
func (p Pot) ulPos(sc *screen) (x int, y int) {
vw, vh := sc.Size()
x = (vw / 2) - (p.w / 2)
y = vh - p.h
return x, y
}

// draw pot and set cursor to tree start pos
func (p Pot) draw(sc *screen, px int, py int) {
sc.x = px
sc.y = py

Expand Down Expand Up @@ -62,10 +68,3 @@ var smallPot = Pot{
sc.draw(" (_________) ", tcell.StyleDefault)
},
}

func potPos(sc *screen, pw int, ph int) (x int, y int) {
vw, vh := sc.Size()
x = (vw / 2) - (pw / 2)
y = vh - ph
return x, y
}

0 comments on commit f188fa5

Please sign in to comment.