ui

package
v0.0.0-...-05bb6ad Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Unlicense Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// SidebarMaxWidth specifies how large the sidebar should be on
	// desktop layouts.
	SidebarMaxWidth = unit.Dp(250)
	// Breakpoint at which to switch from desktop to mobile layout.
	Breakpoint = unit.Dp(600)
)

Functions

func AddAlbumsToUi

func AddAlbumsToUi(rooms *Rooms, artMap map[string][]model.Message, channel *Room, start time.Time)

func MapDto

func MapDto(ui *UI, channels *model.Rooms, albums *model.Messages, g *gen.Generator)

Types

type CachedImage

type CachedImage struct {
	// contains filtered or unexported fields
}

CachedImage is a cacheable image operation.

func (*CachedImage) Cache

func (img *CachedImage) Cache(src image.Image) *CachedImage

Cache the image if it is not already. First call will compute the image operation, subsequent calls will noop. When reloaded, cache will re-populated on next invocation.

func (CachedImage) Op

func (img CachedImage) Op() paint.ImageOp

Op returns the concrete image operation.

func (*CachedImage) Reload

func (img *CachedImage) Reload()

Reload tells the CachedImage to repopulate the cache.

type Channel

type Channel struct {
	// ContextArea holds the clicks state for the right-click context menu.
	component.ContextArea
	widget.Clickable
	Image  CachedImage
	Active bool
}

Channel selector state.

type ChannelConfig

type ChannelConfig 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
	// Count of the latest message.
	Count string
}

ChannelConfig configures room item display.

type ChannelStyle

type ChannelStyle struct {
	*Channel
	Image     Image
	Name      material.LabelStyle
	Summary   material.LabelStyle
	Count     material.LabelStyle
	Indicator color.NRGBA
	Overlay   color.NRGBA
	// Menu configures the right-click context menu for channel.
	Menu component.MenuStyle
}

func CreateChannel

func CreateChannel(th *material.Theme, interact *Channel, menu *component.MenuState, room *ChannelConfig) ChannelStyle

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

func (ChannelStyle) Layout

func (room ChannelStyle) Layout(gtx layout.Context) 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.

func (Image) Layout

func (img Image) Layout(gtx layout.Context) layout.Dimensions

Layout the image.

type Room

type Room struct {
	// Room model defines the backend data describing a room.
	*model.Room
	// Interact defines the interactive state for a room widget.
	Interact Channel
	// RowTracker implements what would be a backend data model.
	// This would be the facade to your business api.
	// This is the source of truth.
	// This type gets asked to create messages and queried for message history.
	RowTracker *RowTracker
	// ListState dynamically manages list state.
	// This lets us surf across a vast ocean of infinite messages, only ever
	// rendering what is actually viewable.
	// The widget.List consumes this during layout.
	ListState *list.Manager
	// List implements the raw scrolling, adding scrollbars and responding
	// to mousewheel / touch fling gestures.
	List widget.List
	// Editor contains the edit buffer for composing messages.
	Editor widget.Editor
	sync.Mutex
	// searchCurSeq    int
	SearchResponses chan []list.Serial
}

Room is a unique conversation context. Note(jfm): Allocates model and interact, not sure about that. Avoids the UI needing to allocate two lists (interact/model) for the rooms.

func (*Room) ClearSync

func (r *Room) ClearSync(siteId uint32)

func (*Room) DeleteRow

func (r *Room) DeleteRow(serial list.Serial)

DeleteRow removes the row with the provided serial from both the row tracker and the list manager for the room.

func (*Room) DownloadAlbum

func (r *Room) DownloadAlbum(siteId uint32, albumId []string, trackQuality string)

func (*Room) DownloadArtist

func (r *Room) DownloadArtist(siteId uint32, artistId string, trackQuality string)

func (*Room) RunSearch

func (r *Room) RunSearch(searchText string)

func (*Room) SyncArtist

func (r *Room) SyncArtist(rooms *Rooms, siteId uint32)

type Rooms

type Rooms struct {
	List []*Room
	sync.Mutex
	// contains filtered or unexported fields
}

Rooms contains a selectable list of rooms.

func (*Rooms) Active

func (r *Rooms) Active() *Room

Active returns the active room, empty if not rooms are available.

func (*Rooms) Changed

func (r *Rooms) Changed() bool

Changed if the active room has changed since last call.

func (*Rooms) DeleteChannel

func (r *Rooms) DeleteChannel(index int, siteId uint32) []*Room

func (*Rooms) GetBaseChannel

func (r *Rooms) GetBaseChannel() *Room

