Пример #1
0
Файл: form.go Проект: 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
	}
}
Пример #2
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
}
Пример #3
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
}