ui

package
v0.0.0-...-69d9917 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2023 License: MIT, Unlicense Imports: 43 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// SidebarMaxWidth specifies how large the side bar should be on
	// desktop layouts.
	SidebarMaxWidth = unit.Dp(250)
	// Breakpoint at which to switch from desktop to mobile layout.
	Breakpoint = unit.Dp(600)
)
View Source
var NavBack *widget.Icon = func() *widget.Icon {
	icon, _ := widget.NewIcon(icons.NavigationArrowBack)
	return icon
}()
View Source
var Send *widget.Icon = func() *widget.Icon {
	icon, _ := widget.NewIcon(icons.ContentSend)
	return icon
}()

Functions

This section is empty.

Types

type C

type C = layout.Context

type Config

type Config struct {
	// theme to use {light,dark}.
	Theme string
	// usePlato to use plato themed widgets.
	UsePlato bool
	// latency specifies maximum latency (in millis) to simulate
	Latency int
	// loadSize specifies maximum number of items to load at a time.
	LoadSize int
	// bufferSize specifies how many elements to hold in memory before
	// compacting the list.
	BufferSize int
	// ScrollToEnd controls whether the chat interfaces start looking at the beginning
	// or end of the chat content.
	ScrollToEnd bool
}

type D

type D = layout.Dimensions

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 appwidget.Room
	// Messages 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.
	Messages *RowTracker
	// ListState dynamically manages list state.
	// This lets us surf across a vast ocean of infinite messages, only ever
	// rendering what is actualy 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
}

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) 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) Latest

func (r *Room) Latest() model.Message

Latest returns a copy of the latest message for the room.

func (*Room) NewRow

func (r *Room) NewRow()

NewRow generates a new row in the Room's RowTracker and inserts it into the list manager for the room.

func (*Room) Send

func (r *Room) Send(user, content string)

Send attempts to send arbitrary content as a message from the specified user.

func (*Room) SendLocal

func (r *Room) SendLocal(msg string)

SendLocal attempts to send the contents of the edit buffer as a to the model. All of the work of this method is dispatched in a new goroutine so that it can safely be called from layout code without blocking.

func (*Room) SetComposing

func (r *Room) SetComposing(user string, isComposing bool)

SetComposing sets the composing status for a user in this room. Note: doesn't actually verify the user pertains to this room.

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) 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) Random

func (r *Rooms) Random() *Room

Index returns a pointer to a random Room in the list.

func (*Rooms) Select

func (r *Rooms) Select(index int)

Select the room at the given index. Index is bounded by [0, len(rooms)).

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
	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 NewExampleData

func NewExampleData(users *model.Users, local *model.User, g *gen.Generator, size int) *RowTracker

NewExampleData constructs a RowTracker populated with the provided quantity of messages.

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 (r *RowTracker) Delete(serial list.Serial)

Delete removes the element with the provided serial from storage.

func (*RowTracker) Index

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

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

func (*RowTracker) Latest

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

Latest returns the latest element, or nil.

func (*RowTracker) Load

func (r *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.

func (*RowTracker) NewRow

func (r *RowTracker) NewRow() list.Element

NewRow generates a new row.

func (*RowTracker) Send

func (rt *RowTracker) Send(user, content string) model.Message

SendMessage adds the message to the data model. This is analogous to interacting with the backend api.

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
	// Local user for this client.
	Local *model.User
	// Users contains user data.
	Users *model.Users
	// RoomList for the sidebar.
	RoomList widget.List
	// Modal can show widgets atop the rest of the ui.
	Modal component.ModalState
	// Bg is the background color of the content area.
	Bg color.NRGBA
	// 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
	// AddBtn holds click state for a button that adds a new message to
	// the current room.
	AddBtn widget.Clickable
	// DeleteBtn holds click state for a button that removes a message
	// from the current room.
	DeleteBtn widget.Clickable
	// MessageMenu is the context menu available on messages.
	MessageMenu component.MenuState
	// ContextMenuTarget tracks the message state on which the context
	// menu is currently acting.
	ContextMenuTarget *model.Message
	// contains filtered or unexported fields
}

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

func NewUI

func NewUI(invalidator func(), conf Config) *UI

NewUI constructs a UI and populates it with dummy data.

func (*UI) Layout

func (ui *UI) Layout(gtx C) D

Layout the application UI.

Jump to

Keyboard shortcuts

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