apptheme

package
v0.0.0-...-6dca35c Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: MIT, Unlicense Imports: 13 Imported by: 0

Documentation

Overview

Package apptheme provides domain-specific material design chat widgets.

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultMaxImageHeight  = unit.Dp(400)
	DefaultMaxMessageWidth = unit.Dp(600)
	DefaultAvatarSize      = unit.Dp(24)
)

Note: the values choosen are a best-guess heuristic, open to change.

View Source
var (
	Light = Palette{
		Error:         rgb(0xB00020),
		Surface:       rgb(0xFFFFFF),
		Bg:            rgb(0xDCDCDC),
		BgSecondary:   rgb(0xEBEBEB),
		OnError:       rgb(0xFFFFFF),
		OnSurface:     rgb(0x000000),
		OnBg:          rgb(0x000000),
		OnBgSecondary: rgb(0x000000),
	}
	Dark = Palette{
		Error:         rgb(0xB00020),
		Surface:       rgb(0x222222),
		Bg:            rgb(0x000000),
		BgSecondary:   rgb(0x444444),
		OnError:       rgb(0xFFFFFF),
		OnSurface:     rgb(0xFFFFFF),
		OnBg:          rgb(0xEEEEEE),
		OnBgSecondary: rgb(0xFFFFFF),
	}
)

Functions

func ToNRGBA

func ToNRGBA(c colorful.Color) color.NRGBA

ToNRGBA converts a colorful.Color to the nearest representable color.NRGBA.

Types

type C

type C = layout.Context

type D

type D = layout.Dimensions

type Palette

type Palette struct {
	// Error used to indicate errors.
	Error   color.NRGBA
	OnError color.NRGBA
	// Surface affect surfaces of components, such as cards, sheets and menus.
	Surface   color.NRGBA
	OnSurface color.NRGBA
	// Bg appears behind scrollable content.
	Bg   color.NRGBA
	OnBg color.NRGBA
	// BgSecondary appears behind scrollable content.
	BgSecondary   color.NRGBA
	OnBgSecondary color.NRGBA
}

Palette defines non-brand semantic colors.

`On` colors define a color that is appropriate to display atop it's counterpart.

type RoomConfig

type RoomConfig struct {
	// Name of the room as raw text.
	Name string
	// Image of the room.
	Image image.Image
	// Content of the latest message as raw text.
	Content string
	// SentAt timestamp of the latest message.
	SentAt time.Time
}

RoomConfig configures room item display.

type RoomStyle

type RoomStyle struct {
	*appwidget.Room
	Image     matchat.Image
	Name      material.LabelStyle
	Summary   material.LabelStyle
	TimeStamp material.LabelStyle
	Indicator color.NRGBA
	Overlay   color.NRGBA
}

RoomStyle lays out a room select card.

func Room

func Room(th *material.Theme, interact *appwidget.Room, room *RoomConfig) RoomStyle

Room creates a style type that can lay out the data for a room.

func (RoomStyle) Layout

func (room RoomStyle) Layout(gtx C) D

type Theme

type Theme struct {
	*material.Theme
	// UserColors tracks a mapping from chat username to the color
	// chosen to represent that user.
	UserColors map[string]UserColorData
	// AvatarSize specifies how large the avatar image should be.
	AvatarSize unit.Dp
	// Palette specifies semantic colors.
	Palette Palette
}

Theme wraps the material.Theme with useful application-specific theme information.

func NewTheme

func NewTheme(fonts []text.FontFace) *Theme

NewTheme instantiates a theme using the provided fonts.

func (*Theme) Contrast

func (t *Theme) Contrast(luminance float64) color.NRGBA

Contrast against a given luminance.

Defaults to a color that contrasts the background color, if the threshold is met, the background color itself is returned.

Note this will depend on the specific palette in question, and may not be a good generalization particularly for low-contrast palettes.

func (*Theme) LocalUserColor

func (t *Theme) LocalUserColor() UserColorData

LocalUserColor returns a color for the "local" user. Local user color is defined as the theme's surface color and it's luminance.

func (*Theme) Toggle

func (t *Theme) Toggle()

Toggle the active theme between pre-configured Light and Dark palettes.

func (*Theme) UsePalette

func (t *Theme) UsePalette(p Palette)

UsePalette changes to the specified palette.

func (*Theme) UserColor

func (t *Theme) UserColor(username string) UserColorData

UserColor returns a color for the provided username. It will choose a new color if the username is new.

type UserColorData

type UserColorData struct {
	color.NRGBA
	Luminance float64
}

UserColorData tracks both a color and its luminance.

Jump to

Keyboard shortcuts

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