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 {
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)
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)
}
}