From f188fa5f51d5dd97bff3efbdd39ddae0ab058751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20H=C3=BCbner?= Date: Mon, 20 Mar 2023 00:15:58 +0100 Subject: [PATCH] pot pos --- main.go | 4 ++-- pot.go | 19 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/main.go b/main.go index 7792450..c619320 100644 --- a/main.go +++ b/main.go @@ -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) diff --git a/pot.go b/pot.go index 3964c92..e2e3250 100644 --- a/pot.go +++ b/pot.go @@ -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 @@ -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 -}