mauthor

package
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 4, 2022 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Package mauthor handles rendering Matrix room members' names.

Index

Constants

This section is empty.

Variables

View Source
var (
	// FNVHasher is the alternative hasher for color hashing.
	FNVHasher = func() hash.Hash32 { return fnv.New32a() }
	// DJB2Hasher is the string hasher used for color hashing.
	DJB2Hasher = newDJB32
)

Functions

func Markup

func Markup(c *gotktrix.Client, rID matrix.RoomID, uID matrix.UserID, mods ...MarkupMod) string

Markup renders the markup string for the given user inside the given room. The markup format follows the Pango markup format.

If the given room ID string is empty, then certain information are skipped. If it's non-empty, then the state will be used to fetch additional information.

func Name

func Name(c *gotktrix.Client, rID matrix.RoomID, uID matrix.UserID, mods ...MarkupMod) string

Name returns the raw name string with no markup.

func RGBHex

func RGBHex(c color.RGBA) string

RGBHex converts the given color to a HTML hex color string. The alpha value is ignored.

func SetDefaultColorHasher

func SetDefaultColorHasher(hasher ColorHasher)

SetDefaultColorHasher sets the default hasher that the package uses.

func Text

func Text(c *gotktrix.Client, iter *gtk.TextIter, rID matrix.RoomID, uID matrix.UserID, mods ...MarkupMod)

Text renders the author's name into a rich text buffer. Tje written string is always minimal. The inserted tags have the "_mauthor" prefix.

func UserColor

func UserColor(uID matrix.UserID, mods ...MarkupMod) string

UserColor returns the color in hexadecimal with the # prefix.

Types

type Chip

type Chip struct {
	*gtk.Box
	// contains filtered or unexported fields
}

Chip describes a user chip. It is used for display in messages and for composing messages in the composer bar.

In Material Design, chips are described as "compact elements tha represen an input, attribute, or action." People who have used Google Mail before will have seen it when they input an email address into the "To" field and having it turn into a small box showing the user information in a friendlier way instead of being an email address.

Note that due to how chips are currently implemented, it only works well at certain font scale ranges. Once the font scale is beyond ~1.3, flaws will start to be very apparent. In that case, the user should use proper graphics scaling using Wayland, not using hacks like font scaling.

func NewChip

func NewChip(ctx context.Context, room matrix.RoomID, user matrix.UserID, mods ...MarkupMod) *Chip

NewChip creates a new Chip widget.

func (*Chip) InsertText

func (c *Chip) InsertText(text *gtk.TextView, iter *gtk.TextIter) *gtk.TextChildAnchor

InsertText inserts the chip into the given TextView at the given TextIter. The inserted anchor is returned.

func (*Chip) Invalidate

func (c *Chip) Invalidate()

Invalidate invalidates the state of the chip and asks it to update the name and avatar. The NewChip constructor will automatically call this method, so the user doesn't have to.

func (*Chip) Name

func (c *Chip) Name() string

Name returns the visible name that the chip is showing.

func (*Chip) RoomID

func (c *Chip) RoomID() matrix.RoomID

RoomID returns the room ID that the chip is showing.

func (*Chip) Unpad added in v0.1.3

func (c *Chip) Unpad()

Unpad removes the negative margin in the Chip.

func (*Chip) UserID

func (c *Chip) UserID() matrix.UserID

UserID returns the user ID that the chip is showing.

type ColorHasher

type ColorHasher interface {
	Hash(name string) color.RGBA
}

ColorHasher describes a string hasher that outputs a color.

var (
	// LightColorHasher generates a pastel color name for use with a dark
	// background.
	LightColorHasher ColorHasher = HSVHasher{
		FNVHasher,
		[2]float64{0.3, 0.4},
		[2]float64{0.9, 1.0},
	}
	// DarkColorHasher generates a darker, stronger color name for use with a
	// light background.
	DarkColorHasher ColorHasher = HSVHasher{
		FNVHasher,
		[2]float64{0.9, 1.0},
		[2]float64{0.6, 0.7},
	}
)

func DefaultColorHasher

func DefaultColorHasher() ColorHasher

DefaultColorHasher returns the default color hasher.

type HSVHasher

type HSVHasher struct {
	H func() hash.Hash32 // hashing function
	S [2]float64         // saturation
	V [2]float64         // value
}

HSVHasher describes a color hasher that accepts saturation and value parameters in the HSV color space.

func (HSVHasher) Hash

func (h HSVHasher) Hash(name string) color.RGBA

Hash hashes the given name using the parameters inside HSVHasher.

type MarkupMod

type MarkupMod func(opts *markupOpts)

MarkupMod is a function type that Markup can take multiples of. It changes subtle behaviors of the Markup function, such as the color hasher used.

func WithColorHasher

func WithColorHasher(hasher ColorHasher) MarkupMod

WithColorHasher uses the given color hasher.

func WithMention

func WithMention() MarkupMod

WithMention makes the renderer prefix an at ("@") symbol.

func WithMinimal

func WithMinimal() MarkupMod

WithMinimal renders the markup without additional information, such as pronouns.

func WithName

func WithName(name string) MarkupMod

WithName overrides the name in the generated author string.

func WithShade

func WithShade() MarkupMod

WithShade renders the markup with a background shade.

func WithTextTagAttr

func WithTextTagAttr(attr textutil.TextTag) MarkupMod

WithTextTagAttr sets the given attribute into the text tag used for the author. It is only useful for Text.

func WithWidgetColor

func WithWidgetColor() MarkupMod

WithWidgetColor determines the best hasher from the given widget. The caller should beware to call this function in the main thread to not cause a race condition.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL