Skip to content

Document

Package presentation/ui/document renders content as a sheet of paper with a column of comments next to it, like a word processor in review mode. Page is the sheet, Editable switches a part of it between a read and an edit view, and the comments are log entries or threads of messages. On small windows the page fills the width and the comments are hidden; they need a large window.

Document

editing := core.AutoState[bool](wnd)
title := core.AutoState[string](wnd).Init(func() string { return "Service agreement" })
when := time.Date(2026, 3, 2, 9, 30, 0, 0, time.UTC)

return document.Page(
	document.Editable(
		func() core.View {
			return Text(title.Get()).Font(HeadlineMedium)
		},
		func() core.View {
			return TextField("Title", title.Get()).InputValue(title)
		},
	).InputValue(editing).FullWidth(),
	Text("This agreement describes the services which the provider renders for the customer."),
).Alignment(TopLeading).
	Size(document.Size{Width: L560, Height: L320}).
	Comment(
		document.LogEntry("Created the document", "Anna", when),
		document.LogEntry("Changed the title", "Ben", when.Add(2*time.Hour)),
	)

Size(document.DinA4) gives the page the proportions of an A4 sheet. Thread shows a discussion with the names and avatars of the users, so it needs the user management. AttachComment marks a view which belongs to a selected comment, and NewCommentDialog asks for the text of a new comment.

LogEntry always formats the time in German, e.g. 02.03.2026 um 09:30.

Constructors

ConstructorDescription
func Page(items ...core.View) TPagePage creates a kind of virtual endless DinA4 styled paper document.
func Editable(onView func() core.View, onEdit func() core.View) TEditableEditable creates a new TEditable with view and edit callbacks.
func LogEntry(message string, who string, when time.Time) TCommentLogEntry creates a simple TComment displaying a log message, the author (who), and the timestamp (when).
func Thread(wnd core.Window, messages ...Message) TCommentThread creates a TComment component that displays a list of messages (a comment thread) along with metadata such as user name, avatar, and timestamp.
func Comment(v core.View) TCommentComment wraps an arbitrary core.View as a TComment.
func AttachComment(selection *core.State[bool], v ui.DecoredView) ui.DecoredViewAttachComment decorates a view with a comment marker if selected.
func NewCommentDialog(presented *core.State[bool], addComment func(text string)) core.ViewShows a modal dialog which asks for the text of a new comment.

Methods

TPage:

MethodDescription
Alignment(alignment ui.Alignment) TPageAlignment sets how child elements inside the page are aligned (leading, trailing, center, stretch, etc.).
Append(items ...core.View) TPageAppend adds one or more UI views to the page’s main content items.
BackgroundColor(color ui.Color) TPageBackgroundColor sets the background color of the page.
Border(border ui.Border) TPageBorder applies a border style (width, radius, color, etc.) to the page.
Comment(comments ...TComment) TPageComment appends the given comments to any already existing comments.
Frame(frame ui.Frame) TPageFrame directly sets the frame (size and layout constraints) of the page.
Size(size Size) TPageSize sets the page size to fixed width and height constraints.

TEditable:

MethodDescription
Alignment(alignment ui.Alignment) TEditableAlignment sets the alignment of the editable component.
BackgroundColor(color ui.Color) TEditableBackgroundColor sets the background color of the editable component.
Border(border ui.Border) TEditableBorder sets the border of the editable component.
Comment(action func()) TEditableComment sets the callback executed when a comment action is triggered.
Frame(frame ui.Frame) TEditableFrame sets the frame (size and layout) of the editable component.
FullWidth() TEditableSets the width to the full available width.
InputValue(editPresented *core.State[bool]) TEditableInputValue sets the edit presented state.
Style(style ToggleStyle) TEditableStyle sets the toggle style of the editable component: TopTrailing (default), InlineTrailing or Clickable.

TComment:

MethodDescription
InputSelectedValue(selected *core.State[bool]) TCommentInputSelectedValue binds the comment’s selected state.
InputValue(comment *core.State[string]) TCommentInputValue binds the comment’s text state.
Resolve(action func()) TCommentResolve sets a callback to mark the comment thread as resolved.

Related