Documentation
¶
Overview ¶
Package kit is the Pando component library of the native desktop: the Web UI design tokens (web-ui/src/styles/tokens.css) ported onto MyGo's ui.Theme, an embedded lucide icon subset, and small components built on MyGo's widget bases. Views import kit for their look; only kit, shell and app/... import MyGo.
Index ¶
- Constants
- Variables
- func Badge(c *ui.Context, text string, tone Tone) ui.Element
- func Button(c *ui.Context, o ButtonOpts) ui.Element
- func Card(c *ui.Context, fn func()) ui.Element
- func CodeBlock(c *ui.Context, lang, code string, opts *markdown.Options) ui.Element
- func CopyText(s string) bool
- func Dialog(c *ui.Context, open *bool, o DialogOpts) ui.Element
- func EmptyState(c *ui.Context, icon, title, description string) ui.Element
- func HasIcon(name string) bool
- func Icon(c *ui.Context, name string) ui.Element
- func IconButton(c *ui.Context, icon, label string) ui.Element
- func IconNames() []string
- func Input(c *ui.Context, value *string, placeholder string) ui.Element
- func NavItem(c *ui.Context, icon, label string, active, collapsed bool) ui.Element
- func OpenWebWindow(title, url string, apply func(c *ui.Context)) *mygo.Window
- func PrimaryButton(c *ui.Context, label string) ui.Element
- func SVG(name string) *ui.SVG
- func SecondaryButton(c *ui.Context, label string) ui.Element
- func SectionLabel(c *ui.Context, text string) ui.Element
- func Select(c *ui.Context, selected *string, options []string) ui.Element
- func SettingsRow(c *ui.Context, label, description string, control func()) ui.Element
- func SettingsSection(c *ui.Context, title, description string, fn func()) ui.Element
- func Spinner(c *ui.Context) ui.Element
- func Switch(c *ui.Context, on *bool, label string) ui.Element
- func ToastViewport(c *ui.Context)
- func ToneColors(tone Tone) (fg, bg ui.Color)
- func Tooltip(el ui.Element, text string) ui.Element
- type Accent
- type ButtonOpts
- type DialogOpts
- type Family
- type Mode
- type Settings
- type Size
- type Toaster
- type Tokens
- type Tone
- type Variant
- type WebPane
- func (p *WebPane) Build(c *ui.Context, browserURL string)
- func (p *WebPane) Err() string
- func (p *WebPane) Eval(code string) (any, error)
- func (p *WebPane) Load(url string, force bool)
- func (p *WebPane) LoadError() string
- func (p *WebPane) Ready() bool
- func (p *WebPane) Reload()
- func (p *WebPane) URL() string
- type WebViewHost
- type WindowControl
- type WindowControlsOpts
Constants ¶
const ( ToastInfo = "" ToastSuccess = "success" ToastError = "error" ToastWarning = "warning" )
Toast types understood by ToastViewport.
const ( IconChat = "message-square" IconSimpleChat = "message-square-plus" IconProjects = "folder-open" IconFolder = "folder" IconFile = "file" IconFileText = "file-text" IconEditor = "code" IconTerminal = "square-terminal" IconOrchestrate = "network" IconDesign = "palette" IconLogs = "scroll-text" IconAgentVCS = "git-branch" IconEvaluator = "sparkles" IconInstances = "server" IconSettings = "settings" IconExtensions = "puzzle" IconSetup = "rocket" IconPlus = "plus" IconSend = "send" IconStop = "square" IconClose = "x" IconCheck = "check" IconCopy = "copy" IconTrash = "trash" IconEdit = "pencil" IconChevronDown = "chevron-down" IconChevronUp = "chevron-up" IconChevronR = "chevron-right" IconChevronL = "chevron-left" IconSearch = "search" IconRefresh = "refresh-cw" IconSpinner = "loader-circle" IconError = "circle-alert" IconWarning = "triangle-alert" IconInfo = "info" IconSuccess = "circle-check" IconThinking = "brain" IconTool = "wrench" IconSun = "sun" IconMoon = "moon" IconMonitor = "monitor" IconPanelLeft = "panel-left" IconPanelRight = "panel-right" IconMore = "ellipsis" IconArrowDown = "arrow-down" IconArrowUp = "arrow-up" IconExternal = "external-link" IconBot = "bot" IconUser = "user" IconClock = "clock" IconTodo = "list-todo" IconHome = "house" IconGlobe = "globe" )
Icon names used by the shell and the views. Prefer these constants over raw strings so a missing icon fails at review, not at run time.
const ( IconBookOpen = "book-open" IconUpdate = "circle-arrow-up" IconCommand = "command" IconLogOut = "log-out" IconKey = "key" )
Icons of the window shell (header, overlays).
const ( IconMinus = "minus" IconMaximize = "square" IconRestore = "copy" )
Icons of the custom window controls (minimise, maximise, restore).
Variables ¶
var DefaultSettings = Settings{Family: FamilyPando, Mode: ModeSystem}
DefaultSettings is Pando, following the system.
var ErrNoWebView = errors.New("embedded web views are not available in this window")
ErrNoWebView is the reason shown when no window is available to host a web view.
Functions ¶
func Button ¶
func Button(c *ui.Context, o ButtonOpts) ui.Element
Button is a Pando button on MyGo's ButtonBase. Read Clicked on the returned element. Give it a key (c.Key) when it is built in a loop.
func CodeBlock ¶
CodeBlock shows highlighted code with a copy button, through the markdown renderer (one fenced block). opts may be nil.
func Dialog ¶
Dialog shows a modal panel over a scrim while *open is true; Escape and a click outside close it.
func EmptyState ¶
EmptyState is a centred icon, title and description, for views with nothing to show yet.
func Icon ¶
Icon shows an embedded icon in the current text colour, sized to the font size unless resized with FontSize or Size.
func IconButton ¶
IconButton is a square ghost button showing an icon, named for assistive technology and the tooltip by label.
func Input ¶
Input is a single-line text input with Pando's field look. Read Changed/Submitted on the returned element.
func NavItem ¶
NavItem is an item of the app sidebar: an icon and a label (the label becomes a tooltip when collapsed). Read Clicked on the result.
func OpenWebWindow ¶
OpenWebWindow opens a native window of its own showing url in an embedded web view (the design canvas, a preview). apply sets the theme each frame (usually kit.Apply(c, a.Theme)). Call it on the UI thread. Without WebKitGTK/WebView2 the window shows the fallback with "Open in browser".
func PrimaryButton ¶
PrimaryButton is a Primary button with a label.
func SVG ¶
SVG returns the embedded icon name, parsed once. An unknown name returns the "circle-alert" icon so a typo shows instead of crashing.
func SecondaryButton ¶
SecondaryButton is a Secondary button with a label.
func SectionLabel ¶
SectionLabel is the small uppercase heading of a sidebar section.
func SettingsRow ¶
SettingsRow is a row of a SettingsSection: a label and description on the left, the control on the right.
func SettingsSection ¶
SettingsSection groups settings rows under a title (settings.css .settings-section).
func ToastViewport ¶
ToastViewport shows the window's toasts bottom-right with Pando's look. Call it once in the root view.
func ToneColors ¶
ToneColors returns the foreground and soft background of a tone.
Types ¶
type Accent ¶
type Accent string
Accent is an accent preset of the Web UI (data-accent); "" keeps the family's own.
type ButtonOpts ¶
type ButtonOpts struct {
Variant Variant
Size Size
// Icon is an embedded icon name shown before the label.
Icon string
Label string
// Tooltip shows on hover; icon-only buttons should set it.
Tooltip string
Disabled bool
// Active draws a pressed/selected state (toggle buttons).
Active bool
}
ButtonOpts configures Button.
type DialogOpts ¶
type DialogOpts struct {
Title string
Description string
// Width of the panel in DIPs (default 440).
Width float32
Body, Footer func()
}
DialogOpts configures Dialog.
type Family ¶
type Family string
Family is a theme family of the Web UI (data-theme-name).
type Settings ¶
Settings selects the theme of the app: a family, an appearance mode and an optional accent preset (the Web UI's appearance settings).
type Toaster ¶
type Toaster struct {
Invalidate func()
// contains filtered or unexported fields
}
Toaster queues toasts from any goroutine; the view flushes them into the window with Flush (c.AddToast needs the UI thread). Invalidate, when set, asks the window for a frame after Push.
type Tokens ¶
type Tokens struct {
Family Family
Dark bool
Bg, BgShell, BgRaised, BgCard, BgInput, BgOverlay, BgHover ui.Color
Fg, FgMuted, FgFaint ui.Color
Border, BorderStrong ui.Color
Accent, AccentFg, AccentSoft, AccentHover, FocusRing ui.Color
Danger, Warning, Success, Info ui.Color
DangerSoft, WarningSoft, SuccessSoft, InfoSoft ui.Color
Scrim ui.Color
// Radii (DIPs): --radius-xs .. --radius-xl.
RadiusXS, RadiusSM, RadiusMD, RadiusLG, RadiusXL float32
// Text sizes (DIPs): --text-xs .. --text-2xl.
TextXS, TextSM, TextBase, TextMD, TextLG, TextXL, Text2XL float32
// ControlH and ControlHSm are the control heights.
ControlH, ControlHSm float32
// MonoFont is the code font family.
MonoFont string
// contains filtered or unexported fields
}
Tokens are the resolved design tokens of one theme: the semantic names of tokens.css. Use them for what ui.Theme has no slot for (shell and card backgrounds, faint text, soft status fills).
func Apply ¶
Apply resolves the theme for this frame and installs it: call it first in the window's view. systemDark comes from c.Theme().Dark before any SetTheme, which follows the system appearance.
func Resolve ¶
Resolve returns the tokens of a family in light or dark, with an optional accent preset. Unknown families resolve to Pando.
type WebPane ¶
type WebPane struct {
// Host returns the window to create the web view in (nil in tests).
Host func() WebViewHost
// Preload is JavaScript run before the page's own scripts.
Preload string
// OnChange asks for a redraw (a load finished or failed).
OnChange func()
// contains filtered or unexported fields
}
WebPane is an embedded web view inside the native UI (MyGo ui.WebView): the preview canvas of the Design Studio, extension panels. The web view is created on first use; where the platform cannot provide one (Linux without WebKitGTK) the pane shows a message and an "Open in browser" button instead, so callers need no special case.
All methods run on the UI thread (Build and event handlers), except Eval/EvalAs which may run from any goroutine once Ready reports true.
func (*WebPane) Build ¶
Build draws the web view filling its container, or the fallback. Pass the URL to open in the system browser from the fallback (usually URL()).
func (*WebPane) Eval ¶
Eval runs JavaScript in the page and returns its value (the body of an async function: use return). Safe from goroutines.
func (*WebPane) Load ¶
Load shows url, creating the web view on first use. An empty url keeps the current page. Loading the same URL again reloads it only when force is set.
type WebViewHost ¶
type WebViewHost interface {
NewWebView(opts mygo.WebViewOptions) (*mygo.WebView, error)
}
WebViewHost creates embedded web views; *mygo.Window implements it.
type WindowControl ¶
type WindowControl int
WindowControl names a button of WindowControls.
const ( ControlNone WindowControl = iota ControlMinimize ControlMaximize // maximise or restore, whichever the icon shows ControlClose )
Window controls, in display order.
func WindowControls ¶
func WindowControls(c *ui.Context, o WindowControlsOpts) WindowControl
WindowControls draws the minimise, maximise/restore and close buttons of a window without a native title bar, flush to the right edge of its parent row (the Web UI's DesktopWindowControls look: 44px wide, full height, a red hover on close). It returns the button clicked this frame, or ControlNone. Keys are "winctl:*".
type WindowControlsOpts ¶
type WindowControlsOpts struct {
// Maximized shows the restore icon instead of the maximise one.
Maximized bool
// Labels are the tooltips and accessible names (already translated).
Minimize, Maximize, Restore, Close string
}
WindowControlsOpts configures WindowControls.