Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2 (Please be gentle).
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

appview/repo: wrap long repo names in og card

Signed-off-by: Anirudh Oppiliappan <anirudh@tangled.org>

+54 -28
+54 -28
appview/repo/opengraph.go
··· 35 35 // Split content horizontally: main content (80%) and avatar area (20%) 36 36 mainContent, avatarArea := contentCard.Split(true, 80) 37 37 38 - // Split main content: 50% for name/description, 50% for spacing 39 - topSection, _ := mainContent.Split(false, 50) 38 + // Use main content area for both repo name and description to allow dynamic wrapping. 39 + mainContent.SetMargin(10) 40 40 41 - // Split top section: 40% for repo name, 60% for description 42 - repoNameCard, descriptionCard := topSection.Split(false, 50) 43 - 44 - // Draw repo name with owner in regular and repo name in bold 45 - repoNameCard.SetMargin(10) 46 41 var ownerHandle string 47 42 owner, err := rp.idResolver.ResolveIdent(context.Background(), repo.Did) 48 43 if err != nil { ··· 46 51 ownerHandle = "@" + owner.Handle.String() 47 52 } 48 53 49 - // Draw repo name with wrapping support 50 - repoNameCard.SetMargin(10) 51 - bounds := repoNameCard.Img.Bounds() 52 - startX := bounds.Min.X + repoNameCard.Margin 53 - startY := bounds.Min.Y + repoNameCard.Margin 54 + bounds := mainContent.Img.Bounds() 55 + startX := bounds.Min.X + mainContent.Margin 56 + startY := bounds.Min.Y + mainContent.Margin 54 57 currentX := startX 58 + currentY := startY 59 + lineHeight := 64 // Font size 54 + padding 55 60 textColor := color.RGBA{88, 96, 105, 255} 56 61 57 - // Draw owner handle in gray 58 - ownerWidth, err := repoNameCard.DrawTextAtWithWidth(ownerHandle, currentX, startY, textColor, 54, ogcard.Top, ogcard.Left) 62 + // Draw owner handle 63 + ownerWidth, err := mainContent.DrawTextAtWithWidth(ownerHandle, currentX, currentY, textColor, 54, ogcard.Top, ogcard.Left) 59 64 if err != nil { 60 65 return nil, err 61 66 } 62 67 currentX += ownerWidth 63 68 64 69 // Draw separator 65 - sepWidth, err := repoNameCard.DrawTextAtWithWidth(" / ", currentX, startY, textColor, 54, ogcard.Top, ogcard.Left) 70 + sepWidth, err := mainContent.DrawTextAtWithWidth(" / ", currentX, currentY, textColor, 54, ogcard.Top, ogcard.Left) 66 71 if err != nil { 67 72 return nil, err 68 73 } 69 74 currentX += sepWidth 70 75 71 - // Draw repo name in bold 72 - _, err = repoNameCard.DrawBoldText(repo.Name, currentX, startY, color.Black, 54, ogcard.Top, ogcard.Left) 73 - if err != nil { 74 - return nil, err 76 + words := strings.Fields(repo.Name) 77 + spaceWidth, _ := mainContent.DrawTextAtWithWidth(" ", -1000, -1000, color.Black, 54, ogcard.Top, ogcard.Left) 78 + if spaceWidth == 0 { 79 + spaceWidth = 15 75 80 } 76 81 77 - // Draw description (DrawText handles multi-line wrapping automatically) 78 - descriptionCard.SetMargin(10) 79 - description := repo.Description 80 - if len(description) > 70 { 81 - description = description[:70] + "…" 82 + for _, word := range words { 83 + // estimate bold width by measuring regular width and adding a multiplier 84 + regularWidth, _ := mainContent.DrawTextAtWithWidth(word, -1000, -1000, color.Black, 54, ogcard.Top, ogcard.Left) 85 + estimatedBoldWidth := int(float64(regularWidth) * 1.15) // Heuristic for bold text 86 + 87 + if currentX+estimatedBoldWidth > (bounds.Max.X - mainContent.Margin) { 88 + currentX = startX 89 + currentY += lineHeight 90 + } 91 + 92 + _, err := mainContent.DrawBoldText(word, currentX, currentY, color.Black, 54, ogcard.Top, ogcard.Left) 93 + if err != nil { 94 + return nil, err 95 + } 96 + currentX += estimatedBoldWidth + spaceWidth 82 97 } 83 98 84 - _, err = descriptionCard.DrawText(description, color.RGBA{88, 96, 105, 255}, 36, ogcard.Top, ogcard.Left) 85 - if err != nil { 86 - log.Printf("failed to draw description: %v", err) 87 - return nil, err 99 + // update Y position for the description 100 + currentY += lineHeight 101 + 102 + // draw description 103 + if currentY < bounds.Max.Y-mainContent.Margin { 104 + totalHeight := float64(bounds.Dy()) 105 + repoNameHeight := float64(currentY - bounds.Min.Y) 106 + 107 + if totalHeight > 0 && repoNameHeight < totalHeight { 108 + repoNamePercent := (repoNameHeight / totalHeight) * 100 109 + if repoNamePercent < 95 { // Ensure there's space left for description 110 + _, descriptionCard := mainContent.Split(false, int(repoNamePercent)) 111 + descriptionCard.SetMargin(8) 112 + 113 + description := repo.Description 114 + if len(description) > 70 { 115 + description = description[:70] + "…" 116 + } 117 + 118 + _, err = descriptionCard.DrawText(description, color.RGBA{88, 96, 105, 255}, 36, ogcard.Top, ogcard.Left) 119 + if err != nil { 120 + log.Printf("failed to draw description: %v", err) 121 + } 122 + } 123 + } 88 124 } 89 125 90 126 // Draw avatar circle on the right side