Example #1
0
func (bf *ButtonsField) DrawInto(box box.Box, x, y int) {
	// do something to centre it.
	curX := x
	for b, butt := range bf.buttons {
		for _, ch := range butt.Text {
			curX++
			if b == bf.currentlySelected {
				box.SetCell(curX, y, ch, termbox.ColorWhite, termbox.ColorGreen)
			} else {
				box.SetCell(curX, y, ch, termbox.ColorWhite, termbox.ColorBlue)
			}
		}
		curX += 2
	}
}
Example #2
0
File: form.go Project: telyn/form
func (f *Form) DrawInto(box box.Box, offsetX, offsetY int) {
	if len(f.fields) == 0 {
		return
	}

	boxW, boxH := box.Size()

	currentY := offsetY
	for _, field := range f.fields {
		field.HandleResize(boxW-offsetX, boxH-offsetY)
	}

	// it would be nice to draw into an infinitely large box and then only copy the relevant portion.. this architecture doesn't really allow for that though
	f.ensureCurrentFieldOnScreen(boxH)

	for _, field := range f.fields[f.currentTopField:] {
		_, fieldH := field.Size()
		//log.Printf("field %d: box: %dx%d offset: (%d,%d) fieldH: %d)", i, boxW, boxH, offsetX, currentY, fieldH)
		if currentY+fieldH > boxH {
			return
		}
		field.DrawInto(box, offsetX, currentY)
		currentY += fieldH + 1
	}
}
Example #3
0
File: string.go Project: telyn/form
func DrawString(str string, box box.Box, offsetX, offsetY, width int) {
	curX := offsetX
	curY := offsetY
	str = FlowString(str, width)
	for _, ch := range str {
		switch ch {
		case '\r':
			curX = offsetX
		case '\n':
			curY++
		default:
			cell := box.GetCell(curX, curY)
			box.SetCell(curX, curY, ch, cell.Fg, cell.Bg)
			curX++
		}
	}

}
Example #4
0
func (f *LabelField) DrawInto(box box.Box, offsetX, offsetY int) {
	boxW, _ /*boxH*/ := box.Size()
	sizeX, _ /*sizeY*/ := f.Size()

	// | label field |
	if offsetX+sizeX > boxW {
		// it aint gonna fit.
		return
	}

	// -2 for spaces either side of the label, -3 for space after the innerField
	DrawString(f.label, box, offsetX+1, offsetY, boxW-offsetX-2)

	return
}
Example #5
0
func (f *LabelledField) DrawInto(box box.Box, offsetX, offsetY int) {
	boxW, _ /*boxH*/ := box.Size()
	sizeX, _ /*sizeY*/ := f.Size()
	innerWidth, _ := f.innerField.Size()

	// | label field |
	if offsetX+sizeX > boxW {
		// it aint gonna fit.
		return
	}

	// -2 for spaces either side of the label, -3 for space after the innerField
	labelWidth := (boxW - offsetX) - innerWidth - 5
	DrawString(f.label, box, offsetX+1, offsetY, labelWidth)
	f.innerField.DrawInto(box, offsetX+labelWidth+4, offsetY)

	return
}