print string adjustments

This commit is contained in:
sqshq 2019-03-14 00:28:26 -04:00
parent e68977b393
commit dcfdc16a41
1 changed files with 9 additions and 4 deletions

View File

@ -187,10 +187,11 @@ func (m *Menu) printAllDirectionsArrowSign(buffer *ui.Buffer, y int) {
} }
for i, a := range arrows { for i, a := range arrows {
buffer.SetString( printString(
a, a,
ui.NewStyle(console.ColorOlive), ui.NewStyle(console.ColorOlive),
getMiddlePoint(m.Block.Rectangle, a, i+y), getMiddlePoint(m.Block.Rectangle, a, i+y),
buffer,
) )
} }
} }
@ -213,9 +214,6 @@ func (m *Menu) renderOptions(buffer *ui.Buffer) {
offset += 2 offset += 2
point := getMiddlePoint(m.Block.Rectangle, string(option), offset-5) point := getMiddlePoint(m.Block.Rectangle, string(option), offset-5)
buffer.SetString(string(option), style, point) buffer.SetString(string(option), style, point)
//if point.In(m.GetRect()) {
// buffer.SetString(string(option), style, point)
//}
} }
} }
} }
@ -247,3 +245,10 @@ func (m *Menu) drawInnerBorder(buffer *ui.Buffer) {
func getMiddlePoint(rectangle image.Rectangle, text string, offset int) image.Point { func getMiddlePoint(rectangle image.Rectangle, text string, offset int) image.Point {
return image.Pt(rectangle.Min.X+rectangle.Dx()/2-len(text)/2, rectangle.Max.Y-rectangle.Dy()/2+offset) return image.Pt(rectangle.Min.X+rectangle.Dx()/2-len(text)/2, rectangle.Max.Y-rectangle.Dy()/2+offset)
} }
// TODO move to utils
func printString(s string, style ui.Style, p image.Point, buffer *ui.Buffer) {
for i, char := range s {
buffer.SetCell(ui.Cell{Rune: char, Style: style}, image.Pt(p.X+i, p.Y))
}
}