Documentation
¶
Overview ¶
Package x holds specialised widgets built on kit and kit/ui: a log view and a lyrics view. They follow kit/ui's props-struct shape.
Index ¶
Constants ¶
const DefaultLogCap = 10000
DefaultLogCap is the capacity of a LogBuffer whose Cap is zero or negative.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type LogBuffer ¶
type LogBuffer struct {
// Cap is the most lines held; zero or negative means DefaultLogCap. It
// may change at any time and takes effect at the next Append, which
// first drops the oldest lines beyond the new capacity.
Cap int
// contains filtered or unexported fields
}
LogBuffer is a fixed-capacity ring of log lines: once full, each Append drops the oldest line. The zero value is an empty buffer of DefaultLogCap lines.
Like all app state it belongs to the UI goroutine: append from elsewhere via App.Post.
func (*LogBuffer) Append ¶
Append adds lines at the newest end, dropping the oldest lines beyond the capacity.
type LogLevel ¶
type LogLevel int
LogLevel orders log severity, lowest first. It is independent of log/slog's Level: map slog records onto these four levels when feeding a LogBuffer.
type LogLine ¶
type LogLine struct {
Time time.Time // when it was logged; zero hides the timestamp
Level LogLevel // colours the line and filters it (LogViewState.MinLevel)
Source string // optional: component, logger name
Text string // the message
}
LogLine is one log record.
type LogView ¶
type LogView struct {
ID string // the scroll region's id; the jump button is ID/jump
Buffer *LogBuffer // the lines; must not be nil
}
LogView shows Buffer: virtualized, monospace, coloured by level. It follows the tail while scrolled to the bottom; scrolling up pauses that and shows a "jump to latest" button (ID/jump). Filtering is incremental, so it stays cheap on large buffers. The scroll region's id is ID.
func (LogView) Layout ¶
func (lv LogView) Layout(gtx layout.Context, th *kit.Theme, v *LogViewState) layout.Dimensions
Layout handles the jump button, syncs the filter index and draws the view. It fills the constraints.
type LogViewState ¶
type LogViewState struct {
Filter string // case-insensitive substring of Text or Source; "" shows everything
MinLevel LogLevel // hide lines below this level
NoTime bool // hide the timestamp column
// contains filtered or unexported fields
}
LogViewState is a LogView's filter, scroll position and filter index. The filter fields are state-owned values: set them directly and the index rebuilds at the next Count or Layout. The zero value shows every line and follows the tail. A LogViewState indexes one LogBuffer; use a new state for a different buffer.
func (*LogViewState) Count ¶
func (v *LogViewState) Count(b *LogBuffer) int
Count is the number of lines of b the view shows. It syncs the filter index first, so it is safe to draw above the view (a toolbar) in the same frame.
func (*LogViewState) Following ¶
func (v *LogViewState) Following() bool
Following reports whether the view is pinned to the newest line.
func (*LogViewState) ListPos ¶
func (v *LogViewState) ListPos() layout.Position
ListPos returns the list's scroll position as of the last layout, for tests and debugging.
type LyricLine ¶
type LyricLine struct {
At time.Duration // start time from the beginning of the track
Text string // the line; "" draws an empty line
}
LyricLine starts at At and remains current until the next line starts.
type Lyrics ¶
type Lyrics struct {
ID string // the scroll region's id
Lines []LyricLine // sorted by At
At time.Duration // the playback position
}
Lyrics is a timed, scrollable line view of Lines at time At; the current line is highlighted and, while following, kept in view. The scroll region's id is ID. Lines must be sorted by At.
func (Lyrics) Layout ¶
func (ly Lyrics) Layout(gtx layout.Context, th *kit.Theme, st *LyricsState) layout.Dimensions
Layout draws the lines, scrolling to the current one when it changes while following, and turns Follow off when the listener scrolls.
type LyricsState ¶
type LyricsState struct {
List kit.List // the scroll position
Follow bool // keep the current line in view; set it to jump there
// contains filtered or unexported fields
}
LyricsState is a Lyrics' scroll position and follow mode. Follow turns off when the listener scrolls the transcript; turning it on jumps to the current line. The zero value does not follow.