mirror of
https://github.com/diamondburned/cchat-discord.git
synced 2024-12-23 04:46:43 +00:00
56 lines
964 B
Go
56 lines
964 B
Go
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.buf.Len(),
|
|
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 + ":"
|
|
}
|