This repository has been archived by the owner on Apr 5, 2022. It is now read-only.
/
guildinfo.go
93 lines (75 loc) · 1.92 KB
/
guildinfo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package overview
import (
"fmt"
"html"
"strconv"
"github.com/diamondburned/arikawa/v2/discord"
"github.com/diamondburned/gotk4/pkg/gtk/v3"
"github.com/diamondburned/gtkcord3/gtkcord/cache"
"github.com/diamondburned/gtkcord3/gtkcord/components/roundimage"
"github.com/diamondburned/gtkcord3/gtkcord/gtkutils"
)
const GuildIconSize = 96
type GuildInfo struct {
*gtk.Box
// rounded
Image *roundimage.Image
// top guild name, bottom nitro info
Info *gtk.Box
Name *gtk.Label
Extra *gtk.Label // nillable
}
func NewGuildInfo(guild *discord.Guild) *GuildInfo {
box := gtk.NewBox(gtk.OrientationHorizontal, 0)
box.Show()
img := roundimage.NewImage(0)
img.SetSizeRequest(GuildIconSize, GuildIconSize)
img.SetFromIconName("network-server-symbolic", 0)
img.SetPixelSize(GuildIconSize)
gtkutils.Margin(img, CommonMargin)
img.Show()
info := gtk.NewBox(gtk.OrientationVertical, 0)
info.Show()
name := gtk.NewLabel(
`<span weight="bold" size="xx-large">` + html.EscapeString(guild.Name) + `</span>`)
name.Show()
name.SetUseMarkup(true)
name.SetVExpand(true)
name.SetVAlign(gtk.AlignEnd)
name.SetHAlign(gtk.AlignStart)
var lvl string
switch guild.NitroBoost {
case discord.NitroLevel1:
lvl = "Nitro Level 1"
case discord.NitroLevel2:
lvl = "Nitro Level 2"
case discord.NitroLevel3:
lvl = "Nitro Level 3"
default:
lvl = "-"
}
extra := gtk.NewLabel(`<span color="#ff73fa">` + lvl + `</span>`)
extra.Show()
extra.SetUseMarkup(true)
extra.SetVExpand(true)
extra.SetVAlign(gtk.AlignStart)
extra.SetHAlign(gtk.AlignStart)
box.Add(img)
box.Add(info)
info.Add(name)
info.Add(extra)
if guild.Icon != "" {
url := fmt.Sprintf("%s?size=%d", guild.IconURL(), 256)
cache.SetImageURLScaled(img, url, GuildIconSize, GuildIconSize)
}
return &GuildInfo{
box,
img,
info,
name,
extra,
}
}
func sizeToURL(url string, w, h int) string {
return url + "?width=" + strconv.Itoa(w) + "&height=" + strconv.Itoa(h)
}