Add alignment to FPS control.

This commit is contained in:
Sander Schobers 2021-08-09 09:33:26 +02:00
parent 12a9f5ee39
commit 98a75206bc

View File

@ -13,6 +13,8 @@ import (
type FPS struct { type FPS struct {
ui.ControlBase ui.ControlBase
Align ui.HorizontalAlignment
update zntg.Animation update zntg.Animation
i int i int
frames []int frames []int
@ -51,6 +53,19 @@ func (f *FPS) Render(ctx ui.Context) {
font := f.font(ctx) font := f.font(ctx)
fps := fmt.Sprintf("FPS: %d", f.total) 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)
}
} }