AccordionHeaderExtent#
func AccordionHeaderExtent(theme ui.Theme) float32AccordionHeaderExtent is the height of one item's header row, for a caller that reserves room for an accordion in a layout before painting it.
Package components contains source-oriented UI recipes built from ui primitives.
Import path: import "github.com/vivaui/viva/components"
Package components contains source-oriented UI recipes built from ui primitives.
Every recipe is a plain Go value: one component per file, no runtime registry, no reflection, no package init, no hidden workers. Linkage is pay-for-what-you-use — the linker keeps only the functions an application actually calls, and a blank import of this whole package links no symbol of github.com/vivaui/viva/components (linkage_test.go builds that program and checks); the standard-library packages and github.com/vivaui/viva/ui it imports add a fixed baseline that is measured separately. Each file is both the implementation and the documentation: colors, geometry, metrics, and state rendering are visible in the source, so a reader (human or model) can understand the full behavior from that file alone.
Components are stateless immediate declarations over a shared ui.Canvas. A Begin constructor returns a small chainable value whose terminal method paints; the application owns all state and re-declares on repaint:
BeginButton(canvas, theme, id, bounds).Default("Save")Hit declaration, hover/press/focus feedback, focus rings, and semantic labels are built into each recipe. Keep hit IDs as explicit literals in disjoint ranges and stable across paints so retained scenes, focus, and accessibility targets stay stable.
Editing components (input, textarea, OTP, combobox) render caller-owned snapshots such as InputSnapshot: value, caret, selection, and IME composition offsets go in, painted glyphs come out. Editing state itself lives in the application, typically driven by an editor from github.com/vivaui/viva/text.
Two levels, in order. Chain knobs (Height, Tint, Disabled, SizeToFit, and friends) cover common adjustments without leaving the package. For deeper change the file is the framework — install a copy into the application module and edit it freely:
viva add buttonInstalled sources are the primary customization path, and every file of this package is a recipe: viva list prints their names. A recipe that calls into another file (a shared color helper, a menu surface) is installed together with it. The installable copies are generated from these files by tools/componentgen, so they cannot drift; go generate ./cmd/viva refreshes them after a component changes. An installed copy stops receiving fixes made here, so import the package until a recipe needs more than its knobs.
Multi-selection:
MultiSelect: `PaintMultiSelect` combines removable chips, a native query input and a filtered popup. `MultiSelectState` handles multi-selection, optional item creation, limits and keyboard/IME-safe confirmation. Bind its Query editor to the application's text-input provider.
Actions:
Button: `BeginButton` paints a labeled control with Default, Secondary, Outline, and Ghost variants; hover, press, and focus states, metrics- scaled geometry, and the hit declaration are built in.
Button row: `BeginButtonRow` lays small buttons out against the right edge of a footer, each as wide as its label, shrinking together when they do not fit.
Button group: `BeginButtonGroup` joins a row of buttons into one bordered control.
Toggle: `BeginToggle` paints a two-state icon button.
Toggle group: `BeginToggleGroup` paints a set of selectable toggles; `ToggleGroupKeyDown` wires arrow-key movement.
Segmented control: `BeginSegmentedControl` paints a compact single-select strip; `SegmentedControlKeyDown` wires arrow keys.
Switch: `BeginSwitch` paints the on/off track and knob.
Checkbox: `BeginCheckbox` paints the checked/unchecked box and check mark.
Color picker: `BeginColorPicker` paints an anchored HSV panel, optional alpha slider, caller-owned HEX input, and clear/cancel/apply actions. `ColorPickerLayout.Pointer` and `ColorPickerLayout.Key` update HSV drafts.
Color swatch: `BeginColorSwatch` paints a named circular color choice, with selection, focus and disabled states and a no-color option.
Radio group: `BeginRadioGroup` paints single-select labeled options; `RadioGroupKeyDown` wires arrow keys.
Slider: `BeginSlider` paints one draggable thumb; `BeginRangeSlider` paints several.
Inputs:
Input: `PaintInput` paints the single-line editor recipe from an InputSnapshot, including caret, selection, placeholder, and IME composition.
Textarea: `PaintTextarea` paints the multi-line editor recipe, wrapping long lines; `TextareaCommandForKey` maps key events to editor commands, and `TextareaMovementForKey` with a `TextareaLayout` moves the caret by visual row (arrows, Home, End, Page keys), scrolls to it, places it on a click and sizes a box that grows with its text.
Code editor: `CodeEditor` adds caller-provided syntax colors and a draggable scrollbar to TextareaLayout, retaining native selection and IME geometry.
Image preview: `PaintImageView` clips an immutable bitmap with fit, zoom and pan; actual size maps one bitmap pixel to one device pixel at any DPI.
One-time code: `PaintInputOTP` paints segmented code entry; `InputOTPCommandForKey` maps key events to editor commands.
Input group: `PaintInputGroup` paints an input with leading and trailing text, button, key-cap, or icon addons.
Select: `BeginSelect` paints the trigger and filtered list popup.
Native select: `PaintNativeSelect` paints the platform-styled control and `PaintNativeSelectSemantics` declares its accessibility tree; `NativeSelectCommandForKey` maps key events.
Combobox: `BeginCombobox` paints an editable input with a suggestion list; `PaintComboboxChips` is the wrapping chip container of a multi-select.
Field: `BeginField` wraps a label, control slot, and hint; `FieldLegend` and `FieldSeparator` structure larger forms, and `BeginFieldSet` and `BeginFieldGroup` stack their rows at Vega's gaps. Naming the control (`Field.For`, `FieldTitle`, `FieldContent`) makes pressing the title focus and click it, as a label's `htmlFor` does, which is how the words beside a switch or a checkbox toggle it.
Form field: `PaintFormField` composes label, input, and validation message from one snapshot.
Layout:
Card: `Card` paints the default card surface; `PaintCard` selects a size tier and returns the header, content and footer rectangles, and `CardSpacing` returns the matching content inset.
Metric card: `MetricCard` paints a title, value, and trend summary.
Separator: `PaintSeparator` paints an auto-direction hairline.
Aspect ratio: `AspectRatio` computes the rect for content of a given ratio inside bounds.
Resizable: `BeginResizable` paints a two-panel split with a draggable handle.
Tree: `BeginTree` paints caller-flattened hierarchical rows with stable disclosure and selection semantics while leaving content application-owned.
Scroll area: `BeginScrollArea` paints a clipped viewport and scrollbar for caller-owned content; Viewport makes it focusable and ScrollForKey moves the caller's offsets.
Sidebar: `BeginSidebar` paints the app sidebar shell, or `BeginSidebarWithOptions` with explicit options; it takes header, group, menu item (with badge and action), sub menu and footer rows, and `PaintSidebarInset` paints the page card of the Inset variant.
Item: `BeginItem` paints a neutral list row surface and returns its media box and text column; `PaintItemSeparator` paints the divider between rows.
Collapsible: `BeginCollapsible` paints a disclosure trigger; the caller paints content below it while open.
Accordion: `BeginAccordion` paints stacked disclosure rows; Item returns each content rectangle.
Overlays enter and leave: while the application paints one it fades and moves in, and once it stops the canvas draws its last frame out, with no input. A menu, select or combobox has to call End for that.
Overlays:
Dialog: `BeginDialog` paints a centered modal with focus scope and dismiss handling; `Dialog.Actions` lays its footer buttons out.
Alert dialog: `BeginAlertDialog` paints the confirmation modal; `AlertDialogOptions.ActionVariant` styles the confirming button, e.g. `ButtonDestructive`.
Drawer: `BeginDrawer` paints a side-anchored overlay panel.
Sheet: `BeginSheet` paints the slide-over panel variant.
Popover: `BeginPopover` paints a panel anchored to a trigger rect; `PlaceOverlay` is the placement (side, align, flip, clamp) every anchored overlay shares and a menu can call.
Hover card: `BeginHoverCard` paints a preview card anchored to a target rect; `HoverIntent` supplies the hover rest, and an ID plus DismissID make the card enterable and dismissible.
Tooltip: `BeginTooltip` paints a label anchored to a target rect; `HoverTooltip` owns hover rest and, with ShowOnFocus, keyboard focus.
Dropdown menu: `BeginDropdownMenu` paints a menu opened from a trigger. A menu or command list taller than its bounds scrolls by the caller's `MenuScroll`, which takes the wheel, moves the arrow, Home, End and Page keys through the items (scrolling the one it reaches into view), matches a typed prefix through `MenuTypeahead`, and drags the scrollbar when it has an identity.
Context menu: `BeginContextMenu` paints a menu at the pointer over a region.
Command: `BeginCommand` paints the searchable command palette surface.
Feedback:
Alert: `Alert` paints an inline banner with variant, optional icon, title, and wrapped description; `AlertHeight` measures it.
Toast: `PaintToast` paints one caller-owned toast.
Toast stack: `PaintSonner` paints the stacked toast column; `ToastQueue` owns Base UI's timeout, visible limit, loading exemption and pause/resume, while the caller owns swipe and the exit.
Progress: `Progress` paints a determinate bar for a fraction, `ProgressIndeterminate` a sliding segment for unknown length, and `PaintProgressRow` adds the label and value line above the track.
Spinner: `PaintSpinner` paints the loading indicator for a phase.
Skeleton: `BeginSkeleton` paints a loading placeholder block.
Empty: `Empty` paints a centered empty state with line icon, title, and description.
Navigation:
Breadcrumb: `BeginBreadcrumb` paints a hierarchy path.
Menubar: `BeginMenubar` paints the top-level bar and `BeginMenubarContent` paints the open menu.
Navigation menu: `BeginNavigationMenu` paints the navbar with peek panels.
Pagination: `BeginPagination` paints page controls.
Tabs: `BeginTabs` paints the tab strip; `TabsKeyDown` wires arrow keys. `BeginTabList` numbers its own tabs and `Paint().Clicked()` reports the one clicked. Fit() sizes the list to its labels.
Data display:
Table: `BeginTable` paints the column-driven table shell; its rows can number themselves and report the one clicked. A cell wider than its column ends in an ellipsis; `FitTableHeadings` widens fixed columns to hold their headings.
Calendar: `BeginCalendar` paints the month grid; selection state is caller-owned and `CalendarCommandForKey` maps the navigation keys.
Carousel: `BeginCarousel` paints a pager viewport for caller content.
Chart: `PaintChartContainer` paints series geometry and axes; `PaintChartLegend` and `PaintChartTooltip` paint the matching chrome.
Message: `Message` paints one chat row; `BeginMessageGroup` stacks the rows of consecutive messages; `BeginMessageScroller` paints the scrollback viewport with jump controls, and `MessageScrollState` holds its policy (follow the live edge, anchor a turn, keep place when history is prepended).
Bubble: `Bubble` paints one chat bubble that shrinks to its text and wraps; `BubbleReaction` paints its reaction chip.
Attachment: `BeginAttachment` paints the media/upload card for a state, with icon actions; `BeginAttachmentGroup` lays cards in a row.
Badge: `PaintBadge` paints the semantic status pill and returns the consumed rect.
Marker: `Marker` paints the plain, centered-separator, and bottom-border marker forms; `MarkerProgress` puts a spinner in the icon slot.
Questionnaire: `BeginQuestionnaire` paints a question list with radio or checkbox semantics.
Avatar: `Avatar` paints one user glyph; `BeginAvatarGroup` overlaps a row of them.
Typography:
Label: `BeginLabel` paints themed text with alignment options; `LabelPainter.For` makes it the label of a control (`htmlFor`).
Keycap: `Kbd` paints one keyboard key chip; `BeginKbdGroup` lays out a sequence.
Typography: `Typography` paints the heading and body text scale.
Markdown: `MarkdownView` lays out and paints a parsed `markdown.Document` (headings, lists, quotes, code blocks, tables, bold, links) in a column, with the link regions and code blocks it contains.
Foundation:
Direction: `Direction` selects LTR or RTL inline flow (`DirectionLTR`, `DirectionRTL`); `LogicalRect` describes geometry on logical axes.
AccordionHeaderExtent#func AccordionHeaderExtent(theme ui.Theme) float32AccordionHeaderExtent is the height of one item's header row, for a caller that reserves room for an accordion in a layout before painting it.
Alert#func Alert(canvas *ui.Canvas, theme ui.Theme, bounds ui.Rect, data AlertData)Alert paints a Vega alert: a bordered card surface with an optional leading icon, a medium-weight title and a wrapped muted description. A non-positive bounds.Height takes AlertHeight. The AlertAction slot remains caller-owned.
AlertHeight#func AlertHeight(canvas *ui.Canvas, theme ui.Theme, width float32, data AlertData) float32AlertHeight returns the height of an alert of the given width: py-3 around a title row and, when there is a description, its wrapped lines after a 2px gap.
AspectRatio#func AspectRatio(bounds ui.Rect, ratio float32) ui.RectAspectRatio returns the largest centered rectangle with ratio width/height that fits bounds. A non-positive or unordered ratio produces an empty rect at the center, making invalid layout input deterministic.
Avatar#func Avatar(canvas *ui.Canvas, theme ui.Theme, bounds ui.Rect, data AvatarData)Avatar paints fallback, border overlay, and optional badge. Explicit bounds win when both dimensions are positive; otherwise the size variant is used.
BadgeExtent#func BadgeExtent(canvas *ui.Canvas, theme ui.Theme, label string) (width, height float32)BadgeExtent is the size PaintBadge gives a badge with the label: as wide as its text plus padding (px-2 and the 1px transparent border Vega gives every variant), so a layout can reserve room for it (a flex Slot) before it is painted.
Bubble#func Bubble(canvas *ui.Canvas, theme ui.Theme, bounds ui.Rect, alignment BubbleAlignment, variant BubbleVariant, text string) ui.RectBubble paints one retained content surface and returns its rectangle. The official component has no speech tail, so alignment only positions content inside the row bounds; the bubble is as wide as its text needs, up to 80% of the row (a ghost bubble: all of it), wraps beyond that, and is as tall as its lines. bounds.Height is not used; BubbleReaction takes the returned rectangle.
BubbleReaction#func BubbleReaction(canvas *ui.Canvas, theme ui.Theme, id ui.ID, bounds ui.Rect, side BubbleReactionSide, alignment BubbleAlignment, label string)BubbleReaction paints the official reaction capsule slot. A non-zero ID makes the capsule interactive without introducing reaction state.
CalendarFocusForKey#func CalendarFocusForKey(key ui.Key, direction Direction, days []CalendarDay, focused ui.ID) (ui.ID, bool)CalendarFocusForKey moves the focused day through a month snapshot: Left and Right by a day (reversed in RTL), Up and Down by a week, Home and End to the start and end of the current week. It clamps at the snapshot edges, skips disabled and zero days, and starts at the first enabled day when none is focused. PageUp/PageDown and Shift+PageUp/PageDown change the month and stay the caller's job, so this reports false for them.
Card#func Card(canvas *ui.Canvas, theme ui.Theme, bounds ui.Rect)Card paints the official default card surface.
CardDescriptionStyle#func CardDescriptionStyle(theme ui.Theme) ui.TextStyleCardDescriptionStyle is CardDescription: text-sm in the muted foreground.
CardHeaderHeight#func CardHeaderHeight(theme ui.Theme, size CardSize, hasDescription bool) float32CardHeaderHeight is the height of a header holding a title line and, when hasDescription, a description line under it with the header's gap-1.
CardSpacing#func CardSpacing(theme ui.Theme, size CardSize) float32CardSpacing returns the official content spacing for a card size.
CardTitleStyle#func CardTitleStyle(theme ui.Theme, size CardSize) ui.TextStyleCardTitleStyle is CardTitle: text-base medium, text-sm in a small card.
CarouselStepForKey#func CarouselStepForKey(key ui.Key, index, count int, direction Direction) (int, bool)CarouselStepForKey is the carousel region's keyboard movement: Left/Up go to the previous slide, Right/Down to the next, and Home/End to the ends. The caller owns the index and does not move past either end.
CheckboxExtent#func CheckboxExtent(theme ui.Theme) float32CheckboxExtent is the side of a checkbox's square at the theme's density.
CheckboxHitExtent#func CheckboxHitExtent(theme ui.Theme) (width, height float32)CheckboxHitExtent is the width and height of the interaction region Paint declares around a checkbox at the theme's density. A layout that gives a checkbox this much room can center the square inside it and keep adjacent checkboxes' hit regions from overlapping.
ContextMenuItemHeight#func ContextMenuItemHeight(theme ui.Theme, item ContextMenuItem, rowHeight float32) float32ContextMenuItemHeight is the height AddItem reserves for item. rowHeight is ContextMenuOptions.RowHeight (zero selects the standard 32px label row).
ContextMenuItemWidth#func ContextMenuItemWidth(canvas *ui.Canvas, theme ui.Theme, item ContextMenuItem) float32ContextMenuItemWidth is the width a context menu needs for item's row to show its icon, label and trailing content whole: take the largest over the menu's items as the bounds' Width. The menu's own minimum still applies.
Empty#func Empty(canvas *ui.Canvas, theme ui.Theme, bounds ui.Rect, data EmptyData) ui.RectEmpty paints a centered empty state: media, a medium title and a wrapped muted description, all within max-w-sm and p-12. The group is centered vertically in bounds. It returns the EmptyContent rectangle (max-w-sm wide, ContentHeight high, below the description) for the caller to place actions in; the rectangle is empty when ContentHeight is zero. The dashed border of the recipe is not drawn.
FieldContent#func FieldContent(canvas *ui.Canvas, theme ui.Theme, bounds ui.Rect, title, description string, control ui.ID, disabled bool) ui.RectFieldContent paints Vega's FieldContent: a title with its description beneath (gap-1), the text column of a row that has a control beside it. It returns the area it used, so the caller can place the control and size the row; the title is omitted when empty. A nonzero control is the identity of the switch, checkbox or field beside the text, which the title then labels (see FieldTitle).
FieldDescription#func FieldDescription(canvas *ui.Canvas, theme ui.Theme, bounds ui.Rect, text string, disabled bool)FieldDescription paints the muted explanation under a title or a control.
FieldError#func FieldError(canvas *ui.Canvas, theme ui.Theme, bounds ui.Rect, errors []string) ui.RectFieldError paints Vega's FieldError: one message as plain destructive text, several as a bulleted list (list-disc, gap-1) with empty and repeated messages left out. It returns the area used, zero high when there is nothing to say. The bullets are drawn dots, not characters.
FieldLegend#func FieldLegend(canvas *ui.Canvas, theme ui.Theme, bounds ui.Rect, text string, label bool)FieldLegend paints a field-set legend. Label legends use the normal control scale; section legends use the slightly stronger heading scale.
FieldSeparator#func FieldSeparator(canvas *ui.Canvas, theme ui.Theme, bounds ui.Rect, text string)FieldSeparator paints the Base UI separator slot with optional centered text (text-sm, px-2 either side).
FieldTitle#func FieldTitle(canvas *ui.Canvas, theme ui.Theme, bounds ui.Rect, text string, control ui.ID, disabled bool)FieldTitle paints the title of a field: text-sm font-medium, for a row whose control is a switch or a checkbox beside it. A nonzero control makes the title that control's label, as FieldLabel's `htmlFor` does: pressing the text toggles the switch or checkbox (see ui.Canvas.HitLabel).
FitTableHeadings#func FitTableHeadings(canvas *ui.Canvas, theme ui.Theme, columns []TableColumn, headings []string)FitTableHeadings widens each fixed-width column of columns that is narrower than its heading to the width the heading needs, so that no heading is cut or ends in an ellipsis. It is what shadcn's TableHead gets from whitespace-nowrap in an auto-width table, whose column is never narrower than its heading. A column that takes the remaining space (Width <= 0) and a column without a heading keep their width; the heading of a column that is too wide for the room left is still ellipsized.
Call it before BeginTable and before TableCellBounds with the columns and headings that are passed to them: the declared widths are the minimum, and the heading is measured in the language and weight it is painted in, so a translation that is longer than its column does not need a wider column written for it.
components.FitTableHeadings(canvas, theme, columns[:], headings[:])
table := components.BeginTable(canvas, theme, bounds, columns[:])
table.Header(headings[:])InputOTPComplete#func InputOTPComplete(value string, slots int) boolInputOTPComplete reports whether value fills every slot of the code (6 when slots is not positive): the moment shadcn's onComplete fires. The component keeps no state, so the caller compares it with the previous value.
ItemGroupGap#func ItemGroupGap(size ItemSize) float32ItemGroupGap is the spacing between items of a group (ItemGroup's gap-4, or gap-2.5 and gap-2 for small and extra-small items).
ItemMediaSize#func ItemMediaSize(theme ui.Theme, size ItemSize, variant ItemMediaVariant) float32ItemMediaSize is the side of the media box for a variant at an item size.
Kbd#func Kbd(canvas *ui.Canvas, theme ui.Theme, bounds ui.Rect, label string) ui.RectKbd paints one compact keyboard keycap. Zero width or height selects a content-fitted dimension; the returned rectangle is the actual painted size.
Marker#func Marker(canvas *ui.Canvas, theme ui.Theme, bounds ui.Rect, variant MarkerVariant, icon *ui.Icon, content string)Marker paints an optional icon and content using muted metadata styling: a timeline entry, a date separator, a "joined the chat" notice. A nil icon paints none. Without a bounds height the marker is as tall as its line of text (plus the official pb-2 and its rule for MarkerBorder).
MarkerProgress#func MarkerProgress(canvas *ui.Canvas, theme ui.Theme, bounds ui.Rect, variant MarkerVariant, phase SpinnerPhase, content string)MarkerProgress is Marker for work in progress: the spinner stands where the icon does, at the given phase. Advancing the phase and scheduling the next frame are the caller's, as for PaintSpinner. Mark the region a status role where the application declares its accessibility tree: the official marker for progress is role=status.
MeasureBubble#func MeasureBubble(canvas *ui.Canvas, theme ui.Theme, rowWidth float32, variant BubbleVariant, text string) ui.SizeMeasureBubble reports the size Bubble gives text in a row rowWidth wide, for laying out a list of messages before painting it.
MessageGroupGap#func MessageGroupGap(metrics ui.Metrics) float32MessageGroupGap is the space between messages of one group, the official MessageGroup gap-2.
MessageScrollerGap#func MessageScrollerGap(metrics ui.Metrics) float32MessageScrollerGap is the space between transcript items, the official MessageScrollerContent gap-8: 32px at the default density.
MessageSlotGap#func MessageSlotGap(metrics ui.Metrics) float32MessageSlotGap is the space between header, content and footer: the official MessageContent gap-2.5, 10px at the default density.
MetricCard#func MetricCard(canvas *ui.Canvas, theme ui.Theme, bounds ui.Rect, title, value, trend string, positive bool)MetricCard paints a dashboard metric with a trend label. Its rows are placed from the theme's metrics, so the card keeps its proportions at every density.
NavigationMenuHover#func NavigationMenuHover(open, trigger ui.ID, now time.Time, intent *HoverIntent, delay time.Duration) (ui.ID, time.Duration)NavigationMenuHover advances the navigation menu's hover switch: while a panel is open, resting on another trigger opens it after delay. It returns the open trigger and the wait before asking again.
NavigationMenuKeyDown#func NavigationMenuKeyDown(current ui.ID, triggers []NavigationMenuTrigger, open ui.ID, direction Direction, key ui.Key) (ui.ID, ui.ID, bool)NavigationMenuKeyDown moves focus between top-level triggers: Left/Right with wrapping (reversed in RTL), Home/End to the ends, Down/Enter/Space opens the focused trigger, and Up/Escape closes the open one and returns to its trigger. It returns the trigger to focus and the trigger whose panel is open (zero for none), and whether it owned the key.
PaintBadge#func PaintBadge(canvas *ui.Canvas, theme ui.Theme, origin ui.Rect, label string, variant BadgeVariant) ui.RectPaintBadge paints a shadcn Vega badge variant. Badges are presentational; callers that need a link or button should declare that interaction separately so its action and accessible name stay explicit.
PaintChartLegend#func PaintChartLegend(canvas *ui.Canvas, theme ui.Theme, bounds ui.Rect, series []ChartSeries) ui.RectPaintChartLegend paints the official centered legend row with 8px series swatches, 6px item-internal gaps, and 16px gaps between entries.
PaintChartTooltip#func PaintChartTooltip(canvas *ui.Canvas, theme ui.Theme, origin ui.Rect, series []ChartSeries, rows []ChartTooltipRow, options ChartTooltipOptions) ui.RectPaintChartTooltip paints the official tooltip-content shell at origin.X/Y. It reads immutable payload rows and series metadata and performs no value formatting, lifecycle management, hit testing, or data-geometry rendering.
PaintInput#func PaintInput(canvas *ui.Canvas, theme ui.Theme, bounds ui.Rect, snapshot InputSnapshot) ui.RectPaintInput paints the official Vega input recipe and returns its normalized geometry. Byte offsets describe DisplayValue (or Value when DisplayValue is empty) and are clamped to UTF-8 boundaries before painting.
PaintItemSeparator#func PaintItemSeparator(canvas *ui.Canvas, theme ui.Theme, bounds ui.Rect) float32PaintItemSeparator paints an ItemSeparator across bounds' width at its top and returns the height it used (ItemSeparatorHeight).
PaintNativeSelect#func PaintNativeSelect(canvas *ui.Canvas, theme ui.Theme, bounds ui.Rect, snapshot NativeSelectSnapshot) ui.RectPaintNativeSelect paints the official Vega select trigger and declares combobox semantics without implementing a source-owned popup.
PaintNativeSelectSemantics#func PaintNativeSelectSemantics(canvas *ui.Canvas, bounds ui.Rect, snapshot NativeSelectSnapshot)PaintNativeSelectSemantics declares only the trigger hit and accessibility state. A platform adapter may pair it with an OS-owned popup without asking the component to draw or retain that popup.
PaintProgressRow#func PaintProgressRow(canvas *ui.Canvas, theme ui.Theme, bounds ui.Rect, label, value string, fraction float32) ui.RectPaintProgressRow paints a ProgressLabel at the start and a ProgressValue at the end of a line, with the track on the line below, and returns the track's rectangle. bounds.Height is ignored; the row is ProgressRowHeight tall. value is the caller-formatted text, such as "64%".
PaintSeparator#func PaintSeparator(canvas *ui.Canvas, theme ui.Theme, bounds ui.Rect, orientation SeparatorOrientation)PaintSeparator paints one one-pixel divider centered in the supplied layout bounds. The bounds may therefore retain a larger hit-free layout gap.
PaintSidebarInset#func PaintSidebarInset(canvas *ui.Canvas, theme ui.Theme, bounds ui.Rect, side SidebarSide) ui.RectPaintSidebarInset paints the page surface that goes with the Inset variant: the region beside the sidebar takes the sidebar color and the content is a rounded background-colored card inside an 8px margin, flush with the sidebar edge (m-2 ml-0). It returns the card's bounds for the caller's content.
PaintTextarea#func PaintTextarea(canvas *ui.Canvas, theme ui.Theme, bounds ui.Rect, snapshot TextareaSnapshot) ui.RectPaintTextarea paints the official Vega multiline recipe and returns its normalized geometry. The official minimum height is 64 logical pixels.
ParseColorHex#func ParseColorHex(value string, alpha bool) (ui.Color, bool)ParseColorHex accepts #RGB/#RRGGBB and, when alpha is enabled, their alpha forms. Product-specific formats and validation stay with the caller.
Progress#func Progress(canvas *ui.Canvas, theme ui.Theme, bounds ui.Rect, fraction float32)Progress paints the official bounded horizontal progress track and indicator. A non-finite or negative fraction is treated as zero.
Like the source, the indicator is a plain bar inside a rounded track that clips it: its left end follows the track's round end at any width, and its right end is flat until the bar fills the track.
ProgressIndeterminate#func ProgressIndeterminate(canvas *ui.Canvas, theme ui.Theme, bounds ui.Rect, phase float32)ProgressIndeterminate paints a track whose indicator is a segment sliding across it, for work of unknown length. phase is the caller's position in the cycle: 0 puts the segment off the left end, 1 off the right end. The caller schedules the frames; nothing here keeps time.
ProgressRowHeight#func ProgressRowHeight(theme ui.Theme) float32ProgressRowHeight is the height of a labeled progress row: a text-sm line, the root's gap-3 and the track.
RadioGroupKeyDown#func RadioGroupKeyDown(current ui.ID, options []RadioOption, direction Direction, key ui.Key) (ui.ID, bool)RadioGroupKeyDown applies radio-group keyboard navigation to current. Arrow keys wrap through enabled non-zero options. Physical Left and Right reverse in RTL. Base UI leaves Home and End to the page, so they are not owned here. The returned bool reports whether key is owned by the pattern.
RangeSliderKeyDown#func RangeSliderKeyDown(values []float32, index int, minimum, maximum, step, largeStep float32, minSteps int, direction Direction, key ui.Key, modifiers ui.Modifiers) boolRangeSliderKeyDown applies Base UI's range-slider keyboard rules to one thumb in a sorted values slice and reports whether it changed any value. Arrows move by step, Shift+arrow and PageUp/PageDown by largeStep, and Home/End go to the ends of the thumb's own range. Thumbs keep minSteps*step apart: moving a thumb pushes its neighbours, while Home and End stop at the neighbour as Base UI's range thumb does.
ResizableHandleForKey#func ResizableHandleForKey(key ui.Key, handles []ui.ID, current ui.ID, reverse bool) (ui.ID, bool)ResizableHandleForKey moves focus between resize handles with F6 and Shift+F6, wrapping and skipping zero identities. The application owns the handles' identities and the focus result.
SegmentedControlKeyDown#func SegmentedControlKeyDown(current ui.ID, options []SegmentOption, direction Direction, key ui.Key) (ui.ID, bool)SegmentedControlKeyDown applies horizontal roving focus to current. Left and Right wrap through enabled non-zero options and reverse in RTL; Home and End choose the first and last enabled options. Vertical arrows are not owned by a horizontal segmented control.
SegmentedControlWidth#func SegmentedControlWidth(canvas *ui.Canvas, theme ui.Theme, options []SegmentOption) float32SegmentedControlWidth is the narrowest width at which every option's label is whole with the theme's control padding on both sides of it. The options are of equal width, so it is the widest label's, times their number: a control given less than this cuts its longest label.
SliderKeyDown#func SliderKeyDown(value, minimum, maximum, step float32, direction Direction, key ui.Key, modifiers ui.Modifiers) (float32, bool)SliderKeyDown applies Base UI's slider keyboard pattern to value with Base UI's default large step of 10 value units: the arrows move it by one step (Right and Up up, Left and Down down; Left and Right swap in RTL), Shift with an arrow and PageUp/PageDown by 10 units, Home and End to the minimum and maximum. A zero or negative step moves by one unit. The result is clamped and snapped like Slider.Step does; the returned bool reports whether key is owned by the slider pattern, so the caller passes anything else on.
next, handled := components.SliderKeyDown(m.volume, 0, 100, 5, components.LTR, event.Key, event.Modifiers)SliderKeyDownLarge#func SliderKeyDownLarge(value, minimum, maximum, step, largeStep float32, direction Direction, key ui.Key, modifiers ui.Modifiers) (float32, bool)SliderKeyDownLarge is SliderKeyDown with Base UI's configurable largeStep: the number of value units Shift+arrow and PageUp/PageDown move, not a number of steps. Base UI's default is 10, which SliderKeyDown uses, so a step of 5 moves 10 units (two steps) rather than 50. A non-positive largeStep also uses 10. The result is snapped to step, so a large step that is not a multiple of step lands on the nearest one.
SubmenuPlacement#func SubmenuPlacement(trigger ui.Rect, size ui.Size, viewport ui.Rect) ui.RectSubmenuPlacement places a submenu beside its trigger row, on the right, top aligned with the row (Base UI's align start and -3px align offset), flipping left or adjusting inside the viewport when there is no room. It is the shared placement a menu's submenu controller uses instead of hand-computed edges.
SubmenuSafe#func SubmenuSafe(trigger, submenu ui.Rect, point ui.Point) boolSubmenuSafe reports whether point is in the grace area between a submenu trigger and its open panel, so a diagonal pointer move does not close the submenu before it arrives. It is the box of the two rectangles with a small margin: more forgiving than a strict triangle, and it does not block pointer events outside the pair the way Base UI's safe polygon does.
SwitchExtent#func SwitchExtent(theme ui.Theme, small bool) (width, height float32)SwitchExtent is the width and height of a switch at the theme's density.
SwitchHitExtent#func SwitchHitExtent(theme ui.Theme, small bool) (width, height float32)SwitchHitExtent is the width and height of the interaction region Paint declares around a switch. The padding is the fixed 12 by 8 logical pixels Paint adds, not scaled by density.
TableCellBounds#func TableCellBounds(columns []TableColumn, row ui.Rect, dst []ui.Rect) []ui.RectTableCellBounds appends to dst the cells of a row that fills row, as Header and Row paint them: fixed widths in order, a column without one taking what is left, cells that no longer fit left out. It lets a caller put something on a cell, a sort arrow or a hit region, without painting the row first.
TableHeaderHeight#func TableHeaderHeight(theme ui.Theme) float32TableHeaderHeight is the default height of the header row, TableHead's h-10.
TableRowHeight#func TableRowHeight(theme ui.Theme) float32TableRowHeight is the default height of a body or footer row: TableCell's p-2 around one 20px line, scaled to the theme's control height.
TabsKeyDown#func TabsKeyDown(current ui.ID, options []TabOption, orientation TabsOrientation, direction Direction, key ui.Key) (ui.ID, bool)TabsKeyDown applies orientation-aware roving focus to current. Arrow keys on the tab list's layout axis wrap through enabled non-zero options; Home and End choose the first and last. Horizontal Left and Right reverse in RTL.
ToastHeight#func ToastHeight(canvas *ui.Canvas, theme ui.Theme, viewport ui.Rect, snapshot ToastSnapshot, options ToastOptions) float32ToastHeight is how tall PaintToast makes the toast, for a caller that stacks toasts itself.
ToggleGroupKeyDown#func ToggleGroupKeyDown(current ui.ID, options []ToggleGroupOption, orientation ToggleGroupOrientation, direction Direction, key ui.Key) (ui.ID, bool)ToggleGroupKeyDown applies orientation-aware roving focus to current. Arrow keys on the group's layout axis wrap through enabled non-zero options; Home and End choose the first and last. Horizontal Left and Right reverse in RTL.
Typography#func Typography(canvas *ui.Canvas, theme ui.Theme, bounds ui.Rect, variant TypographyVariant, text string)Typography paints one line using the theme's type scale. Rich text, wrapping, and document layout remain separate concerns of the text subsystem.
const (
DirectionLTR Direction = iota + 1
DirectionRTL
LTR = DirectionLTR
RTL = DirectionRTL
)const (
ToastQueueTimeout = 5 * time.Second
ToastQueueLimit = 3
)ToastQueueTimeout and ToastQueueLimit are Base UI's default toast lifetime (5 seconds) and visible limit.
const HoverTooltipDelay = 0HoverTooltipDelay is how long the pointer rests on a control before its tooltip appears. The pinned shadcn TooltipProvider uses delay 0, so a tooltip appears with the pointer; an application may pass a longer delay to Paint when it wants one.
const ItemSeparatorHeight = 17ItemSeparatorHeight is the room an ItemSeparator takes: a hairline with my-2 above and below.
const MenuTypeaheadReset = 500 * time.MillisecondMenuTypeaheadReset is how long Base UI keeps a menu's typed prefix before it starts a new one.
const MessageScrollPreviousPeek float32 = 64MessageScrollPreviousPeek is the slice of the previous item the official scroller keeps above an anchored turn, scrollPreviousItemPeek.
const MessageScrollerEdgeThreshold float32 = 8MessageScrollerEdgeThreshold is how close to an end the viewport counts as being at it, the official scrollEdgeThreshold. Inside it the jump button for that end is not offered, so a reply that grows by a line while streaming does not make the button flicker.
const (
// Diagonal spokes are a staircase of spinnerDiagonalRows horizontal strips,
// each spinnerDiagonalStep tall and shifted by the same amount, so the
// edge runs at 45 degrees. A half-pixel step is one physical pixel on a 2x
// display. The outermost strips are one pixel narrower to round the tips.
// SpinnerLabel is the official accessible name for the status indicator.
SpinnerLabel = "Loading"
)const TooltipDefaultSideOffset = float32(10)TooltipDefaultSideOffset is the gap between a tooltip and the control it names when TooltipOptions.SideOffset is zero. The compact icon buttons of desktop toolbars read better with the tooltip clear of them.