1
0
Fork 0
mirror of https://github.com/diamondburned/cchat-gtk.git synced 2024-11-01 20:14:16 +00:00
cchat-gtk/internal/ui/messages/container/compact/message.go

77 lines
1.9 KiB
Go
Raw Normal View History

2020-06-06 07:44:36 +00:00
package compact
import (
"github.com/diamondburned/cchat"
"github.com/diamondburned/cchat-gtk/internal/ui/messages/container"
"github.com/diamondburned/cchat-gtk/internal/ui/messages/input"
"github.com/diamondburned/cchat-gtk/internal/ui/messages/message"
"github.com/diamondburned/cchat-gtk/internal/ui/primitives"
2020-06-06 07:44:36 +00:00
"github.com/gotk3/gotk3/gtk"
"github.com/gotk3/gotk3/pango"
2020-06-06 07:44:36 +00:00
)
type PresendMessage struct {
2020-06-07 04:27:28 +00:00
message.PresendContainer
Message
2020-06-06 07:44:36 +00:00
}
func NewPresendMessage(msg input.PresendMessage) PresendMessage {
msgc := message.NewPresendContainer(msg)
attachCompact(msgc.GenericContainer)
2020-06-07 04:27:28 +00:00
2020-06-06 07:44:36 +00:00
return PresendMessage{
2020-06-07 04:27:28 +00:00
PresendContainer: msgc,
Message: Message{msgc.GenericContainer},
2020-06-06 07:44:36 +00:00
}
}
type Message struct {
*message.GenericContainer
}
var _ container.MessageRow = (*Message)(nil)
2020-06-06 07:44:36 +00:00
func NewMessage(msg cchat.MessageCreate) Message {
2020-06-07 04:27:28 +00:00
msgc := message.NewContainer(msg)
attachCompact(msgc)
2020-06-07 04:27:28 +00:00
message.FillContainer(msgc, msg)
2020-06-07 04:27:28 +00:00
return Message{msgc}
2020-06-06 07:44:36 +00:00
}
func NewEmptyMessage() Message {
ct := message.NewEmptyContainer()
attachCompact(ct)
return Message{ct}
2020-06-06 07:44:36 +00:00
}
var messageTimeCSS = primitives.PrepareClassCSS("message-time", `
.message-time {
margin-left: 1em;
margin-right: 1em;
}
`)
var messageAuthorCSS = primitives.PrepareClassCSS("message-author", `
.message-author {
margin-right: 0.5em;
}
`)
func attachCompact(container *message.GenericContainer) {
container.Timestamp.SetVAlign(gtk.ALIGN_START)
container.Username.SetMaxWidthChars(25)
container.Username.SetEllipsize(pango.ELLIPSIZE_NONE)
container.Username.SetLineWrap(true)
container.Username.SetLineWrapMode(pango.WRAP_WORD_CHAR)
messageTimeCSS(container.Timestamp)
messageAuthorCSS(container.Username)
container.PackStart(container.Timestamp, false, false, 0)
container.PackStart(container.Username, false, false, 0)
container.PackStart(container.Content, true, true, 0)
container.SetClass("compact")
2020-06-06 07:44:36 +00:00
}