1
0
Fork 0
mirror of https://github.com/diamondburned/cchat-discord.git synced 2024-11-01 12:24:15 +00:00
cchat-discord/segments/emoji.go

56 lines
958 B
Go
Raw Normal View History

2020-06-19 01:00:24 +00:00
package segments
import (
"github.com/diamondburned/cchat/text"
"github.com/diamondburned/ningen/md"
"github.com/yuin/goldmark/ast"
)
const (
InlineEmojiSize = 22
LargeEmojiSize = 48
)
type EmojiSegment struct {
start int
name string
emojiURL string
large bool
}
var _ text.Imager = (*EmojiSegment)(nil)
func (r *TextRenderer) emoji(n *md.Emoji, enter bool) ast.WalkStatus {
if enter {
r.append(EmojiSegment{
start: r.i(),
name: n.Name,
large: n.Large,
emojiURL: n.EmojiURL() + "&size=64",
})
}
return ast.WalkContinue
}
func (e EmojiSegment) Bounds() (start, end int) {
return e.start, e.start
}
func (e EmojiSegment) Image() string {
return e.emojiURL
}
// TODO: large emoji
func (e EmojiSegment) ImageSize() (w, h int) {
if e.large {
return LargeEmojiSize, LargeEmojiSize
}
return InlineEmojiSize, InlineEmojiSize
}
func (e EmojiSegment) ImageText() string {
return ":" + e.name + ":"
}