Documentation
¶
Overview ¶
Package material provides material design building blocks for chat interfaces.
Index ¶
Constants ¶
const FailedToSend = "Sending failed"
FailedToSend is the message that is displayed to the user when there was a problem sending a chat message.
Variables ¶
var ( DefaultMaxImageHeight = unit.Dp(400) DefaultMaxMessageWidth = unit.Dp(600) DefaultAvatarSize = unit.Dp(24) DefaultDangerColor = color.NRGBA{R: 200, A: 255} )
Note: the values choosen are a best-guess heuristic, open to change.
var ErrorIcon *widget.Icon = func() *widget.Icon { icon, _ := widget.NewIcon(icons.AlertErrorOutline) return icon }()
ErrorIcon is the material design outlined error indicator.
Functions ¶
Types ¶
type BubbleStyle ¶
type BubbleStyle struct { // The radius of the corners of the surface. // Non-rounded rectangles can just provide a zero. CornerRadius unit.Dp Color color.NRGBA }
BubbleStyle defines a colored surface with (optionally) rounded corners.
func Bubble ¶
func Bubble(th *material.Theme) BubbleStyle
Bubble creates a Bubble style for the provided theme with the theme background color and rounded corners.
func (BubbleStyle) Layout ¶
func (c BubbleStyle) Layout(gtx layout.Context, w layout.Widget) layout.Dimensions
Layout renders the BubbleStyle, beneath the provided widget.
type D ¶
type D = layout.Dimensions
type Image ¶
type Image struct { widget.Image widget.Clickable // Radii specifies the amount of rounding. Radii unit.Dp // Width and Height specify respective dimensions. // If left empty, dimensions will be unconstrained. Width, Height unit.Dp }
Image lays out an image with optionally rounded corners.
type MessageStyle ¶
type MessageStyle struct { // Interaction holds the stateful parts of this message. Interaction *chatwidget.Message // MaxMessageWidth constrains the display width of the message's background. MaxMessageWidth unit.Dp // MaxImageHeight constrains the maximum height of an image message. The image // will be scaled to fit within this height. MaxImageHeight unit.Dp // ContentPadding separates the Content field from the edges of the background. ContentPadding layout.Inset // BubbleStyle configures a chat bubble beneath the message. If NinePatch is // non-nil, this field is ignored. BubbleStyle // Ninepatch provides a ninepatch stretchable image background. Only used if // non-nil. *ninepatch.NinePatch // Content is the actual styled text of the message. Content richtext.TextStyle // Image is the optional image content of the message. Image }
MessageStyle configures the presentation of a chat message.
func Message ¶
func Message(th *material.Theme, interact *chatwidget.Message, content string, img image.Image) MessageStyle
Message constructs a MessageStyle with sensible defaults.
func (MessageStyle) Layout ¶
func (m MessageStyle) Layout(gtx C) D
Layout the message atop its background.
func (MessageStyle) WithBubbleColor ¶
func (c MessageStyle) WithBubbleColor(th *material.Theme, col color.NRGBA, luminance float64) MessageStyle
WithBubbleColor sets the message bubble color and selects a contrasted text color.
func (MessageStyle) WithNinePatch ¶
func (c MessageStyle) WithNinePatch(th *material.Theme, np ninepatch.NinePatch) MessageStyle
WithNinePatch sets the message surface to a ninepatch image.
type RowConfig ¶
type RowConfig struct { Sender string Avatar image.Image Content string SentAt time.Time Image image.Image Local bool Status string }
RowConfig describes the aspects of a chat message relevant for displaying it within a widget.
type RowStyle ¶
type RowStyle struct { chatlayout.Row // Local indicates that the message was sent by the local user, // and should be right-aligned. Local bool // Time is the timestamp associated with the message. Time material.LabelStyle // StatusIcon is an optional icon that will be displayed to the right of // the message instead of its timestamp. StatusIcon *widget.Icon // StatusIconColor is the color of the status icon, if any is set. StatusIconColor color.NRGBA // IconSize defines the size of the StatusIcon (if it is set). IconSize unit.Dp // StatusMessage defines a warning message to be displayed beneath the // chat message. StatusMessage material.LabelStyle // UserInfoStyle configures how the sender's information is displayed. UserInfoStyle // MessageStyle configures how the text and its background are presented. MessageStyle // Interaction holds the interactive state of this message. Interaction *chatwidget.Row // Menu configures the right-click context menu for this message. Menu component.MenuStyle }
RowStyle configures the presentation of a chat message within a vertical list of chat messages.
type SeparatorStyle ¶
type SeparatorStyle struct { Message material.LabelStyle TextMargin layout.Inset LineMargin layout.Inset LineWidth unit.Dp }
SeparatorStyle configures the presentation of the unread indicator.
func DateSeparator ¶
func DateSeparator(th *material.Theme, date time.Time) SeparatorStyle
DateSeparator makes a SeparatorStyle with indicating the transition to the date provided in the time.Time.
func UnreadSeparator ¶
func UnreadSeparator(th *material.Theme) SeparatorStyle
UnreadSeparator fills in a SeparatorStyle with sensible defaults.
func (SeparatorStyle) Layout ¶
func (u SeparatorStyle) Layout(gtx layout.Context) layout.Dimensions
Layout the Separator.
type UserInfoStyle ¶
type UserInfoStyle struct { // Username configures the presentation of the user name text. Username material.LabelStyle // Avatar defines the image shown as the user's avatar. Avatar Image // Spacer is inserted between the username and avatar fields. layout.Spacer // Local controls the Left-to-Right ordering of layout. If false, // the Left-to-Right order will be: // - Avatar // - Spacer // - Username // If true, the order is reversed. Local bool }
UserInfoStyle defines the presentation of information about a user. It can present the user's name and avatar with a space between them.
func UserInfo ¶
func UserInfo(th *material.Theme, interact *chatwidget.UserInfo, username string, avatar image.Image) UserInfoStyle
UserInfo constructs a UserInfoStyle with sensible defaults.