-
Notifications
You must be signed in to change notification settings - Fork 6
/
emoji.go
135 lines (111 loc) · 2.81 KB
/
emoji.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package emojiview
import (
"github.com/diamondburned/gotk4/pkg/gtk/v4"
"github.com/diamondburned/gotk4/pkg/pango"
"github.com/diamondburned/gotkit/gtkutil/cssutil"
"github.com/diamondburned/gotktrix/internal/components/uploadutil"
"github.com/diamondburned/gotktrix/internal/gotktrix/events/emojis"
"github.com/diamondburned/gotrix/matrix"
)
type emoji struct {
*gtk.ListBoxRow
emoji *gtk.Image
name *gtk.Label
// states
mxc matrix.URL
}
var emojiCSS = cssutil.Applier("emojiview-emoji", `
.emojiview-emoji {
padding: 8px;
}
.emojiview-emoji > *:not(:first-child) {
margin-left: 8px;
}
`)
func newEmptyEmoji(name emojis.EmojiName) emoji {
img := gtk.NewImage()
img.SetSizeRequest(EmojiSize, EmojiSize)
label := gtk.NewLabel(string(name))
label.SetXAlign(0)
label.SetHExpand(true)
label.SetEllipsize(pango.EllipsizeEnd)
label.SetTooltipText(string(name))
box := gtk.NewBox(gtk.OrientationHorizontal, 0)
box.Append(img)
box.Append(label)
emojiCSS(box)
row := gtk.NewListBoxRow()
row.SetName(string(name))
row.SetChild(box)
return emoji{
ListBoxRow: row,
emoji: img,
name: label,
}
}
func (e *emoji) Rename(name emojis.EmojiName) {
e.name.SetLabel(string(name))
e.name.SetTooltipText(string(name))
e.SetName(string(name))
}
type uploadingEmoji struct {
*gtk.ListBoxRow
img *gtk.Image
name *gtk.Label
pbar *uploadutil.ProgressBar
action *gtk.Button
}
func newUploadingEmoji(name emojis.EmojiName) uploadingEmoji {
img := gtk.NewImage()
img.SetSizeRequest(EmojiSize, EmojiSize)
label := gtk.NewLabel(string(name))
label.SetEllipsize(pango.EllipsizeEnd)
label.SetTooltipText(string(name))
label.SetXAlign(0)
prog := uploadutil.NewProgressBar()
progLabel := gtk.NewBox(gtk.OrientationVertical, 0)
progLabel.SetHExpand(true)
progLabel.Append(label)
progLabel.Append(prog)
action := gtk.NewButtonFromIconName("process-stop-symbolic")
action.SetHasFrame(false)
action.SetTooltipText("Stop")
box := gtk.NewBox(gtk.OrientationHorizontal, 5)
box.Append(img)
box.Append(progLabel)
box.Append(action)
emojiCSS(box)
row := gtk.NewListBoxRow()
row.SetName(string(name))
row.SetChild(box)
return uploadingEmoji{
ListBoxRow: row,
img: img,
name: label,
pbar: prog,
action: action,
}
}
type renamingEmoji struct {
*gtk.Box
entry *gtk.Entry
name emojis.EmojiName
}
func newEmojiRenameRow(name emojis.EmojiName, emoji emoji) renamingEmoji {
img := gtk.NewImage()
img.SetSizeRequest(EmojiSize, EmojiSize)
img.SetFromPaintable(emoji.emoji.Paintable())
entry := gtk.NewEntry()
entry.SetHExpand(true)
entry.SetText(name.Name())
entry.SetInputPurpose(gtk.InputPurposeAlpha)
box := gtk.NewBox(gtk.OrientationHorizontal, 0)
box.Append(img)
box.Append(entry)
emojiCSS(box)
return renamingEmoji{
Box: box,
entry: entry,
name: name,
}
}