fix pregnancy progress

This commit is contained in:
Gabriel Augendre 2025-01-26 12:57:52 +01:00
parent b101d53631
commit db7ef066fe

34
img.go
View file

@ -152,7 +152,7 @@ func getImg(ctx context.Context, nowFunc func() time.Time, weatherClient *weathe
drawWeather(ctx, gc, wthr) drawWeather(ctx, gc, wthr)
drawMsg(gc, msg) drawMsg(gc, msg)
drawProgress(gc, pregnancy, "Baby loading...", color.RGBA{255, 255, 255, 255}, color.RGBA{0, 0, 0, 255}) drawProgress(gc, pregnancy, "\uE774" /* baby icon */, color.RGBA{255, 255, 255, 255}, color.RGBA{0, 0, 0, 255})
return img, nil return img, nil
} }
@ -174,42 +174,26 @@ func drawMsg(gc *draw2dimg.GraphicContext, quote string) {
text(gc, quote, 15, leftX, 460, fonts.Italic) text(gc, quote, 15, leftX, 460, fonts.Italic)
} }
func drawProgress(gc *draw2dimg.GraphicContext, pct float64, msg string, white color.RGBA, black color.RGBA) { func drawProgress(gc *draw2dimg.GraphicContext, pct float64, icon string, white color.RGBA, black color.RGBA) {
const ( const (
topY = 405 topY = 400
height = 20 height = 21
width = 400 width = 400
textYOffset = 15 barLeftX = leftX + 38
textXOffset = 5 iconYOffset = 2
) )
progressWidth := width * pct / 100 progressWidth := width * pct / 100
// Draw outer rectangle // Draw outer rectangle
gc.SetFillColor(white) gc.SetFillColor(white)
gc.SetStrokeColor(black) gc.SetStrokeColor(black)
gc.BeginPath() rect(gc, barLeftX, topY, barLeftX+width, topY+height)
gc.MoveTo(leftX, topY)
gc.LineTo(leftX+width, topY)
gc.LineTo(leftX+width, topY+height)
gc.LineTo(leftX, topY+height)
gc.Close()
gc.FillStroke()
// Fill progress // Fill progress
gc.SetFillColor(black) gc.SetFillColor(black)
gc.BeginPath() rect(gc, barLeftX, topY, barLeftX+progressWidth, topY+height)
gc.MoveTo(leftX, topY) // should always be called first for a new path
gc.LineTo(leftX+progressWidth, topY)
gc.LineTo(leftX+progressWidth, topY+height)
gc.LineTo(leftX, topY+height)
gc.Close()
gc.FillStroke()
// Draw text text(gc, icon, 22, leftX, topY+height+iconYOffset, fonts.Icons)
gc.SetFillColor(white)
gc.SetFontData(draw2d.FontData{Name: fonts.Regular})
gc.SetFontSize(12)
gc.FillStringAt(msg, leftX+textXOffset, topY+textYOffset)
} }
func drawWeather(ctx context.Context, gc *draw2dimg.GraphicContext, wthr *weather.Prevision) { func drawWeather(ctx context.Context, gc *draw2dimg.GraphicContext, wthr *weather.Prevision) {