예제 #1
0
파일: text.go 프로젝트: xormplus/ui-1
// tokenSize retrieves the metrics from the internal cache, sizes.
// It is expensive to calculate the token sizes each frame and the
// sizes do not change often to justify the cost.  Testing revealed
// this approach yields a slower rate of growth.
//
// TODO: maybe choose to disable cpu scaling for better performance
//         > echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
//       or
//         > sudo update-rc.d ondemand disable
func (self *Text) tokenBounds(i int, ctx *vg.Context) *ui.Rectangle {
	bounds := self.bounds[i]
	if bounds == nil {
		x, y, w, h := ctx.TextBounds(self.tokens[i], 0, 0)

		bounds = &ui.Rectangle{ui.Position{x, y}, ui.Size{w, h}}
		self.bounds[i] = bounds
	}
	return bounds
}
예제 #2
0
파일: text.go 프로젝트: xormplus/ui-1
func (self *Text) spaceWidth(ctx *vg.Context) float64 {
	xmin, _, xmax, _ := ctx.TextBounds(".", 0, 0)
	return xmax - xmin
}