diff --git a/play/fps.go b/play/fps.go index 3ea40d4..9b18593 100644 --- a/play/fps.go +++ b/play/fps.go @@ -13,6 +13,8 @@ import ( type FPS struct { ui.ControlBase + Align ui.HorizontalAlignment + update zntg.Animation i int frames []int @@ -51,6 +53,19 @@ func (f *FPS) Render(ctx ui.Context) { font := f.font(ctx) fps := fmt.Sprintf("FPS: %d", f.total) - ctx.Renderer().Text(font, geom.PtF32(5, 5), ctx.Style().Palette.Background, fps) - ctx.Renderer().Text(font, geom.PtF32(4, 4), ctx.Style().Palette.Text, fps) + + renderer := ctx.Renderer() + switch f.Align { + case ui.AlignLeft: + ctx.Renderer().Text(font, geom.PtF32(5, 5), ctx.Style().Palette.Background, fps) + ctx.Renderer().Text(font, geom.PtF32(4, 4), ctx.Style().Palette.Text, fps) + case ui.AlignCenter: + center := .5 * renderer.Size().ToF32().X + ctx.Renderer().TextAlign(font, geom.PtF32(center, 5), ctx.Style().Palette.Background, fps, ui.AlignCenter) + ctx.Renderer().TextAlign(font, geom.PtF32(center+1, 4), ctx.Style().Palette.Text, fps, ui.AlignCenter) + case ui.AlignRight: + right := renderer.Size().ToF32().X - 5 + ctx.Renderer().TextAlign(font, geom.PtF32(right, 5), ctx.Style().Palette.Background, fps, ui.AlignRight) + ctx.Renderer().TextAlign(font, geom.PtF32(right+1, 4), ctx.Style().Palette.Text, fps, ui.AlignRight) + } }