Example #1
0
// 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
}
Example #2
0
func (self *Text) spaceWidth(ctx *vg.Context) float64 {
	xmin, _, xmax, _ := ctx.TextBounds(".", 0, 0)
	return xmax - xmin
}