Skip to content

Commit

Permalink
passing width correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Cufee committed Jan 20, 2025
1 parent 6fb4643 commit ce8ac5a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions internal/stats/render/session/v2/cards.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func generateCards(session, career fetch.AccountStatsOverPeriod, cards session.C
var vehicleBlockWidth = make(map[prepare.Tag]float64)
for _, card := range cards.Unrated.Vehicles {
for _, block := range card.Blocks {
labelStyle := styledVehicleLegendPill()
labelStyle := styledVehicleLegendPill(0)
label := facepaint.MeasureString(block.Label, labelStyle.Font).TotalWidth + labelStyle.PaddingLeft + labelStyle.PaddingRight
value := facepaint.MeasureString(block.Value().String(), styledVehicleCard.value(0).Font).TotalWidth
vehicleBlockWidth[block.Tag] = max(vehicleBlockWidth[block.Tag], label, value)
Expand Down Expand Up @@ -116,7 +116,7 @@ func generateCards(session, career fetch.AccountStatsOverPeriod, cards session.C
var sectionBlocks []*facepaint.Block
sectionBlocks = append(sectionBlocks, facepaint.NewBlocksContent(style.NewStyle(style.Parent(styledCardsSection)), overviewCards...))
if len(vehicleCards) > 0 {
vehicleCards = append(vehicleCards, newVehicleLegendCard(cards.Unrated.Vehicles[0]))
vehicleCards = append(vehicleCards, newVehicleLegendCard(cards.Unrated.Vehicles[0], vehicleBlockWidth))
sectionBlocks = append(sectionBlocks, facepaint.NewBlocksContent(style.NewStyle(style.Parent(styledCardsSection)), vehicleCards...))
}
statsCardsBlock := facepaint.NewBlocksContent(style.NewStyle(style.Parent(styledCardsSectionsWrapper)), sectionBlocks...)
Expand Down
3 changes: 2 additions & 1 deletion internal/stats/render/session/v2/vehicle-style.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ var styledVehicleLegendPillWrapper = style.NewStyle(style.Parent(style.Style{
Gap: 5,
}))

func styledVehicleLegendPill() *style.Style {
func styledVehicleLegendPill(width float64) *style.Style {
return &style.Style{
Debug: debugVehicleCards,

Width: width,
Color: common.TextAlt,
Font: common.FontSmall(),

Expand Down
4 changes: 2 additions & 2 deletions internal/stats/render/session/v2/vehicle.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ func newVehicleCard(data session.VehicleCard, blockWidth map[prepare.Tag]float64

}

func newVehicleLegendCard(data session.VehicleCard) *facepaint.Block {
func newVehicleLegendCard(data session.VehicleCard, blockWidth map[prepare.Tag]float64) *facepaint.Block {
var legendBlocks []*facepaint.Block
for _, block := range data.Blocks {
legendBlocks = append(legendBlocks, facepaint.MustNewTextContent(styledVehicleLegendPill().Options(), block.Label))
legendBlocks = append(legendBlocks, facepaint.MustNewTextContent(styledVehicleLegendPill(blockWidth[block.Tag]).Options(), block.Label))
}

return facepaint.NewBlocksContent(styledVehicleLegendPillWrapper,
Expand Down

0 comments on commit ce8ac5a

Please sign in to comment.