Skip to content

Commit ad3f535

Browse files
committed
Fix overlapping text in Generic Gauge
1 parent ed418b6 commit ad3f535

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

FlightStreamDeck.Logics/ImageLogic.cs

+10-7
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public string GetWindImage(double windDirectionInDegrees, double windVelocity, d
273273

274274
public string GetGenericGaugeImage(string text, double value, double min, double max, int? fontSize, string valueFormat, string? subValueText = null)
275275
{
276-
var font = SystemFonts.CreateFont("Arial", fontSize ?? 22, FontStyle.Regular);
276+
var valueFont = SystemFonts.CreateFont("Arial", fontSize ?? 22, FontStyle.Regular);
277277
var titleFont = SystemFonts.CreateFont("Arial", 13, FontStyle.Regular);
278278
var pen = new SolidPen(Color.DarkRed, 5);
279279
var range = max - min;
@@ -306,19 +306,22 @@ public string GetGenericGaugeImage(string text, double value, double min, double
306306

307307
ctx.DrawLine(pen, needle);
308308

309-
FontRectangle size = new FontRectangle(0, 0, 0, 0);
309+
FontRectangle titleSize = new FontRectangle(0, 0, 0, 0);
310310
if (!string.IsNullOrWhiteSpace(text))
311311
{
312-
size = TextMeasurer.MeasureSize(text, new TextOptions(titleFont));
313-
ctx.DrawText(text, titleFont, Color.White, new PointF(HALF_WIDTH - size.Width / 2, 43));
312+
titleSize = TextMeasurer.MeasureSize(text, new TextOptions(titleFont));
313+
ctx.DrawText(text, titleFont, Color.White, new PointF(HALF_WIDTH - titleSize.Width / 2, 46));
314314
}
315315

316316
var valueText = value.ToString(valueFormat);
317-
var sizeValue = TextMeasurer.MeasureSize(valueText, new TextOptions(font));
317+
var valueSize = TextMeasurer.MeasureSize(valueText, new TextOptions(valueFont));
318318
var textColor = value > max ? Color.Red : Color.White;
319-
ctx.DrawText(valueText, font, textColor, new PointF(18, 46 - sizeValue.Height));
319+
ctx.DrawText(valueText, valueFont, textColor, new PointF(18, 46 - 4 - valueSize.Height));
320320

321-
if (!string.IsNullOrWhiteSpace(subValueText)) ctx.DrawText(subValueText, titleFont, textColor, new PointF(20, 41 + size.Height));
321+
if (!string.IsNullOrWhiteSpace(subValueText))
322+
{
323+
ctx.DrawText(subValueText, titleFont, textColor, new PointF(20, 46 + 3 + titleSize.Height));
324+
}
322325
});
323326

324327
return img.ToBase64PNG();

0 commit comments

Comments
 (0)