1
0
Fork 0
mirror of https://github.com/diamondburned/cchat-gtk.git synced 2024-11-16 19:22:51 +00:00
cchat-gtk/internal/ui/messages/container/cozy/message_collapsed.go

63 lines
1.7 KiB
Go
Raw Normal View History

2020-06-07 04:27:28 +00:00
package cozy
import (
"github.com/diamondburned/cchat-gtk/internal/ui/messages/container"
"github.com/diamondburned/cchat-gtk/internal/ui/messages/message"
"github.com/gotk3/gotk3/gtk"
)
// Collapsed is a message that follows after FullMessage. It does not show
2020-06-07 04:27:28 +00:00
// the header, and the avatar is invisible.
type CollapsedMessage struct {
// Author is still updated normally.
*message.State
2021-01-05 02:05:33 +00:00
Timestamp *gtk.Label
}
// WrapCollapsedMessage wraps the given message state to be a collapsed message.
func WrapCollapsedMessage(gc *message.State) *CollapsedMessage {
// Set Timestamp's padding accordingly to Avatar's.
2021-01-05 02:05:33 +00:00
ts := message.NewTimestamp()
ts.SetSizeRequest(AvatarSize, -1)
ts.SetVAlign(gtk.ALIGN_START)
ts.SetXAlign(0.5) // middle align
ts.SetMarginEnd(container.ColumnSpacing)
ts.SetMarginStart(container.ColumnSpacing * 2)
// Set Content's padding accordingly to FullMessage's main box.
2020-07-10 23:26:07 +00:00
gc.Content.ToWidget().SetMarginEnd(container.ColumnSpacing * 2)
2021-01-05 02:05:33 +00:00
gc.PackStart(ts, false, false, 0)
gc.PackStart(gc.Content, true, true, 0)
gc.SetClass("cozy-collapsed")
return &CollapsedMessage{
State: gc,
Timestamp: ts,
}
}
func (c *CollapsedMessage) Collapsed() bool { return true }
func (c *CollapsedMessage) Unwrap(revert bool) *message.State {
if revert {
// Remove State's widgets from the containers.
c.Remove(c.Timestamp)
c.Remove(c.Content)
}
return c.State
}
type CollapsedSendingMessage struct {
2020-06-29 02:55:13 +00:00
*CollapsedMessage
message.Presender
}
func WrapCollapsedSendingMessage(pstate *message.PresendState) *CollapsedSendingMessage {
return &CollapsedSendingMessage{
CollapsedMessage: WrapCollapsedMessage(pstate.State),
Presender: pstate,
}
2020-06-07 04:27:28 +00:00
}