From 98a75206bcc57df9f65337734cf59484906823e6 Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Mon, 9 Aug 2021 09:33:26 +0200 Subject: [PATCH] Add alignment to FPS control. --- play/fps.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) 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) + } }