func (*Rooms) GetChannelById

func (r *Rooms) GetChannelById(artistId string) *Room

func (*Rooms) Index

func (r *Rooms) Index(index int) *Room

Index returns a pointer to a Room at the given index. Index is bounded by [0, len(rooms)).

func (*Rooms) SelectAndFill

func (r *Rooms) SelectAndFill(siteId uint32, index int, albs []model.Message, invalidator func(), presentChatRow func(data list.Element, state interface{}) layout.Widget, err error)

type Row

type Row struct {
	// ContextArea holds the clicks state for the right-click context menu.
	component.ContextArea
	// Image contains the cached image op for the message.
	Avatar CachedImage
	// Message
	widget.Clickable

	Active bool
}

Row holds persistent state for a single row of a chat.

type RowConfig

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

type RowStyle

type RowStyle struct {
	*Row
	Image     Image
	Name      material.LabelStyle
	Summary   material.LabelStyle
	TimeStamp material.LabelStyle
	Indicator color.NRGBA
	Overlay   color.NRGBA
	// Menu configures the right-click context menu for this message.
	Menu component.MenuStyle
}

func NewRow

func NewRow(th *material.Theme, interact *Row, menu *component.MenuState, msg *RowConfig) RowStyle

func (RowStyle) Layout

func (row RowStyle) Layout(gtx layout.Context) layout.Dimensions

type RowTracker

type RowTracker struct {
	// SimulateLatency is the maximum latency in milliseconds to
	// simulate on loads.
	// SimulateLatency int
	sync.Mutex
	Rows          []list.Element
	SerialToIndex map[list.Serial]int
	// Users         *model.Users
	Messages *model.Messages
	// Local         *model.User
	Generator *gen.Generator
	// MaxLoads specifies the number of elements a given load in either
	// direction can return.
	MaxLoads    int
	ScrollToEnd bool
}

RowTracker is a stand-in for an application's data access logic. It stores a set of chat messages and can load them on request. It simulates network latency during the load operations for realism.

func (*RowTracker) Add

func (rt *RowTracker) Add(r list.Element)

Add a list element as a row of data to track.

func (*RowTracker) Delete

func (rt *RowTracker) Delete(serial list.Serial)

Delete removes the element with the provided serial from storage.

func (*RowTracker) Index

func (rt *RowTracker) Index(ii int) list.Element

Index returns the element at the given index, or nil.

func (*RowTracker) Latest

func (rt *RowTracker) Latest() list.Element

Latest returns the latest element, or nil.

func (*RowTracker) Load

func (rt *RowTracker) Load(dir list.Direction, relativeTo list.Serial) (loaded []list.Element, more bool)

Load simulates loading chat history from a database or API. It sleeps for a random number of milliseconds and then returns some 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

Layout the Separator.

type UI

type UI struct {
	// Loader loads resources asynchronously.
	// Deallocates stale resources.
	// Stale is defined as "not being scheduled frequently".
	async.Loader
	// Rooms is the root of the data, containing messages chunked by
	// room.
	// It also contains interact state, rather than maintaining two
	// separate lists for the model and state.
	Rooms Rooms
	// RowTracker *model.Messages
	// RoomList for the sidebar.
	RoomList widget.List
	// Back button navigates out of a room.
	Back widget.Clickable
	// InsideRoom if we are currently in the room view.
	// Used to decide when to render the sidebar on small viewports.
	InsideRoom bool
	// room menu
	SyncBtn, DownloadChannelBtn, CopyChannelBtn, DeleteBtn widget.Clickable
	// message menu
	CopyAlbBtn, CopyAlbArtistBtn, DownloadBtn widget.Clickable
	// MessageMenu is the context menu available on messages.
	MessageMenu component.MenuState
	// ChannelMenu is the context menu available on channel.
	ChannelMenu component.MenuState
	// ContextMenuTarget tracks the message state on which the context
	// menu is currently acting.
	ContextMenuTarget *model.Message

	ChannelMenuTarget *Room
	Invalidator       func()

	SiteId   uint32
	LoadSize int
	// contains filtered or unexported fields
}

UI manages the state for the entire application's UI.

func NewUI

func NewUI(invalidator func(), theme *page.Theme, loadSize int, siteId uint32) *UI

NewUI constructs a UI and populates it with data.

func (*UI) AddChannel

func (ui *UI) AddChannel(siteId uint32, artistUrl string)

func (*UI) Layout

func (ui *UI) Layout(gtx layout.Context) layout.Dimensions

Layout the application UI.

Jump to

Keyboard shortcuts

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