Skip to content

Commit e80a837

Browse files
committed
Scoreboard refactoring.
1 parent f6d19e9 commit e80a837

File tree

1 file changed

+32
-44
lines changed

1 file changed

+32
-44
lines changed

Moblin/VideoEffects/Scoreboard/ScoreboardEffect.swift

Lines changed: 32 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,7 @@ private struct ModularScoreboardView: View {
239239
)
240240
}
241241
.frame(width: finalWidth)
242-
if modular.showGlobalStatsBlock && !activeStats.isEmpty {
243-
VStack(spacing: 0) {
244-
ForEach(0 ..< activeStats.count, id: \.self) { i in
245-
self.renderGlobalStatBox(val: activeStats[i], h: subH, modular: modular)
246-
}
247-
}
248-
.frame(width: modular.fontSize() * 3.5, height: totalH)
249-
.background(.black)
250-
}
242+
renderInfoBox(stats: activeStats, height: subH, totalHeight: totalH, modular: modular)
251243
}
252244
}
253245

@@ -379,15 +371,7 @@ private struct ModularScoreboardView: View {
379371
)
380372
}
381373
.frame(width: CGFloat(modular.width))
382-
if modular.showGlobalStatsBlock && !activeStats.isEmpty {
383-
VStack(spacing: 0) {
384-
ForEach(0 ..< activeStats.count, id: \.self) { i in
385-
self.renderGlobalStatBox(val: activeStats[i], h: subH, modular: modular)
386-
}
387-
}
388-
.frame(width: modular.fontSize() * 3.5, height: totalH)
389-
.background(.black)
390-
}
374+
renderInfoBox(stats: activeStats, height: subH, totalHeight: totalH, modular: modular)
391375
}
392376
}
393377

@@ -494,12 +478,10 @@ private struct ModularScoreboardView: View {
494478
}
495479
.background(backgroundColor)
496480
if modular.showMoreStats {
497-
renderMoreStats(
498-
team: team,
499-
fontSize: fontSize,
500-
height: height * 0.6,
501-
backgroundColor: backgroundColor
502-
)
481+
renderMoreStats(team: team,
482+
fontSize: fontSize,
483+
height: height * 0.6,
484+
backgroundColor: backgroundColor)
503485
}
504486
}
505487
.foregroundStyle(textColor)
@@ -574,13 +556,11 @@ private struct ModularScoreboardView: View {
574556
}
575557
.background(backgroundColor)
576558
if modular.showMoreStats {
577-
renderMoreStats(
578-
team: team,
579-
fontSize: fontSize,
580-
height: height * 0.6,
581-
backgroundColor: backgroundColor,
582-
alignRight: !mirrored
583-
)
559+
renderMoreStats(team: team,
560+
fontSize: fontSize,
561+
height: height * 0.6,
562+
backgroundColor: backgroundColor,
563+
alignRight: !mirrored)
584564
}
585565
}
586566
.foregroundStyle(textColor)
@@ -678,21 +658,29 @@ private struct ModularScoreboardView: View {
678658
}
679659
}
680660

681-
private func renderGlobalStatBox(val: String,
682-
h: CGFloat,
683-
modular: SettingsWidgetModularScoreboard) -> some View
661+
@ViewBuilder
662+
private func renderInfoBox(stats: [String],
663+
height: CGFloat,
664+
totalHeight: CGFloat,
665+
modular: SettingsWidgetModularScoreboard) -> some View
684666
{
685-
ZStack {
686-
Text(val)
687-
.font(.system(size: modular.fontSize() * 0.9))
688-
.bold(modular.isBold)
689-
.monospacedDigit()
690-
.minimumScaleFactor(0.1)
691-
.lineLimit(1)
667+
if modular.showGlobalStatsBlock && !stats.isEmpty {
668+
VStack(spacing: 0) {
669+
ForEach(0 ..< stats.count, id: \.self) { i in
670+
Text(stats[i])
671+
.font(.system(size: modular.fontSize() * 0.9))
672+
.bold(modular.isBold)
673+
.monospacedDigit()
674+
.minimumScaleFactor(0.1)
675+
.lineLimit(1)
676+
.frame(maxWidth: .infinity)
677+
.frame(height: height)
678+
}
679+
}
680+
.frame(width: modular.fontSize() * 3.5, height: totalHeight)
681+
.background(.black)
682+
.foregroundStyle(.white)
692683
}
693-
.frame(maxWidth: .infinity)
694-
.frame(height: h)
695-
.foregroundStyle(.white)
696684
}
697685

698686
private func renderTitleBlock(title: String, modular: SettingsWidgetModularScoreboard) -> some View {

0 commit comments

Comments
 (0)