Example #1
0
func DrawQuestion(q string, items []string, selected int, selectedButton int) {
	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)

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

	listBox := term.NewBox()
	listBox.SetThirdSize(questionBox)
	inner = questionBox.GetInner()

	frame = listBox.GetFrame()
	frame.X = inner.X + 3
	frame.Y = inner.Y + 3
	listBox.SetFrame(frame)

	inner = listBox.GetInner()
	inner.W += 5
	listBox.SetInner(term.DrawBox(listBox, false))

	frame = listBox.GetFrame()
	frame.X += 2
	frame.Y += 2
	listBox.SetFrame(frame)

	term.DrawList(listBox, items, selected)

	frame = listBox.GetFrame()
	term.DrawButton(frame.X, frame.H+frame.Y, "OK", selectedButton == 0)
	term.DrawButton(frame.X+11, frame.H+frame.Y, "Cancel", selectedButton == 1)
}
Example #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)
		}
	}
}