Exemple #1
0
func DrawTitle(text string) {
	padding := 1
	y := 1
	term.Write(padding, y, text, term.TITLECOLOR, term.BG)
	y++
	term.Write(padding, y, term.Repeat(term.HCHAR, term.ScreenWidth()-padding*2), term.TITLECOLOR, term.BG)
}
Exemple #2
0
// Draw information text, with linesbreaks and an optional asciiart header
func DrawInformation(info, asciiart string) {

	screen := term.NewBox()

	frame := screen.GetFrame()
	frame.W = term.ScreenWidth()
	frame.H = term.ScreenHeight()
	screen.SetFrame(frame)

	inner := screen.GetInner()
	inner.X = 0
	inner.Y = 3 // This space is used by the title
	inner.W = frame.W - inner.X
	inner.H = frame.H - inner.Y
	screen.SetInner(inner)

	infoBox := term.NewBox()
	infoBox.SetThirdSize(screen)
	infoBox.FillWithPercentageMargins(screen, 0.07, 0.1)
	infoBox.SetInner(term.DrawBox(infoBox, true))

	inner = infoBox.GetInner()
	x := inner.X + 3
	y := inner.Y + 1

	y = term.DrawAsciiArt(x, y, asciiart)

	span := inner.W - 6

	from := 0
	to := span
	skew := 0
	for {
		// Word break
		skew = 0
		for testpos := 1; testpos < span; testpos++ {
			pos := to - testpos
			if pos < 0 || pos >= len(info) {
				break
			}
			if info[pos] == ' ' {
				to = to - testpos
				skew = testpos
				break
			}
		}
		// Last line?
		if (len(info) - from) < span {
			to = len(info)
		}
		// Write the line
		term.Write(x, y, info[from:to], term.TEXTCOLOR, term.BOXBG)
		// Adjust the next positions
		y++
		from += span - skew
		if from >= (len(info) - 1) {
			break
		}
		if info[from] == ' ' {
			from++
		}
		to += span
		if to >= len(info) {
			to = len(info)
		}
	}
}