// Code generated by go generate ./ui; DO NOT EDIT. package ui import ( i18n "github.com/egoist/mygo/i18n" platform "github.com/egoist/mygo/internal/platform" transfer "github.com/egoist/mygo/transfer" image "image" time "time" ) // Focus gives the list the keyboard focus and reports whether it was // built in the current pass of c. A pending focus request can wait until // a hidden list returns: // // if app.focusFiles && app.files.Focus(c) { // app.focusFiles = false // } // // Call it after building the list, or while building its rows. func (_handle *ListState) Focus(c *Context) bool { _ctx := c.build() if _ctx == nil { return false } return _handle.coreFocus(_ctx) } // FocusWithin reports whether the list or one of its descendants has the // keyboard focus, with the same lifetime as Focused. Row builders can use // it before List returns, without saving an Element from an earlier frame. func (_handle *ListState) FocusWithin(c *Context) bool { _ctx := c.build() if _ctx == nil { return false } return _handle.coreFocusWithin(_ctx) } // Focused reports whether the List, Table or Outline using s has // the keyboard focus. Call it from the view, after building the list or // while building its rows. It returns false when s was not built in the // current pass of c, including when the list is hidden. func (_handle *ListState) Focused(c *Context) bool { _ctx := c.build() if _ctx == nil { return false } return _handle.coreFocused(_ctx) } // Shortcut reports whether mods+key was pressed while the list or one of // its descendants had the focus, as Element.Shortcut does. Call it after // building the list, or while building its rows. A list not built in the // current pass of c registers and handles no shortcuts. func (_handle *ListState) Shortcut(c *Context, mods Modifiers, key Key) bool { _ctx := c.build() if _ctx == nil { return false } _ctx.rt.applyInputs() return _handle.coreShortcut(_ctx, mods, key) } // Page returns the element holding the page, a column filling the router, // for its style. func (_handle *Route) Page() Element { _ctx := _handle.router.rtContext() if _ctx == nil { return Element{} } return wrapElement(_handle.corePage()) } // View builds the pages of the rest of the path, which the {name...} // wildcard of the pattern Match matched last took, with fn, in a column // taking the room it is given, and returns the column: the page holding // it is a layout, as a page of settings with a list of its sections // around the section shown. The layout stays as the pages inside change, // keeping its state, and they slide or fade in its place, keep their state // in the history and take the focus as the router's pages do. Their // patterns match the rest of the path, and Param returns the wildcards of // the layout's pattern too: // // case r.Match("/settings/{section...}"): // app.settingsSidebar(c) // r.View(c, func(r *ui.Route) { // switch { // case r.Match("/general"): // app.general(c) // case r.Match("/fonts"): // app.fonts(c) // } // }) // // View panics when the pattern Match matched last has no {name...}. func (_handle *Route) View(c *Context, fn func(r *Route)) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := _handle.coreView(_ctx, fn) _ctx.rt.endBuild() return wrapElement(_e) } // InSystemStack reports whether the system shows r's pages as its own // stack of screens (SystemStack), with its navigation bar: the view then // shows no bar of its own over them, nor a back button. func (_handle *Router) InSystemStack(c *Context) bool { _ctx := c.build() if _ctx == nil { return false } return _handle.coreInSystemStack(_ctx) } // View builds the page shown with fn, in a column taking the room it is // given, and returns the column. As a page slides in, it builds the one // going away too, which takes neither the pointer nor the keyboard. func (_handle *Router) View(c *Context, fn func(r *Route)) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := _handle.coreView(_ctx, fn) _ctx.rt.endBuild() return wrapElement(_e) } // Item creates a section of the accordion, open while *open: a // CollapsibleBase, whose Trigger is its header, which a click opens and // closes, as do Enter and Space, and the arrows, Home and End leave for // the other sections' headers; Panel builds what shows below it while it // is open. Assistive technology sees the header as a disclosure, expanded // while open. func (_handle AccordionParts) Item(open *bool) CollapsibleParts { _parts := _handle.resolve() if _parts == nil { return CollapsibleParts{} } _ctx := _parts.c _ = _ctx _ctx.rt.beginBuild() _p := _parts.Item(open) _ctx.rt.endBuild() return wrapCollapsibleParts(_p) } // Panel builds fn in the panel of the collapsible while it is open, and as // it opens and closes, when the panel grows and shrinks with Progress, // clipping what fn built. It returns the column holding what fn builds, // to style, and nil while the collapsible is closed. func (_handle CollapsibleParts) Panel(fn func()) Element { _parts := _handle.resolve() if _parts == nil { return Element{} } _ctx := _parts.c _ = _ctx _ctx.rt.beginBuild() _e := _parts.Panel(fn) _ctx.rt.endBuild() return wrapElement(_e) } // Progress returns how far the collapsible is open, from 0 closed to 1 // open, moving between them as it opens and closes: draw its arrow from // it. It moves at once where the desktop asks for less motion. func (_handle CollapsibleParts) Progress() float32 { _parts := _handle.resolve() if _parts == nil { return 0 } _ctx := _parts.c _ = _ctx return _parts.Progress() } // Chosen returns the option the user chose in this frame, by a click or // Enter: ask it after Popup, which takes the input of the options it // built as it returns, so the choice can be handled in the same build pass. func (_handle ComboboxParts) Chosen() (string, bool) { _parts := _handle.resolve() if _parts == nil { return "", false } _ctx := _parts.c _ = _ctx return _parts.Chosen() } // Filtering reports whether the text is what the user typed since the // popup opened, which the options should match; it is not when the popup // opened by a click or Down, which shows them all. func (_handle ComboboxParts) Filtering() bool { _parts := _handle.resolve() if _parts == nil { return false } _ctx := _parts.c _ = _ctx return _parts.Filtering() } // Item creates an option: a row that is Highlighted when the pointer or // the arrows are on it, and that chooses value when clicked. The option // the highlight moves to scrolls into view, once, so that the wheel // scrolls on past it. func (_handle ComboboxParts) Item(value string) Element { _parts := _handle.resolve() if _parts == nil { return Element{} } _ctx := _parts.c _ = _ctx _ctx.rt.beginBuild() _e := _parts.Item(value) _ctx.rt.endBuild() return wrapElement(_e) } // Open reports whether the popup shows. func (_handle ComboboxParts) Open() bool { _parts := _handle.resolve() if _parts == nil { return false } _ctx := _parts.c _ = _ctx return _parts.Open() } // Popup shows the popup below the input, at least as wide, while it is // open: fn styles the panel and builds the options with Item. A popup // without options shows only while it holds something else to read, as a // row saying that nothing matches, which assistive technology reads out // as it appears: // // if len(matches) == 0 { // ui.Text(c, "No matches found").Padding(6, 10) // } // // It returns the panel, or nil while it does not show. func (_handle ComboboxParts) Popup(fn func(panel Element)) Element { _parts := _handle.resolve() if _parts == nil { return Element{} } _ctx := _parts.c _ = _ctx _ctx.rt.beginBuild() _e := _parts.Popup(func(panel *node) { fn(wrapElement(panel)) }) _ctx.rt.endBuild() return wrapElement(_e) } // SetOpen opens or closes the popup. func (_handle ComboboxParts) SetOpen(o bool) { _parts := _handle.resolve() if _parts == nil { return } _ctx := _parts.c _ = _ctx _parts.SetOpen(o) } // AddToast shows t near the bottom of the window, as Toast does, and // returns its ID, to close it with CloseToast: // // id := c.AddToast(ui.Toast{Title: "Uploading", Timeout: -1}) // // ... // c.CloseToast(id) // // Adding a toast with the ID of one showing changes that toast, which // shows anew. Toasts show with the theme's look, unless the view builds // them with ToastViewportBase. func (_handle *Context) AddToast(t Toast) string { _ctx := _handle.build() if _ctx == nil { return "" } return _ctx.AddToast(t) } // After asks for another frame after d, for something that changes with // time, such as a clock. func (_handle *Context) After(d time.Duration) { _ctx := _handle.build() if _ctx == nil { return } _ctx.After(d) } // AnimationFrame asks for another frame as soon as the display can show // it, for something moving. Call it in every frame while it moves. A // drawing that moves while the layout stays asks with // Painter.AnimationFrame instead, whose frames do not build the view. func (_handle *Context) AnimationFrame() { _ctx := _handle.build() if _ctx == nil { return } _ctx.AnimationFrame() } // Announce asks screen readers to read text out once, after what they // are reading, for news the keyboard focus does not bring, as a search // done or a file saved: a Router announces the title of a page it shows, // and a toast its text. It does nothing while no assistive technology // reads the window. func (_handle *Context) Announce(text string) { _ctx := _handle.build() if _ctx == nil { return } _ctx.Announce(text) } // CloseToast closes the toast with id, or every toast when id is empty, // and runs their OnClose. func (_handle *Context) CloseToast(id string) { _ctx := _handle.build() if _ctx == nil { return } _ctx.CloseToast(id) } // Direction returns the direction of the elements built now: that of the // element they go in. Widgets of an app's own read it to draw what points // along the line, as an arrow forward: // // forward := "M5 2 11 8 5 14" // if c.Direction() == ui.RightToLeft { // forward = "M11 2 5 8 11 14" // } func (_handle *Context) Direction() Direction { _ctx := _handle.build() if _ctx == nil { return *new(Direction) } return _ctx.Direction() } // DisableAnimations makes the values that animate in this frame // (AnimateTo, Animate, Spring), the element transitions and the pages of // routers go to their targets at once, as SwiftUI's disablesAnimations: // for a change that should not show as motion, as restoring a window's // state or jumping to a search result. Call it before building what // changes. Keyframes and timelines, which play on their own rather than // towards a target, go on as they were: Seek a Timeline to jump it. func (_handle *Context) DisableAnimations() { _ctx := _handle.build() if _ctx == nil { return } _ctx.DisableAnimations() } // FocusTakesText reports whether the element with the keyboard focus takes // text, typed or composed: a text input or text area, or an editor of // rich text or code, that is not read only, or an element that takes text // itself (HandleTextInput, TextCaret). It is the web's guard of // single-key shortcuts (isContentEditable, an input or a textarea, the // role textbox): a command palette's letters step aside while a field // takes them as text. // // if !c.FocusTakesText() && c.Shortcut(0, ui.KeyK) { // app.palette = true // } // // It is false while the window does not have the keyboard, as the // window tells the system's input methods then. func (_handle *Context) FocusTakesText() bool { _ctx := _handle.build() if _ctx == nil { return false } return _ctx.FocusTakesText() } // Instant reports whether this frame shows animated values at once // (DisableAnimations). Views read it to render a change settled in the same // frames where its animations are disabled. func (_handle *Context) Instant() bool { _ctx := _handle.build() if _ctx == nil { return false } return _ctx.Instant() } // KeyDown reports whether key is held down in the window, whichever // element has the focus and whether or not one took the key, without // taking it from them: a cheat sheet of shortcuts lights the keys held // while its search field has the focus. A frame that reads it is drawn // again as the keys held change. Keys count as shortcuts take them (a // chord of a key the layout types no US key for, as S on a Cyrillic // layout, by its position); the modifier keys are Modifiers'. A key whose // press ran a menu item's shortcut went to the menu, not the window. The // window lets go of every key as it loses the keyboard, whose releases go // elsewhere. func (_handle *Context) KeyDown(key Key) bool { _ctx := _handle.build() if _ctx == nil { return false } return _ctx.KeyDown(key) } // KeysDown returns the keys held down in the window, as KeyDown tells // them, in the order they were pressed; nil while none is. A cheat sheet // fades the rows of shortcuts that use none of them: // // held := c.KeysDown() // for _, s := range app.shortcuts { // row := shortcutRow(c, s) // if len(held) > 0 && !s.usesAny(held) { // row.Opacity(0.4) // } // } func (_handle *Context) KeysDown() []Key { _ctx := _handle.build() if _ctx == nil { return nil } return _ctx.KeysDown() } // Locale returns the language the app shows (mygo.App.Locale), a BCP 47 // tag such as "en" or "zh-Hans", for what the view says in it. Text is in // it unless an element says otherwise (Element.Lang). A frame follows its // changes, as App.SetLocale makes them. func (_handle *Context) Locale() string { _ctx := _handle.build() if _ctx == nil { return "" } return _ctx.Locale() } // MeasureText returns the size spans of text take as Painter.RichText draws // them, wrapping lines at width DIPs (none for 0), to lay out what depends // on it while building. func (_handle *Context) MeasureText(width float32, spans ...Span) (float32, float32) { _ctx := _handle.build() if _ctx == nil { return 0, 0 } return _ctx.MeasureText(width, spans...) } // MenuPresentation returns how the window shows its popup menus // (SetMenuPresentation). func (_handle *Context) MenuPresentation() MenuPresentation { _ctx := _handle.build() if _ctx == nil { return *new(MenuPresentation) } return _ctx.MenuPresentation() } // Modifiers returns the modifier keys held now, as the last key, pointer // or modifier event said: a view showing each row's shortcut while Cmd is // held reads it, and draws again as it changes. func (_handle *Context) Modifiers() Modifiers { _ctx := _handle.build() if _ctx == nil { return 0 } return _ctx.Modifiers() } // Now returns the time the frame started, for animations. func (_handle *Context) Now() time.Time { _ctx := _handle.build() if _ctx == nil { return *new(time.Time) } return _ctx.Now() } // OpenURL opens a URL in the default browser, or the app registered for // its scheme, as a Link does. It returns at once; OpenURLThen tells what // came of it. func (_handle *Context) OpenURL(url string) { _ctx := _handle.build() if _ctx == nil { return } _ctx.OpenURL(url) } // OpenURLThen opens a URL as OpenURL does, and done, unless nil, gets what // came of it in a while, before a frame builds anew with what it changed: // an error when no app could open the URL. // // c.OpenURLThen(url, func(err error) { // if err != nil { // app.failed = url // } // }) func (_handle *Context) OpenURLThen(url string, done func(err error)) { _ctx := _handle.build() if _ctx == nil { return } _ctx.OpenURLThen(url, done) } // Preferences returns the settings of the desktop that controls follow. // A frame follows their changes. func (_handle *Context) Preferences() Preferences { _ctx := _handle.build() if _ctx == nil { return *new(Preferences) } return _ctx.Preferences() } // ReadClipboard returns the text on the clipboard, and WriteClipboard // puts text there, for widgets that copy and paste themselves. Call them // on the main thread: in the view, or in an input handler. // WriteClipboardThen tells whether the text got there. func (_handle *Context) ReadClipboard() string { _ctx := _handle.build() if _ctx == nil { return "" } return _ctx.ReadClipboard() } // Region returns the user's regional formats (mygo.App.Region): the // locale of the formats, the first day of the week and the hour cycle, // which dates and times follow. A frame follows their changes. func (_handle *Context) Region() i18n.Region { _ctx := _handle.build() if _ctx == nil { return *new(i18n.Region) } return _ctx.Region() } // Root returns the element holding the window's content: a column the // size of the window. func (_handle *Context) Root() Element { _ctx := _handle.build() if _ctx == nil { return Element{} } return wrapElement(_ctx.Root()) } // isPath reports whether a link's target is a path within the app, as // "/notes/42", "edit" or "?tab=info", rather than a URL with a scheme. // Router returns the router whose page is being built, which a Link to a // path without a scheme goes through, or nil outside one. func (_handle *Context) Router() *Router { _ctx := _handle.build() if _ctx == nil { return nil } return _ctx.Router() } // SafeArea returns how far in from each edge of the window what the system // draws covers it, in DIPs: a phone's bars, its cutout and the keyboard. The // window's root keeps its content inside them; what draws in the Overlay, as // a sheet, or under them, reads them here. func (_handle *Context) SafeArea() (float32, float32, float32, float32) { _ctx := _handle.build() if _ctx == nil { return 0, 0, 0, 0 } return _ctx.SafeArea() } // SetMenuPresentation sets how the window shows its popup menus: those of // ContextMenu and Menu, the menus MyGo's widgets build with them, as a // table's header and cell menus, and the editing menu of text inputs and // selectable text. With PopoverMenus they draw in the window as // PopoverMenu draws its menu, with its keys, focus and roles, so that an // app with a look of its own shows no menu of the desktop's beside its // own; with SystemMenus, the default, the system shows them. It stays // until set again. PopoverMenu and PopoverMenuButton draw theirs in the // window whatever it is. Only the menus MyGo builds follow it: the menu // bar, the tray's menu and the Dock's stay the system's, and a web view's // are the web view's own. // // c.SetMenuPresentation(ui.PopoverMenus) func (_handle *Context) SetMenuPresentation(p MenuPresentation) { _ctx := _handle.build() if _ctx == nil { return } _ctx.SetMenuPresentation(p) } // SetTheme makes the frame use t, for the window's root and the widgets // created after the call. Inside the children of a Themed, which keep its // theme, t is for the root and the widgets after the Themed. func (_handle *Context) SetTheme(t *Theme) { _ctx := _handle.build() if _ctx == nil { return } _ctx.SetTheme(t) } // SetZoom zooms the window's content by z, as a browser zooms a page: the // view is laid out in a window 1/z its size and shown z times larger, // drawn at the screen's resolution times z, so that text, icons, vectors // and images stay as sharp as at that size natively, not a picture of // the window scaled up. 1 shows the content at its size; the zoom // stays until set again, and is clamped to between 0.25 and 5. A frame // that sets another builds again at the new size before it shows. // // What the view sees is zoomed: Size, TitleBar, Bounds and every length // are in the content's DIPs, z of them to the window's. The pointer, text // input, input methods, accessibility, context menus, drags and web views // follow it. The window's own sizes are not zoomed: Window.SetContentSize // and Window.ContentSize are in the window's DIPs, z times the content's. // // c.SetZoom(app.zoom) // 1.25 for 125% func (_handle *Context) SetZoom(z float32) { _ctx := _handle.build() if _ctx == nil { return } _ctx.SetZoom(z) } // Shortcut reports whether the key with exactly the modifiers mods was // pressed, wherever the keyboard focus is, unless a focused element // handled it first: a focused button or link takes Enter and Space, and a // check box, switch or radio button Space, so that Enter can press a // dialog's default button. func (_handle *Context) Shortcut(mods Modifiers, key Key) bool { _ctx := _handle.build() if _ctx == nil { return false } _ctx.rt.applyInputs() return _ctx.Shortcut(mods, key) } // ShortcutRepeated reports whether the key that the last Shortcut to // report one took came as the auto-repeat of a key held down, as the web's // KeyboardEvent.repeat: Context's, an Element's, a list's or an overlay's, // and those that run OnShortcut's actions, which can ask it as they run. // An action that steps while the key is held takes every key; a toggle // takes the press alone, and lets the repeats go by: // // if c.Shortcut(0, ui.KeyT) && !c.ShortcutRepeated() { // app.panel = !app.panel // } // // It is false in a frame no shortcut took a key in yet. func (_handle *Context) ShortcutRepeated() bool { _ctx := _handle.build() if _ctx == nil { return false } return _ctx.ShortcutRepeated() } // Size returns the size of the window's content in DIPs. func (_handle *Context) Size() (float32, float32) { _ctx := _handle.build() if _ctx == nil { return 0, 0 } return _ctx.Size() } // Theme returns the theme of the frame: the light or dark theme following // the system's appearance, unless SetTheme replaced it. While the children // of a Themed build, it is the Themed's theme. func (_handle *Context) Theme() *Theme { _ctx := _handle.build() if _ctx == nil { return nil } return _ctx.Theme() } // TitleBar returns the room the window controls take in a window with a // hidden title bar (mygo.WindowOptions.TitleBarStyle), whose view draws // the title bar under them: the traffic lights on macOS, the window // buttons on Linux and Windows. It is zero in other windows and in full // screen, where the controls hide. Keep clear of the controls, and let the // title bar drag the window: // // bar := c.TitleBar() // ui.Row(c).Height(max(bar.Height, 32)).Padding(0, bar.Right, 0, bar.Left).DragWindow() // // A sidebar under the controls starts below Bottom: // // ui.Column(c).Padding(bar.Bottom+8, 0, 0, 0) func (_handle *Context) TitleBar() TitleBar { _ctx := _handle.build() if _ctx == nil { return *new(TitleBar) } return _ctx.TitleBar() } // Toast shows message near the bottom of the window for a few seconds, as // the outcome of what the user just did: // // if ui.Button(c, "Save").Clicked() { // app.save() // c.Toast("Saved") // } // // A message already showing shows anew; others stack above it, three at // most. It shows for as long as the pointer rests on it. Screen readers // read it out. It is AddToast with message as the ID and the title. func (_handle *Context) Toast(message string) { _ctx := _handle.build() if _ctx == nil { return } _ctx.Toast(message) } // ToastAction shows message as Toast does, for longer, with a button of // label that runs action, as Undo after deleting, and closes the toast; // Tab reaches the button. action runs on the main thread, as the view // does, which builds the frame again after it. // // app.trash(note) // c.ToastAction("Note deleted", "Undo", func() { app.restore(note) }) func (_handle *Context) ToastAction(message string, label string, action func()) { _ctx := _handle.build() if _ctx == nil { return } _ctx.ToastAction(message, label, action) } // Vibrancy reports whether the window shows its material // (mygo.WindowOptions.Vibrancy) wherever the view draws no background: on // macOS, and on Windows 11 22H2 and later in a window created with one. // Elsewhere, what the view leaves transparent shows no material: draw a // background there instead. The root draws the theme's background unless // told otherwise; a sidebar over the material, beside opaque content: // // if c.Vibrancy() { // c.Root().Background(ui.Transparent) // } // ui.Row(c).Fill().AlignItems(ui.Stretch).Children(func() { // sidebar := ui.Column(c).Width(240) // if !c.Vibrancy() { // sidebar.Background(c.Theme().Surface) // } // sidebar.Children(func() { app.sidebar(c) }) // ui.Column(c).Grow(1).Background(c.Theme().Background).Children(func() { app.content(c) }) // }) func (_handle *Context) Vibrancy() bool { _ctx := _handle.build() if _ctx == nil { return false } return _ctx.Vibrancy() } // WindowActive reports whether the window is drawn as active: the window // the user's input goes to, as native apps draw it, while it or one of its // flyouts has the keyboard (and always as Window.SetActiveAppearance keeps // it). The built-in widgets fade their accent to gray in a window that is // not, as AppKit's do (Theme.InactiveAccent), and macOS fades the // window's material. A frame that reads it is drawn again as it changes; // draw what shows which window has the user's input in a view of your own // with it: // // icon := c.Theme().Accent // if !c.WindowActive() { // icon = c.Theme().TextMuted // } func (_handle *Context) WindowActive() bool { _ctx := _handle.build() if _ctx == nil { return false } return _ctx.WindowActive() } // WindowHidden reports whether nothing of the window shows on screen, as // the web's document.hidden: it is minimized, hidden, on another space or // desktop, or covered by other windows, as far as the system tells (see // the platform differences). A view that shows a clock, a price or what // plays stops working while it is hidden, and refreshes as it shows // again: the view builds once as it hides, and again as it shows, from // the first time it asks. Frames that only move what shows wait while it // is hidden anyway. // // app.ticker.SetPaused(c.WindowHidden()) func (_handle *Context) WindowHidden() bool { _ctx := _handle.build() if _ctx == nil { return false } return _ctx.WindowHidden() } func (_handle *Context) WriteClipboard(s string) { _ctx := _handle.build() if _ctx == nil { return } _ctx.WriteClipboard(s) } // WriteClipboardThen puts text on the clipboard as WriteClipboard does, // and done, unless nil, gets what came of it a moment later, before a // frame builds anew with what it changed, as navigator.clipboard's // writeText resolves or rejects: an error when the text did not get // there, as when another app holds the clipboard, or a browser refuses // a write the user did not act for (a press or a key, a moment before). // A copy button shows "Copied" or "Failed" with it: // // if ui.Button(c, "Copy").Clicked() { // c.WriteClipboardThen(link, func(err error) { // app.copied, app.copyFailed = err == nil, err != nil // }) // } func (_handle *Context) WriteClipboardThen(s string, done func(err error)) { _ctx := _handle.build() if _ctx == nil { return } _ctx.WriteClipboardThen(s, done) } // Zoom returns the zoom SetZoom set, 1 for none. func (_handle *Context) Zoom() float32 { _ctx := _handle.build() if _ctx == nil { return 0 } return _ctx.Zoom() } // Accordion creates sections, one above the other in a bordered box, that // fn builds with AccordionItem. Each opens and closes on its own; Up and // Down move the focus between their headers, as do Home and End. // // ui.Accordion(c, func() { // ui.AccordionItem(c, "General", &app.general, func() { ... }) // ui.AccordionItem(c, "Privacy", &app.privacy, func() { ... }) // }) // // For one section open at a time, close the others as one opens: // // for i, s := range sections { // open := app.section == i // if ui.AccordionItem(c, s.Title, &open, s.Build).Changed() { // app.section = -1 // if open { // app.section = i // } // } // } func Accordion(c *Context, fn func()) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreAccordion(_ctx, fn) _ctx.rt.endBuild() return wrapElement(_e) } // AccordionBase creates an accordion without a look: a column of // sections, each a CollapsibleBase that Item makes, opening and closing // on its own, whose headers Up and Down move the keyboard focus between, // as do Home and End. Build the sections in Root: // // acc := ui.AccordionBase(c) // acc.Root.Gap(4).Children(func() { // for i := range app.sections { // s := &app.sections[i] // item := acc.Item(&s.open) // item.Trigger.Padding(8, 12).Radius(6).Children(func() { // ui.Text(c, s.title).Grow(1) // ui.Icon(c, chevron).Rotate(180 * item.Progress()) // }) // item.Panel(func() { s.build(c) }) // } // }) // // Accordion is AccordionBase with the theme's look. func AccordionBase(c *Context) AccordionParts { _ctx := c.build() if _ctx == nil { return AccordionParts{} } _ctx.rt.beginBuild() _p := coreAccordionBase(_ctx) _ctx.rt.endBuild() return wrapAccordionParts(_p) } // AccordionItem creates a section of an Accordion: a header showing title, // which a click opens and closes, as do Enter and Space, and below it what // fn builds while *open is true. Changed reports a click. func AccordionItem(c *Context, title string, open *bool, fn func()) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreAccordionItem(_ctx, title, open, fn) _ctx.rt.endBuild() return wrapElement(_e) } // AlertDialog shows an alert over the window while *open is true, as // AppKit's: title, message, and buttons, the last of which is the default, // in the accent color, with the focus, which Enter clicks. Escape closes the // alert choosing no button, as canceling does, whatever the buttons say; a // click outside the alert does nothing. It returns the index of the button // clicked, in the frame it is, which closes the alert, AlertDismissed in // the frame Escape closes it, and -1 otherwise. An alert that must be // answered stays open by setting *open back to true on AlertDismissed. // Assistive technology sees an alert named by title and described by // message. // // switch ui.AlertDialog(c, &app.asking, "Delete “Notes”?", "You can't undo this.", "Cancel", "Delete") { // case 1: // app.delete() // } func AlertDialog(c *Context, open *bool, title string, message string, buttons ...string) int { _ctx := c.build() if _ctx == nil { return 0 } return coreAlertDialog(_ctx, open, title, message, buttons...) } // Autocomplete creates a text input editing *value, which suggests below // it those of suggestions containing what was typed, those starting with // it first: Up and Down move among them and Enter takes one, as does a // click, while Enter on none is Submitted. Changed reports a change, // typed or taken. Name it with Label. // // ui.Autocomplete(c, &app.city, cities).Label("City") func Autocomplete(c *Context, value *string, suggestions []string) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreAutocomplete(_ctx, value, suggestions) _ctx.rt.endBuild() return wrapElement(_e) } // Avatar creates a picture of a person or a thing named name: the image, // cropped to a circle, or the initials of name on a color it picks from // it, as high as twice the font size. Assistive technology sees an image // named name. func Avatar(c *Context, name string, image *Bitmap) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreAvatar(_ctx, name, image) _ctx.rt.endBuild() return wrapElement(_e) } // BackButton creates a button going back in r's history, disabled at its // start, as in the toolbar of Finder or a browser; a right click lists // the pages before, to go back several. ForwardButton goes forward again. func BackButton(c *Context, r *Router) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreBackButton(_ctx, r) _ctx.rt.endBuild() return wrapElement(_e) } // Badge creates a short text in a pill, as a count of unread messages // beside a sidebar's item. func Badge(c *Context, text string) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreBadge(_ctx, text) _ctx.rt.endBuild() return wrapElement(_e) } // Box creates a container that lays its children out in a column. func Box(c *Context) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreBox(_ctx) _ctx.rt.endBuild() return wrapElement(_e) } // Breadcrumbs creates a path of items, as Finder's path bar and AppKit's // path control, separated by chevrons: the items but the last are links, // which a click chooses, as Enter does, setting *chosen to its index, which // Changed reports. Long items shorten with an ellipsis as room runs short. // Assistive technology sees links in a navigation landmark, which Label // names, and the last item as the current page. // // path := []string{"Macintosh HD", "Users", "ada", "Documents"} // if ui.Breadcrumbs(c, path, &app.chosen).Label("Path").Changed() { // app.open(path[:app.chosen+1]) // } func Breadcrumbs(c *Context, items []string, chosen *int) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreBreadcrumbs(_ctx, items, chosen) _ctx.rt.endBuild() return wrapElement(_e) } // Button creates a button showing label. Ask Clicked whether it was // clicked; give it other content with Children and an empty label. func Button(c *Context, label string) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreButton(_ctx, label) _ctx.rt.endBuild() return wrapElement(_e) } // ButtonBase creates a button without a look: a row centering its // children that takes the keyboard focus, and reports Clicked for the // pointer, Enter and Space. Style it and give it children; Button is // ButtonBase with the theme's look. func ButtonBase(c *Context) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreButtonBase(_ctx) _ctx.rt.endBuild() return wrapElement(_e) } // Calendar creates a month's calendar choosing *date, as SwiftUI's // graphical date picker, in the window's language, its weeks starting on // the first day of the user's regional formats (Context.Region): a click chooses a day, as the arrows do while the // calendar has the focus, Page Up and Page Down or its buttons move by // months, and Home and End go to the first and the last day of the month. // Changed reports a new date, which keeps the time of day and location of // *date. Assistive technology reads the day chosen as the arrows move. // Browse makes the keys and the buttons move without choosing. func Calendar(c *Context, date *time.Time) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreCalendar(_ctx, date) _ctx.rt.endBuild() return wrapElement(_e) } // Checkbox creates a check box toggling *checked, with a label. func Checkbox(c *Context, checked *bool, label string) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreCheckbox(_ctx, checked, label) _ctx.rt.endBuild() return wrapElement(_e) } // CheckboxBase creates a check box without a look: a row that toggles // *checked when clicked, or with Space while it has the focus, which // Changed reports, and that assistive technology sees as a check box, // checked or not. Draw its box from *checked; Checkbox is CheckboxBase // with the theme's look. func CheckboxBase(c *Context, checked *bool) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreCheckboxBase(_ctx, checked) _ctx.rt.endBuild() return wrapElement(_e) } // CheckboxGroup creates a check box over the check boxes that fn builds, // indented below it, as a list of permissions: it is checked when they all // are, mixed when some are, and a click, or Space while it has the focus, // checks them all, or none when they all are. Changed reports a click. // Assistive technology sees a check box, mixed while some are checked, // and a group of the others named by label. // // ui.CheckboxGroup(c, "Notifications", func() { // ui.Checkbox(c, &app.mail, "Mail") // ui.Checkbox(c, &app.calendar, "Calendar") // }) func CheckboxGroup(c *Context, label string, fn func()) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreCheckboxGroup(_ctx, label, fn) _ctx.rt.endBuild() return wrapElement(_e) } // CheckboxState creates a check box that can be mixed, with a label: a // click, or Space while it has the focus, checks it, or unchecks it when // it is checked, setting *state, and Changed reports a click. It shows a // dash while mixed, and assistive technology sees it mixed. CheckboxGroup // is one over the check boxes it holds. func CheckboxState(c *Context, state *CheckState, label string) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreCheckboxState(_ctx, state, label) _ctx.rt.endBuild() return wrapElement(_e) } // CheckboxStateBase creates a check box without a look that can be mixed, // as a "select all" box in a table's header, checked when every row is // and mixed when some are: a row that sets *state to CheckOn when // clicked, or with Space while it has the focus, or to CheckOff when it // is CheckOn, which Changed reports, and that assistive technology sees // as a check box, checked, unchecked or mixed. Draw its box from *state; // CheckboxState is CheckboxStateBase with the theme's look. // // all := ui.CheckOff // switch n := app.selectedCount(); { // case n == len(app.rows): // all = ui.CheckOn // case n > 0: // all = ui.CheckMixed // } // cb := ui.CheckboxStateBase(c, &all).Label("Select all") // cb.Children(func() { app.box(c, all) }) // a dash while mixed // if cb.Changed() { // app.selectAll(all == ui.CheckOn) // } func CheckboxStateBase(c *Context, state *CheckState) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreCheckboxStateBase(_ctx, state) _ctx.rt.endBuild() return wrapElement(_e) } // Collapsible creates a disclosure, as SwiftUI's DisclosureGroup: label // beside an arrow, which a click opens and closes, as do Enter and Space, // showing below it what fn builds while *open is true. The arrow turns // and the content grows into view as it opens. Changed reports a click. // // ui.Collapsible(c, "Advanced", &app.advanced, func() { // ui.Checkbox(c, &app.verbose, "Verbose logging") // }) func Collapsible(c *Context, label string, open *bool, fn func()) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreCollapsible(_ctx, label, open, fn) _ctx.rt.endBuild() return wrapElement(_e) } // CollapsibleBase creates a collapsible without a look, open while *open: // its Trigger, and below it the panel Panel builds. Collapsible is // CollapsibleBase with the theme's look. func CollapsibleBase(c *Context, open *bool) CollapsibleParts { _ctx := c.build() if _ctx == nil { return CollapsibleParts{} } _ctx.rt.beginBuild() _p := coreCollapsibleBase(_ctx, open) _ctx.rt.endBuild() return wrapCollapsibleParts(_p) } // ColorPicker creates a picker of *color, as AppKit's color panel: a // square choosing the saturation, across, and the brightness, up, of the // hue its slider chooses below it, a slider of opacity, the color in hex, // which the user edits, and swatches of common colors. The arrows move // across the square while it has the focus, Up and Down changing the // brightness and Left and Right the saturation. Changed reports a new // color. func ColorPicker(c *Context, color *Color) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreColorPicker(_ctx, color) _ctx.rt.endBuild() return wrapElement(_e) } // ColorWell creates a swatch of *color that opens a ColorPicker below it, // as AppKit's color well: a click, Enter or Space opens it, and Escape or // a click outside closes it. Changed reports a new color. Assistive // technology sees a color well whose value is the color in hex; name it // with Label. func ColorWell(c *Context, color *Color) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreColorWell(_ctx, color) _ctx.rt.endBuild() return wrapElement(_e) } // Column creates a container that lays its children out from top to // bottom, stretched to its width. func Column(c *Context) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreColumn(_ctx) _ctx.rt.endBuild() return wrapElement(_e) } // Combobox creates a combobox choosing *selected among options: a field // showing the choice, whose text filters the options below it as the user // types, those starting with it first, while a click or Down shows them // all; a click showing them selects the choice, for typing to replace. // Up and Down move among them and Enter chooses, as does a click; Escape // closes them, and the text goes back to the choice when the field loses // the focus. Changed reports a new choice. Name it with Label. // // ui.Combobox(c, &app.font, fonts).Label("Font") func Combobox(c *Context, selected *string, options []string) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreCombobox(_ctx, selected, options) _ctx.rt.endBuild() return wrapElement(_e) } // ComboboxBase creates a combobox without a look: a text input editing // *text, whose popup of options, built with Popup and Item, opens below it // as the user types, clicks it or presses Down. Up and Down move among the // options, Enter or a click chooses one, which Chosen reports, and // Escape, or the input losing the focus, closes the popup. Assistive // technology sees a combo box, and follows the option the arrows are on; // tell it with AutoComplete when the options are those matching what was // typed (AutoCompleteList). // // cb := ui.ComboboxBase(c, &app.query) // cb.Input.Padding(6, 10).Border(1, gray).Label("Font") // cb.Popup(func(panel ui.Element) { // panel.Padding(4).Background(white).Border(1, gray) // for _, f := range fonts { // item := cb.Item(f).Padding(6, 10) // if item.Highlighted() { // item.Background(blue).TextColor(white) // } // item.Children(func() { ui.Text(c, f) }) // } // }) // if f, ok := cb.Chosen(); ok { // app.font = f // } // // Combobox, Autocomplete and TokenField are built on it. func ComboboxBase(c *Context, text *string) ComboboxParts { _ctx := c.build() if _ctx == nil { return ComboboxParts{} } _ctx.rt.beginBuild() _p := coreComboboxBase(_ctx, text) _ctx.rt.endBuild() return wrapComboboxParts(_p) } // ContextMenuBase gives target a context menu without a look, which shows // while *open is true, as MenuBase's: it opens where target is clicked // with the secondary button, or Control-clicked on macOS, and, while // target or an element inside it has the focus, below it when the menu // key or Shift+F10 is pressed. Build it in Popup, as MenuBase's; it has // the same keys, and assistive technology sees it so. PopoverMenu draws // its menu with these parts, in the theme's look. // // m := ui.ContextMenuBase(c, row, &app.rowMenu) // m.Popup(func(panel ui.Element) { ... }) func ContextMenuBase(c *Context, target Element, open *bool) MenuParts { _ctx := c.build() if _ctx == nil { return MenuParts{} } _ctx.rt.beginBuild() _p := coreContextMenuBase(_ctx, target.nodeFor(_ctx.rt), open) _ctx.rt.endBuild() return wrapMenuParts(_p) } // DataDragOver makes e a native destination, as DropData does, and returns // the advertised formats and operations while a matching drag is over it. // Hover never invokes a data provider. func DataDragOver(e Element, options transfer.DropOptions) (transfer.Offer, bool) { _node := e.node() if _node == nil { return *new(transfer.Offer), false } _ctx := _node.c _ = _ctx return coreDataDragOver(e.nodeFor(_ctx.rt), options) } // DateInput creates a field showing *date in the user's regional formats, // as 1/5/2026 in the United States, which a calendar below it changes. A click, Enter or Space opens the calendar, where a // click chooses a day, as do the arrows and Enter; Page Up and Page Down, // or its buttons, move by months, and Escape closes it. Changed reports a // new date, which keeps the time of day and location of *date. func DateInput(c *Context, date *time.Time) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreDateInput(_ctx, date) _ctx.rt.endBuild() return wrapElement(_e) } // DecimalInput creates a text input editing *value as an exact decimal // between lo and hi, which the arrows Up and Down, and the buttons beside // it, step by step: a NumberInput for amounts of money, which it never // rounds. *value is written with exactly the decimals of step, as // "1234.50"; lo and hi are written the same way, "" for no limit. What is // typed applies as soon as it is a number in range, with '.' before its // decimals and ',' between groups of three digits: "1,234.5" sets // "1234.50", and shows so once the input loses the focus. Text with more // decimals than step's (other than zeros), out of range or not a number // leaves *value as it was and marks the input with Error, whose message // an enclosing Field shows, until it is corrected. A value the app sets // replaces what was typed. Changed reports a new value. // // ui.DecimalInput(c, &app.amount, "0", "", "0.01") func DecimalInput(c *Context, value *string, lo string, hi string, step string) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreDecimalInput(_ctx, value, lo, hi, step) _ctx.rt.endBuild() return wrapElement(_e) } // DialogBase shows a dialog without a look over the window while *open is // true: fn styles the backdrop covering the window, which centers the // panel, and the panel, and builds the panel's content. Clicking the // backdrop or pressing Escape sets *open to false, which Dismissed // reports. It returns the panel, or nil while closed; Modal is DialogBase // with the theme's look. func DialogBase(c *Context, open *bool, fn func(backdrop Element, panel Element)) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreDialogBase(_ctx, open, func(backdrop *node, panel *node) { fn(wrapElement(backdrop), wrapElement(panel)) }) _ctx.rt.endBuild() return wrapElement(_e) } // Divider creates a thin line across its row or column. func Divider(c *Context) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreDivider(_ctx) _ctx.rt.endBuild() return wrapElement(_e) } // DragOver makes e take values of type T dragged within the window, as // Drop does, and returns the value dragged over it, for showing it would // take it. func DragOver[T any](e Element) (T, bool) { _node := e.node() if _node == nil { return *new(T), false } _ctx := _node.c _ = _ctx return coreDragOver[T](e.nodeFor(_ctx.rt)) } // Drop makes e take values of type T dragged within the window (Element.Drag) // and returns the value dropped on it since the last frame. // // if f, ok := ui.Drop[*File](folder); ok { // app.move(f, dir) // } func Drop[T any](e Element) (T, bool) { _node := e.node() if _node == nil { return *new(T), false } _ctx := _node.c _ = _ctx return coreDrop[T](e.nodeFor(_ctx.rt)) } // DropData makes e take native transfers matching options, and reports a // completed drop once, in the next frame. Decode custom formats explicitly // from the returned Data. Empty Formats accepts nothing. func DropData(e Element, options transfer.DropOptions) (transfer.Drop, bool) { _node := e.node() if _node == nil { return *new(transfer.Drop), false } _ctx := _node.c _ = _ctx return coreDropData(e.nodeFor(_ctx.rt), options) } // EditableText shows *value as a text that the user edits in place, as a // file's name in Finder: a double click on it, or Enter while it has the // focus, shows a text input of it, with the text before its extension // selected. Enter keeps what was typed, as moving the focus away does, and // Escape goes back; Changed reports a new value. // // In a List's or a Table's rows, the list keeps the focus and the text // takes none: Enter on macOS, and F2, edit the text of the row chosen, // while a double click on the row is Submitted; a click on the text of a // row already chosen edits it, once a second click would no longer make a // double click. // // ui.Table(c, &app.files, cols, len(app.names), func(row, col int) { // if ui.EditableText(c, &app.names[row]).Changed() { // app.rename(row) // } // }) func EditableText(c *Context, value *string) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreEditableText(_ctx, value) _ctx.rt.endBuild() return wrapElement(_e) } // Field creates a field: label, above the control that fn builds, or // beside it in a Form. The label names the control for assistive // technology, unless the control names itself, as a check box with its own // text does, when it names the field around it; a click on the label // focuses the control, or clicks a check box, a switch or a radio button. // Description and Error add texts below the control, which describe it: // // ui.Field(c, "Email", func() { // ui.TextInput(c, &app.email) // }).Description("For receipts.").Error(app.emailError) // // The control is the first element fn builds that takes the focus, or a // group of them, such as a RadioGroup. func Field(c *Context, label string, fn func()) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreField(_ctx, label, fn) _ctx.rt.endBuild() return wrapElement(_e) } // Fieldset creates a group of the fields that fn builds, under legend, // which names the group for assistive technology. Disabled disables them // all. In a Form, their labels line up with those of the other fields. // // ui.Fieldset(c, "Shipping", func() { // ui.Field(c, "Address", func() { ui.TextInput(c, &app.address) }) // }) func Fieldset(c *Context, legend string, fn func()) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreFieldset(_ctx, legend, fn) _ctx.rt.endBuild() return wrapElement(_e) } // FindBar creates a bar for finding text while *open is true, as Safari's // and Xcode's: a field of *query, which takes the focus as the bar opens, // how many matches there are of matches, previous and next buttons // choosing *current among them, and Done. Enter in the field goes to the // next match, Shift+Enter to the previous, as do Cmd+G and Shift+Cmd+G on // macOS, F3 and Shift+F3 elsewhere, round the ends; Escape and Done close // the bar. The app finds: it counts the matches of *query and shows match // *current, which Changed reports moving. Assistive technology hears the // count as it changes. While closed, it returns an element showing // nothing. func FindBar(c *Context, open *bool, query *string, matches int, current *int) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreFindBar(_ctx, open, query, matches, current) _ctx.rt.endBuild() return wrapElement(_e) } // Form creates a column of the fields that fn builds (Field, Fieldset), // whose labels sit in a column of their own, beside the controls, as in // macOS's forms: aligned to the right, as wide as the widest, and level // with the first line of their control. // // ui.Form(c, func() { // ui.Field(c, "Name", func() { ui.TextInput(c, &app.name) }) // ui.Field(c, "Size", func() { ui.Select(c, &app.size, sizes) }) // }) func Form(c *Context, fn func()) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreForm(_ctx, fn) _ctx.rt.endBuild() return wrapElement(_e) } // ForwardButton creates a button going forward in r's history, as // BackButton goes back. func ForwardButton(c *Context, r *Router) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreForwardButton(_ctx, r) _ctx.rt.endBuild() return wrapElement(_e) } // Grid creates a grid: its children fill its cells row by row, or go where // ColumnStart and RowStart put them, spanning ColumnSpan columns and // RowSpan rows. Columns and ColumnTracks set its columns; it adds rows as // its children need them. // // ui.Grid(c).Columns(3).Gap(12).Children(func() { // for _, p := range photos { // ui.Image(c, p).AspectRatio(1).Fit(ui.Cover) // } // }) func Grid(c *Context) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreGrid(_ctx) _ctx.rt.endBuild() return wrapElement(_e) } // GridView creates a scroll container of n items in a grid, as Photos' // library and Finder's icon view, built with item(i): as many columns as // fit items at least minWidth wide, which share the width left, and rows // height high, built only as they show, so grids of millions of items are // as fast as small ones. Gap spaces the items. // // s keeps the place and says how items are chosen, or nil: with // s.Selected, a click chooses an item, as the arrow keys do in two // dimensions while the grid has the keyboard focus, with Home, End and the // first letters of an item's Label. // // app.photos.Selected = &app.photo // ui.GridView(c, &app.photos, len(photos), 140, 120, func(i int) { // ui.Image(c, thumbs[i]).Fit(ui.Contain).Grow(1) // }).Grow(1) func GridView(c *Context, s *GridState, n int, minWidth float32, height float32, item func(i int)) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreGridView(_ctx, s, n, minWidth, height, item) _ctx.rt.endBuild() return wrapElement(_e) } // Icon creates an element showing an SVG as an icon: its shapes in the // color of the text, which it takes from its ancestors as text does // (TextColor), whatever colors the SVG has. It is as high as the font size // (FontSize), keeping the SVG's aspect ratio, unless given a size, and // does not stretch across a column. Icons are decorations that assistive // technology does not see, unless Label names them. // // ui.Row(c).Gap(6).Children(func() { // ui.Icon(c, save) // ui.Text(c, "Save") // }) func Icon(c *Context, s *SVG) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreIcon(_ctx, s) _ctx.rt.endBuild() return wrapElement(_e) } // Image creates an element showing a bitmap, or an SVG in its own colors // (with the text color for its currentColor), by default at its size as // DIPs, scaled to fit when given another size. func Image(c *Context, src ImageSource) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreImage(_ctx, src) _ctx.rt.endBuild() return wrapElement(_e) } // Link creates a text that opens url in the browser when clicked, or // Enter while it has the focus. In a page of a Router, a path without a // scheme, as "/notes/42" or "edit", goes there in the router (Push). // Inside a RichText it is a link within the paragraph; give it an empty // label and Children to style parts of its text. func Link(c *Context, label string, url string) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreLink(_ctx, label, url) _ctx.rt.endBuild() return wrapElement(_e) } // Local returns state of type T that element e keeps from frame to frame, // keyed by key among its states; init creates it the first time. Custom // widgets keep what they need with it, on the element they create. // // The element owns what init made. When a frame no longer builds it, a // value that is an io.Closer (T or *T has Close() error) is closed once, // on the main thread, after that frame, as the web aborts an // AbortController as an element is removed: a component cancels in Close // the work it started, as a streaming request, a ticker or a subscription: // // s := ui.Local(e, "stream", func() *stream { return startStream(url) }) // // An element leaving with an exit transition closes them once its exit // ended, and every element as its window closes. A nil value is not // closed, and Close's error is ignored. Keep a value the element must not // close, as one the app shares, in the app's state. func Local[T any](e Element, key any, init func() T) *T { _node := e.node() if _node == nil { return nil } _ctx := _node.c _ = _ctx return coreLocal[T](e.nodeFor(_ctx.rt), key, init) } // MenuBase creates a menu button without a look, whose menu shows while // *open is true: a button that takes the focus and opens the menu as the // pointer goes down on it, or for Enter, Space, Up or Down while it has the // focus, and closes it when pressed again. Give the trigger children, and // build the menu in Popup with Item, CheckItem, RadioItem and // SubmenuItem, and the submenus with Submenu; an item's Clicked reports // its choice, which closes the menu: // // m := ui.MenuBase(c, &app.menuOpen) // m.Trigger.Padding(6).Radius(6).Children(func() { ui.Icon(c, dots) }) // m.Popup(func(panel ui.Element) { // panel.Padding(4).Radius(8).Background(t.Background).Border(1, t.Border) // item := m.Item().Padding(6, 10).Radius(4) // if item.Highlighted() { // item.Background(t.Accent).TextColor(t.AccentText) // } // item.Children(func() { ui.Text(c, "Duplicate") }) // if item.Clicked() { // app.duplicate() // } // }) // // The menu has the keys of PopoverMenu's: it takes the focus as it opens, // on its first item when the keyboard opened it, and gives it back as it // closes; Up and Down move the highlight among its items, past those // disabled, as do Home, End and typing the first letters of an item; // Right opens a submenu and Left closes it, the other way round right to // left (Direction); Enter and Space choose an item, Escape closes the // submenu on top, and Tab and a press outside the menu close it. The // pointer highlights the item it moves onto, opening its submenu. // Assistive technology sees a menu button, expanded while its menu shows, // and a menu of items, check box items and radio items. PopoverMenuButton // draws its menu with these parts, in the theme's look. func MenuBase(c *Context, open *bool) MenuParts { _ctx := c.build() if _ctx == nil { return MenuParts{} } _ctx.rt.beginBuild() _p := coreMenuBase(_ctx, open) _ctx.rt.endBuild() return wrapMenuParts(_p) } // MenuButton creates a button showing label and an arrow, which opens a // menu below it that build fills with items, as the pointer goes down on // it or for Enter, Space or Down while it has the focus (Element.Menu): // // ui.MenuButton(c, "Sort by", func(m *ui.Menu) { // for _, by := range []string{"Name", "Date", "Size"} { // if m.Item(by).Checked(app.sort == by).Chosen() { // app.sort = by // } // } // }) // // PopoverMenuButton draws its menu in the window, with the theme's look. func MenuButton(c *Context, label string, build func(m *Menu)) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreMenuButton(_ctx, label, build) _ctx.rt.endBuild() return wrapElement(_e) } // Meter creates a bar showing value between lo and hi, as AppKit's level // indicator and the web's meter: the theme's Success color, or Warning and // Danger from the levels given, nil for none, or the levels' own colors. // Background colors its track. Assistive technology sees a level // indicator of that value; name it with Label. // // ui.Meter(c, app.disk.Used, 0, app.disk.Size, &ui.MeterLevels{Warning: 0.8 * size, Critical: 0.95 * size}).Label("Disk") func Meter(c *Context, value float64, lo float64, hi float64, levels *MeterLevels) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreMeter(_ctx, value, lo, hi, levels) _ctx.rt.endBuild() return wrapElement(_e) } // Modal shows a dialog built by fn over a dimmed window while *open is // true; clicking outside it or pressing Escape sets *open to false, which // Dismissed reports. func Modal(c *Context, open *bool, fn func()) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreModal(_ctx, open, fn) _ctx.rt.endBuild() return wrapElement(_e) } // NativeView shows a view of the platform, a value of a native module's // interface that embeds native.View (an NSView on macOS), in the element's // content box, as WebView shows a web view: it has no size of its own and // takes its size from layout, it is cut to the element's Radius, and what // paints after it shows over it, its children first. Make the view once, // outside the view function, and show it from there: // // ui.NativeView(c, app.player).Fill().Children(func() { // ui.Text(c, caption).Absolute().Left(24).Bottom(24) // }) // // The view takes the pointer where it shows, and the keyboard once // clicked or tabbed into, as any view of the platform. A view the frame // does not build hides and keeps its state; one closed leaves the window. // Where views of the platform cannot show, as in browsers, the element // shows nothing. // // v is nil where the module has no implementation, its constructor having // returned errors.ErrUnsupported: the element is then a plain box, which // paints its background and children, so a view can show something else // in the view's place. func NativeView(c *Context, v PlatformView) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreNativeView(_ctx, v) _ctx.rt.endBuild() return wrapElement(_e) } // NewRecorder returns a Recorder of view, in frames of the size o gives. func NewRecorder(view func(c *Context), o RecorderOptions) *Recorder { return coreNewRecorder(func(c *context) { view(makeContext(c)) }, o) } // NewTester starts testing view in a window of width×height DIPs. Two // elements given one key under one parent make it panic where the second // was given, as apps only log it. func NewTester(view func(c *Context), width int, height int) *Tester { return coreNewTester(func(c *context) { view(makeContext(c)) }, width, height) } // NewTesterWith starts testing view in a window of width×height DIPs, as // NewTester does, with the desktop's settings of o from the first frame: // // tt := ui.NewTesterWith(view, 400, 300, ui.TesterOptions{Preferences: ui.Preferences{ReduceMotion: true}}) func NewTesterWith(view func(c *Context), width int, height int, o TesterOptions) *Tester { return coreNewTesterWith(func(c *context) { view(makeContext(c)) }, width, height, o) } // NumberInput creates a text input editing *value as a number between lo // and hi, which the arrows Up and Down, and the buttons beside it, step // by step. What is typed applies as soon as it is a number in range, and // shows rounded to the decimals of step once the input loses the focus. // Changed reports a new value. // // ui.NumberInput(c, &app.copies, 1, 99, 1) func NumberInput(c *Context, value *float64, lo float64, hi float64, step float64) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreNumberInput(_ctx, value, lo, hi, step) _ctx.rt.endBuild() return wrapElement(_e) } // Outline creates a list of items in a tree, as AppKit's outline view and // SwiftUI's List of children: roots at the top, and below each item open // its children, indented, which children returns, nil for an item without // any. A click on an item's arrow opens or closes it, with all its // children's children with Option (Alt). row builds the content of an // item's row, after its arrow; Gap, Padding and the rest are a List's. // // The outline builds only the rows in view, as a List does. It walks the // open items in every frame, unless s.Generation tells it when children // changes, which keeps trees of any size as fast as small ones. With // s.List.Selected or Selection, rows are chosen as a List's, and while // the outline has the focus, Right opens the item chosen or goes to its // first child, and Left closes it or goes to its parent, with Option on // macOS and Shift elsewhere, as in GTK, opening and closing all inside. // // app.files.List.Selected = &app.file // ui.Outline(c, &app.files, []string{"/"}, func(dir string) []string { // return app.children[dir] // nil for files // }, func(path string) { // ui.Text(c, filepath.Base(path)) // }).Grow(1) func Outline[K comparable](c *Context, s *OutlineState[K], roots []K, children func(arg0 K) []K, row func(item K)) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreOutline[K](_ctx, s, roots, children, row) _ctx.rt.endBuild() return wrapElement(_e) } // OutlineTable creates an outline whose rows are a Table's, as AppKit's // outline view with columns: the first of columns shows the items' arrows, // indented as they are deep, before what cell builds. It takes the // columns, the sort and the keys of a Table, and those of an Outline. // // ui.OutlineTable(c, &app.files, cols, roots, children, func(path string, col int) { // switch col { // case 0: // ui.Text(c, filepath.Base(path)).SingleLine() // case 1: // ui.Text(c, app.size(path)) // } // }) func OutlineTable[K comparable](c *Context, s *OutlineState[K], columns []TableColumn, roots []K, children func(arg0 K) []K, cell func(item K, col int)) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreOutlineTable[K](_ctx, s, columns, roots, children, cell) _ctx.rt.endBuild() return wrapElement(_e) } // Overlay builds fn's elements above the rest of the window. Place them // with Absolute, Left and Top, in DIPs relative to the window, or beside // another element with AttachTo. Each, as it goes with the focus in it, // gives the focus back to the element that had it as it came. Built inside // the children of a Themed, they take its theme. func Overlay(c *Context, fn func()) { _ctx := c.build() if _ctx == nil { return } coreOverlay(_ctx, fn) } // Popover shows fn's elements in a panel below anchor while *open is // true; clicking outside it or pressing Escape sets *open to false, which // Dismissed reports. func Popover(c *Context, anchor Element, open *bool, fn func()) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := corePopover(_ctx, anchor.nodeFor(_ctx.rt), open, fn) _ctx.rt.endBuild() return wrapElement(_e) } // PopoverBase shows a panel without a look below anchor while *open is // true: fn styles the panel and builds its content. Pressing outside the // panel and the anchor, or Escape, sets *open to false, which Dismissed // reports; the press goes on to what is under the pointer, as with the // web's popovers. It starts at the anchor's start: its left, or its right // right to left (Direction). Where there is // no room below the anchor, the panel shows above it; a top margin keeps // it apart from the anchor on either side. fn may place it elsewhere with // AttachTo, as after the anchor: // // panel.AttachTo(anchor, ui.AnchorEnd, ui.AnchorStart).MarginStart(6) // // It returns the panel, or nil while closed; Popover is PopoverBase with // the theme's look. func PopoverBase(c *Context, anchor Element, open *bool, fn func(panel Element)) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := corePopoverBase(_ctx, anchor.nodeFor(_ctx.rt), open, func(panel *node) { fn(wrapElement(panel)) }) _ctx.rt.endBuild() return wrapElement(_e) } // PopoverMenuButton creates a button showing label and an arrow, as // MenuButton does, whose menu MyGo draws in the window with the theme's // look, as PopoverMenu draws a context menu (Element.PopoverMenuButton): // // ui.PopoverMenuButton(c, "Sort by", func(m *ui.Menu) { // for _, by := range []string{"Name", "Date", "Size"} { // if m.Item(by).Radio(app.sort == by).Chosen() { // app.sort = by // } // } // }) // // Its options place the menu and open it from the app, as // Element.PopoverMenuButton's do. func PopoverMenuButton(c *Context, label string, build func(m *Menu), options ...PopoverMenuButtonOptions) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := corePopoverMenuButton(_ctx, label, build, options...) _ctx.rt.endBuild() return wrapElement(_e) } // PrimaryButton creates a button in the accent color, for the main action. func PrimaryButton(c *Context, label string) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := corePrimaryButton(_ctx, label) _ctx.rt.endBuild() return wrapElement(_e) } // PrimarySplitButton creates a split button (SplitButton) in the accent // color, for the main action, as PrimaryButton is. func PrimarySplitButton(c *Context, label string) SplitButtonParts { _ctx := c.build() if _ctx == nil { return SplitButtonParts{} } _ctx.rt.beginBuild() _p := corePrimarySplitButton(_ctx, label) _ctx.rt.endBuild() return wrapSplitButtonParts(_p) } // Progress creates a progress bar filled to value between 0 and 1; a // negative value shows activity of unknown length. It fills from its // start: the right right to left (Direction). Reverse fills it from the // other side. It fills in the accent color, or the color TextColor gives // it, as a quota bar in a product's own color, over a track in the // theme's Border color, or the one Background gives it. // // ui.Progress(c, app.used/app.quota).TextColor(brand).Label("Storage") func Progress(c *Context, value float64) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreProgress(_ctx, value) _ctx.rt.endBuild() return wrapElement(_e) } // Radio creates a radio button that selects value into *selected, with a // label. func Radio[T comparable](c *Context, selected *T, value T, label string) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreRadio[T](_ctx, selected, value, label) _ctx.rt.endBuild() return wrapElement(_e) } // RadioBase creates a radio button without a look: a row that selects // value into *selected when clicked, or with Space while it has the // focus, which Changed reports, and that assistive technology sees as a // radio button, on when *selected is value. Radio is RadioBase with the // theme's look. func RadioBase[T comparable](c *Context, selected *T, value T) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreRadioBase[T](_ctx, selected, value) _ctx.rt.endBuild() return wrapElement(_e) } // RadioGroup creates a column of the radio buttons that fn builds (Radio, // RadioBase), which are one stop of Tab: Tab goes to the one chosen, and // the arrows choose among them, as do Home and End. Assistive technology // sees a radio group; name it with Label. Make it a row with Row. // // ui.RadioGroup(c, func() { // for _, size := range []string{"Small", "Medium", "Large"} { // ui.Radio(c, &app.size, size, size) // } // }).Label("Size") func RadioGroup(c *Context, fn func()) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreRadioGroup(_ctx, fn) _ctx.rt.endBuild() return wrapElement(_e) } // RangeSlider creates a slider of two knobs setting *low and *high between // lo and hi, as a price range: each knob takes the focus, which Tab moves // between, and the arrows, Home and End move it while it has the focus; // a press on the track moves the knob nearest to it. A step above 0 snaps // the values to lo and multiples of step from it, with tick marks. Changed // reports a new value. Assistive technology sees two sliders, named by // the RangeSlider's Label and "minimum" and "maximum". func RangeSlider(c *Context, low *float64, high *float64, lo float64, hi float64, step float64) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreRangeSlider(_ctx, low, high, lo, hi, step) _ctx.rt.endBuild() return wrapElement(_e) } // Rating creates a row of max stars, as AppKit's rating level indicator, // of which *value are filled: a click on a star sets it, a click on the // star set clears it, and the arrows, Home and End change it while the // rating has the focus. Changed reports a new value. Assistive technology // sees a slider from 0 to max; name it with Label. func Rating(c *Context, value *int, max int) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreRating(_ctx, value, max) _ctx.rt.endBuild() return wrapElement(_e) } // Render draws a frame of view in a window of width×height DIPs at scale // device pixels per DIP, without a window: for snapshots and tests. func Render(view func(c *Context), width int, height int, scale float32) *image.RGBA { return coreRender(func(c *context) { view(makeContext(c)) }, width, height, scale) } // RichText creates a text whose spans differ in style, over the style of // the text, which its methods and the elements around it set as for Text: // // ui.RichText(c, // ui.Span{Text: "Saved "}, // ui.Span{Text: "report.pdf", Weight: 600}, // ui.Span{Text: " to "}, // ui.Span{Text: "Documents", Color: t.Accent, Underline: true}, // ) // // The spans wrap together as one paragraph, or several at newlines. // // Text elements built in its Children (Text, Link, RichText) continue the // paragraph after its spans, as HTML's inline elements do: each styles its // own text over the paragraph's, and keeps its interaction (Clicked, // Hovered, the focus, a Tooltip, assistive technology) with its words as // its area. A link in a sentence: // // ui.RichText(c).Children(func() { // ui.Text(c, "Read ") // ui.Link(c, "the guide", url) // ui.Text(c, " to get started.") // }) // // Only text elements go inside a text, and their sizes, padding, borders // and corners do not apply; a background highlights their text. func RichText(c *Context, spans ...Span) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreRichText(_ctx, spans...) _ctx.rt.endBuild() return wrapElement(_e) } // Row creates a container that lays its children out from left to right, // centered vertically. func Row(c *Context) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreRow(_ctx) _ctx.rt.endBuild() return wrapElement(_e) } // Scroll creates a container that scrolls its children vertically. Give // it a size, or Grow it within its parent. func Scroll(c *Context) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreScroll(_ctx) _ctx.rt.endBuild() return wrapElement(_e) } // ScrollBoth creates a container that scrolls its children both ways, as // a canvas, a wide table or code does. Give it a size, or Grow it within // its parent. func ScrollBoth(c *Context) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreScrollBoth(_ctx) _ctx.rt.endBuild() return wrapElement(_e) } // ScrollHorizontal creates a row that scrolls its children horizontally. func ScrollHorizontal(c *Context) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreScrollHorizontal(_ctx) _ctx.rt.endBuild() return wrapElement(_e) } // SearchField creates a field for searching, editing *query: a magnifying // glass, the text, and a button clearing it while it holds any, as Escape // does then. Enter is its Submitted, and Changed reports a change. It // shows Search while empty, or what Placeholder sets, and assistive // technology sees a search field; name it with Label. // // if ui.SearchField(c, &app.query).Label("Search mail").Changed() { // app.filter() // } func SearchField(c *Context, query *string) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreSearchField(_ctx, query) _ctx.rt.endBuild() return wrapElement(_e) } // Segmented creates a segmented control showing labels, of which // *selected is the index of the one chosen, as a switch between views: a // click chooses a segment, as do the arrows while it has the focus, and // Changed reports a new choice. Assistive technology sees a radio group; // name it with Label. For icons, build the segments with SegmentedBase. // Its segments are as wide as their labels; FillEqually makes it as wide // as its parent, its segments sharing the width. // // ui.Segmented(c, &app.view, "List", "Grid").Label("View") func Segmented(c *Context, selected *int, labels ...string) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreSegmented(_ctx, selected, labels...) _ctx.rt.endBuild() return wrapElement(_e) } // SegmentedBase creates a segmented control of n segments without a look, // of which *selected is the index of the one chosen: a radio group (see // RadioGroup) whose radio buttons are the segments, built in Track with // Segment. Track's Changed reports a new choice. Segmented is // SegmentedBase with the theme's look. func SegmentedBase(c *Context, selected *int, n int) SegmentedParts { _ctx := c.build() if _ctx == nil { return SegmentedParts{} } _ctx.rt.beginBuild() _p := coreSegmentedBase(_ctx, selected, n) _ctx.rt.endBuild() return wrapSegmentedParts(_p) } // Select creates a drop-down choosing one of options into *selected. func Select(c *Context, selected *string, options []string) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreSelect(_ctx, selected, options) _ctx.rt.endBuild() return wrapElement(_e) } // SelectBase creates a select without a look: a trigger that opens a // popup of options, which choose *selected. With the focus on the // trigger, the arrows open the popup and move among its options, past // those disabled, as do Home and End; Enter and Space choose one, and // Escape closes it; the trigger's Changed reports a new choice. Give the // trigger children showing the choice, and build the options in Popup // with Item: // // sel := ui.SelectBase(c, &app.size) // sel.Trigger.Padding(6, 10).Border(1, gray).Children(func() { // ui.Text(c, app.size) // }) // sel.Popup(func(panel ui.Element) { // panel.Padding(4).Background(white).Border(1, gray) // for _, size := range sizes { // item := sel.Item(size).Padding(6, 10) // if item.Highlighted() { // item.Background(blue).TextColor(white) // } // item.Children(func() { ui.Text(c, size) }) // } // }) // // Select is SelectBase with the theme's look. func SelectBase[T comparable](c *Context, selected *T) SelectParts[T] { _ctx := c.build() if _ctx == nil { return SelectParts[T]{} } _ctx.rt.beginBuild() _p := coreSelectBase[T](_ctx, selected) _ctx.rt.endBuild() return wrapSelectParts[T](_p) } // SelectBaseOpen is SelectBase whose popup shows while *open, a flag the // caller owns, as PopoverBase's: the select sets it as it opens and // closes, and the caller may set it too, as typing on the closed trigger // opens the popup, or Tab moving on closes it. The highlight starts on the // choice each time the popup opens. Owning the flag, the caller can keep // the popup a little longer as it closes, to shrink it back into the // trigger. func SelectBaseOpen[T comparable](c *Context, selected *T, open *bool) SelectParts[T] { _ctx := c.build() if _ctx == nil { return SelectParts[T]{} } _ctx.rt.beginBuild() _p := coreSelectBaseOpen[T](_ctx, selected, open) _ctx.rt.endBuild() return wrapSelectParts[T](_p) } // Sidebar creates a sidebar of the sections and the items that fn builds // (SidebarSection, SidebarItem), as Finder's and Mail's, scrolling when // they do not fit: a click chooses an item, whose ID *selected holds, and // while the sidebar has the focus, Up and Down choose among its items, as // do Home, End and typing the first letters of an item. It is one stop of // Tab, and Changed reports a new choice. Give it a width: // // ui.Sidebar(c, &app.mailbox, func() { // ui.SidebarSection(c, "Mailboxes", &app.mailboxes, func() { // ui.SidebarItem(c, "inbox", inboxIcon, "Inbox").Children(func() { // ui.Badge(c, "12") // }) // ui.SidebarItem(c, "sent", sentIcon, "Sent") // }) // }).Width(220) // // Assistive technology sees a tree, whose sections hold their items. func Sidebar(c *Context, selected *string, fn func()) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreSidebar(_ctx, selected, fn) _ctx.rt.endBuild() return wrapElement(_e) } // SidebarItem creates an item of a Sidebar choosing id, showing label // after icon, nil for none. Add to it with Children, as a Badge. func SidebarItem(c *Context, id string, icon *SVG, label string) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreSidebarItem(_ctx, id, icon, label) _ctx.rt.endBuild() return wrapElement(_e) } // SidebarSection creates a section of a Sidebar under title, holding the // items fn builds while *open is true, as Finder's: a click on the title // shows and hides them, as does its arrow, which shows as the pointer // rests on the title. A nil open keeps the section open. func SidebarSection(c *Context, title string, open *bool, fn func()) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreSidebarSection(_ctx, title, open, fn) _ctx.rt.endBuild() return wrapElement(_e) } // Slider creates a slider setting *value between lo and hi. func Slider(c *Context, value *float64, lo float64, hi float64) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreSlider(_ctx, value, lo, hi) _ctx.rt.endBuild() return wrapElement(_e) } // SliderBase creates a slider without a look: dragging across its // content box, within its padding, sets *value between lo and hi, as do // the arrows, Home and End while it has the focus, by a hundredth of the // range unless Step says otherwise; Changed reports a new value, and // assistive technology sees a slider of that range. Draw its track and // thumb where (*value-lo)/(hi-lo) puts them, and pad it by half the // thumb's width to keep the thumb inside it. Right to left // (Context.Direction), lo is at the right of the content box, as the // arrows go: draw it mirrored. // // s := ui.SliderBase(c, &app.volume, 0, 100).Height(24).PaddingX(12) // s.Draw(func(p *ui.Painter, r ui.Rect) { // x := r.X + 12 + (r.W-24)*float32(app.volume/100) // p.Fill(ui.Rect{X: r.X + 12, Y: r.Y + 10, W: r.W - 24, H: 4}, gray, 2) // p.Fill(ui.Rect{X: x - 12, Y: r.Y, W: 24, H: 24}, blue, 12) // }) // // Vertical makes it go up from lo at the bottom. Slider is SliderBase with // the theme's look. func SliderBase(c *Context, value *float64, lo float64, hi float64) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreSliderBase(_ctx, value, lo, hi) _ctx.rt.endBuild() return wrapElement(_e) } // Spacer creates an empty element that takes the free space of its row or // column, pushing its siblings apart. func Spacer(c *Context) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreSpacer(_ctx) _ctx.rt.endBuild() return wrapElement(_e) } // Spinner creates an indicator of work of unknown length, as AppKit's // spinning progress indicator: spokes turning, as high as the font size, // in the theme's muted text color, or the color TextColor gives it, as one // on a chosen row of a list needs. Assistive technology sees a progress // indicator of unknown length; name it with Label. func Spinner(c *Context) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreSpinner(_ctx) _ctx.rt.endBuild() return wrapElement(_e) } // Split lays out first and second side by side, with a divider between // them that the user drags to resize them, or moves with the arrows once // it has the keyboard focus: *size is the width of first, which the // divider keeps 40 DIPs from either edge. With less room than that, first // gives way, keeping *size for when there is room again. Changed reports a // move. Right to left (Direction), first is on the right. SplitReset makes // a double click on the divider put first back at a size the app chooses. // // ui.Split(c, &app.sidebar, app.files, app.editor).Fill() func Split(c *Context, size *float32, first func(), second func()) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreSplit(_ctx, size, first, second) _ctx.rt.endBuild() return wrapElement(_e) } // SplitButton creates a button joined to an arrow that opens a menu of // related actions, as Save beside Save As…: one control drawn as Button // is, with the face and the border its two segments share and a line // between them, each lighting up apart as the pointer hovers and presses // it. Button, its leading segment, shows label and does the action; give // Arrow, its trailing segment, the menu with Menu, or with // PopoverMenuButton for one MyGo draws in the window, which opens below // the arrow as a menu button's does: // // save := ui.SplitButton(c, "Save") // save.Arrow.Menu(func(m *ui.Menu) { // if m.Item("Save As…").Chosen() { // app.saveAs() // } // }) // if save.Button.Clicked() { // app.save() // } // // It is one stop of Tab, and Left and Right move the focus between its // segments, the other way round right to left, where the arrow is on the // left. Enter and Space click Button while it has the focus, and open the // menu while Arrow has it, as do Up and Down; Alt+Down opens it from // Button too. Assistive technology sees a group of a button and a menu // button, named More options until Arrow's Label names it, expanded while // its menu shows. Disabled on Group disables the whole control, and on // Button the action alone, leaving the menu. In a toolbar it takes no face // of its own until hovered, as the toolbar's buttons. PrimarySplitButton // is one in the accent color. func SplitButton(c *Context, label string) SplitButtonParts { _ctx := c.build() if _ctx == nil { return SplitButtonParts{} } _ctx.rt.beginBuild() _p := coreSplitButton(_ctx, label) _ctx.rt.endBuild() return wrapSplitButtonParts(_p) } // SplitPercent is Split with *p the percentage of the room first takes, // from 0 to 100, so that both panes grow and shrink with the room, in // proportion. // // ui.SplitPercent(c, &app.sidebarPercent, app.files, app.editor).Fill() func SplitPercent(c *Context, p *float32, first func(), second func()) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreSplitPercent(_ctx, p, first, second) _ctx.rt.endBuild() return wrapElement(_e) } // SplitVertical is Split with first above second, *size its height. func SplitVertical(c *Context, size *float32, first func(), second func()) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreSplitVertical(_ctx, size, first, second) _ctx.rt.endBuild() return wrapElement(_e) } // SplitVerticalPercent is SplitPercent with first above second. func SplitVerticalPercent(c *Context, p *float32, first func(), second func()) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreSplitVerticalPercent(_ctx, p, first, second) _ctx.rt.endBuild() return wrapElement(_e) } // StepSlider creates a slider setting *value to lo or a multiple of step // from it, up to hi, with a tick mark at each, as AppKit's sliders with // tick marks: dragging snaps to them, and the arrows step by step. func StepSlider(c *Context, value *float64, lo float64, hi float64, step float64) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreStepSlider(_ctx, value, lo, hi, step) _ctx.rt.endBuild() return wrapElement(_e) } // Stepper creates a pair of arrows changing *value by step between lo and // hi, as AppKit's stepper beside a field: a click on an arrow steps up or // down, as do Up and Down while the stepper has the focus, and holding an // arrow keeps stepping. Changed reports a new value. Assistive technology // sees a spin button; name it with Label. func Stepper(c *Context, value *float64, lo float64, hi float64, step float64) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreStepper(_ctx, value, lo, hi, step) _ctx.rt.endBuild() return wrapElement(_e) } // Switch creates a switch toggling *on. func Switch(c *Context, on *bool) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreSwitch(_ctx, on) _ctx.rt.endBuild() return wrapElement(_e) } // SwitchBase creates a switch without a look: CheckboxBase, which // assistive technology sees as a switch. Switch is SwitchBase with the // theme's look. func SwitchBase(c *Context, on *bool) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreSwitchBase(_ctx, on) _ctx.rt.endBuild() return wrapElement(_e) } // Table creates a table of n rows under a header of columns, whose rows // are a List's: it builds only those in view, cell building the content // of a row's column, usually a Text. Rows are as high as their tallest // cell, and at least as high as the header. // // s keeps the place of the rows and says how they behave, as a List's, or // nil: with s.Selected, a click chooses a row, as Up, Down, Home and End // do while the table has the keyboard focus, Changed reports a new choice, // and Submitted a double click or Enter on it; with s.Selection, the user // chooses several. A row s.Header names spans // every column, cell building it as column 0, and stays at the top while // the rows of its section scroll under it. // // The user resizes columns by dragging the edges of their headers, and // moves them by dragging the headers, which s.Columns keeps; Changed // reports the new layout once the user lets go, or once a double click // fits a column to its cells, for the app to save. Columns wider // than the table scroll sideways, the header with them. With s.Sort, a // click on the header of a Sortable column sorts the rows by it; with // s.SortBy, a Cmd-click or a Shift-click sorts by it after the others; // with s.HeaderMenu, the header has a context menu. // // cols := []ui.TableColumn{{Title: "Name", Sortable: true}, {Title: "Size", Width: 90, Align: ui.End, Sortable: true}} // app.files.Selected, app.files.Sort = &app.file, &app.sort // if ui.Table(c, &app.files, cols, len(files), func(row, col int) { // f := files[row] // switch col { // case 0: // ui.Text(c, f.Name).SingleLine() // case 1: // ui.Text(c, f.Size()) // } // }).Grow(1).Submitted() { // app.open(files[app.file]) // } func Table(c *Context, s *ListState, columns []TableColumn, n int, cell func(row int, col int)) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreTable(_ctx, s, columns, n, cell) _ctx.rt.endBuild() return wrapElement(_e) } // Tabs creates a row of tabs showing labels, of which *selected is the // index of the one chosen. A click chooses a tab, as do the arrows, Home // and End while one has the keyboard focus, which follows the choice: // // ui.Tabs(c, &app.tab, "General", "Appearance", "Advanced") // switch app.tab { // case 0: // app.general(c) // … // } // // Changed reports a new choice. func Tabs(c *Context, selected *int, labels ...string) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreTabs(_ctx, selected, labels...) _ctx.rt.endBuild() return wrapElement(_e) } // TabsBase creates a list of n tabs without a look, of which *selected is // the index of the one chosen. A click chooses a tab, as do the arrows, // Home and End while one has the keyboard focus, which follows the // choice, past the tabs disabled; List's Changed reports a new choice. // Build the tabs in List with Tab: // // tabs := ui.TabsBase(c, &app.tab, len(names)) // tabs.List.Gap(4).Children(func() { // for i, name := range names { // tab := tabs.Tab(i).Padding(6, 12).Radius(6) // if i == app.tab { // tab.Background(c.Theme().Surface) // } // tab.Children(func() { ui.Text(c, name) }) // } // }) // // Tabs is TabsBase with the theme's look. func TabsBase(c *Context, selected *int, n int) TabsParts { _ctx := c.build() if _ctx == nil { return TabsParts{} } _ctx.rt.beginBuild() _p := coreTabsBase(_ctx, selected, n) _ctx.rt.endBuild() return wrapTabsParts(_p) } // Text creates a text, which wraps at the width it gets. func Text(c *Context, s string) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreText(_ctx, s) _ctx.rt.endBuild() return wrapElement(_e) } // TextArea creates a multi-line text input editing *value. func TextArea(c *Context, value *string) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreTextArea(_ctx, value) _ctx.rt.endBuild() return wrapElement(_e) } // TextAreaBase creates a multi-line text input without a look, editing // *value: TextArea without its padding, background, border and corners. func TextAreaBase(c *Context, value *string) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreTextAreaBase(_ctx, value) _ctx.rt.endBuild() return wrapElement(_e) } // TextAreaBuffer creates a multiline control editing indexed storage. // Ordinary edits and native queries never materialize the whole document. // Layout retains the paragraphs in view, as TextArea does. func TextAreaBuffer(c *Context, value *TextBuffer) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreTextAreaBuffer(_ctx, value) _ctx.rt.endBuild() return wrapElement(_e) } func TextAreaBufferBase(c *Context, value *TextBuffer) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreTextAreaBufferBase(_ctx, value) _ctx.rt.endBuild() return wrapElement(_e) } // TextInput creates a single-line text input editing *value. func TextInput(c *Context, value *string) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreTextInput(_ctx, value) _ctx.rt.endBuild() return wrapElement(_e) } // TextInputBase creates a single-line text input without a look, editing // *value: TextInput without its padding, background, border and // corners. func TextInputBase(c *Context, value *string) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreTextInputBase(_ctx, value) _ctx.rt.endBuild() return wrapElement(_e) } // TextInputBuffer creates a single-line control editing indexed storage. // It shares TextInput's selection, composition, undo and styling behavior. func TextInputBuffer(c *Context, value *TextBuffer) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreTextInputBuffer(_ctx, value) _ctx.rt.endBuild() return wrapElement(_e) } // TextInputBufferBase and TextAreaBufferBase are the unstyled buffer controls. func TextInputBufferBase(c *Context, value *TextBuffer) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreTextInputBufferBase(_ctx, value) _ctx.rt.endBuild() return wrapElement(_e) } // Textf creates a text formatted with fmt.Sprintf. func Textf(c *Context, format string, args ...any) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreTextf(_ctx, format, args...) _ctx.rt.endBuild() return wrapElement(_e) } // Themed creates a column whose children build with t, as SetTheme has // the whole window build: the widgets inside take their colors and metrics // (Spacing, Radius, FontSize) from t, Context.Theme returns t while they // build and Painter.Theme while they paint, and the popovers, menus, // tooltips and dialogs they open take t too. The column paints t's // Background, and the text inside takes t's Text color, FontSize and Font, // as the root has the window's theme's; Background(ui.Transparent) keeps // what is behind it instead. The root, and what is built after the column, // keep the window's theme. Light beside dark, as a theme picker previews // them: // // ui.Row(c).Fill().AlignItems(ui.Stretch).Children(func() { // for _, t := range []*ui.Theme{ui.LightTheme(), ui.DarkTheme()} { // ui.Themed(c, t).Grow(1).Padding(16).Gap(8).Children(func() { // ui.Text(c, "Preview") // ui.Button(c, "OK") // }) // } // }) // // A nil t makes it a Column. func Themed(c *Context, t *Theme) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreThemed(_ctx, t) _ctx.rt.endBuild() return wrapElement(_e) } // TimeInput creates a field of the time of day of *tm, in the hour cycle // of the user's regional formats (Context.Region): 15:04, or 3:04 PM with // the window's language's names of the halves of the day, before the // hours where the language writes them so (下午3:04). Its hours, minutes // and half of the day each take the focus, as the segments of AppKit's // date picker: Up and Down step the one with the focus round the clock, // digits typed set it, going on to the minutes once the hours are typed, // the first letter of a half of the day chooses it, and Left and Right // move between them. Changed reports a new time, which keeps the date and // the location of *tm. Assistive technology sees spin buttons, named // after the field's Label and "hours", "minutes" and "AM/PM". It reads // left to right in an interface laid out right to left too, as times are // written there. // // ui.TimeInput(c, &app.alarm).Label("Alarm") func TimeInput(c *Context, tm *time.Time) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreTimeInput(_ctx, tm) _ctx.rt.endBuild() return wrapElement(_e) } // ToastBase creates the toast t without a look, in the viewport of // ToastViewportBase. func ToastBase(c *Context, t Toast) ToastParts { _ctx := c.build() if _ctx == nil { return ToastParts{} } _ctx.rt.beginBuild() _p := coreToastBase(_ctx, t) _ctx.rt.endBuild() return wrapToastParts(_p) } // ToastViewportBase builds the window's toasts without a look, in place of // the theme's: fn styles viewport, a column covering the window that the // pointer goes through, which holds them at its bottom, and builds each of // toasts with ToastBase, giving it the look of its Type and Data. toasts // are those showing, the newest three, oldest first. Call it once in the // view, wherever. Toasts in the bottom right corner: // // ui.ToastViewportBase(c, func(viewport ui.Element, toasts []ui.Toast) { // viewport.Padding(16).AlignItems(ui.End).Gap(8) // for _, t := range toasts { // toast := ui.ToastBase(c, t) // toast.Root.Row().Gap(12).Padding(10, 14).Radius(8).Background(surface) // toast.Root.Children(func() { // ui.Text(c, t.Title).Grow(1) // toast.CloseButton().Label("Close").Children(func() { ui.Icon(c, x) }) // }) // } // }) // // The time of the toasts stops while the pointer rests on viewport or the // keyboard focus is in it with the window's, and runs on while the window // is in the background. viewport stays while no toast shows, for the // last one to go with an exit transition. It returns viewport. func ToastViewportBase(c *Context, fn func(viewport Element, toasts []Toast)) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreToastViewportBase(_ctx, func(viewport *node, toasts []Toast) { fn(wrapElement(viewport), toasts) }) _ctx.rt.endBuild() return wrapElement(_e) } // Toggle creates a button that stays pressed while *on, as Bold in an // editor's toolbar: a click presses it or lets it go, as does Space while // it has the focus, and Changed reports a change. Give it other content, // such as an icon, with Children and an empty label, and name it with // Label: // // ui.Toggle(c, &app.bold, "").Label("Bold").Children(func() { ui.Icon(c, boldIcon) }) func Toggle(c *Context, on *bool, label string) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreToggle(_ctx, on, label) _ctx.rt.endBuild() return wrapElement(_e) } // ToggleBase creates a toggle button without a look: a row that turns *on // over when clicked, or with Space while it has the focus, which Changed // reports, and that assistive technology sees as a toggle button, pressed // while *on. Toggle is ToggleBase with the theme's look. func ToggleBase(c *Context, on *bool) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreToggleBase(_ctx, on) _ctx.rt.endBuild() return wrapElement(_e) } // ToggleGroup creates a row of the toggles and buttons that fn builds, // drawn joined as the segments of one control, as Bold, Italic and // Underline. They are one stop of Tab, among which the arrows move the // focus, as in a toolbar; name the group with Label. // // ui.ToggleGroup(c, func() { // ui.Toggle(c, &app.bold, "B") // ui.Toggle(c, &app.italic, "I") // }).Label("Style") func ToggleGroup(c *Context, fn func()) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreToggleGroup(_ctx, fn) _ctx.rt.endBuild() return wrapElement(_e) } // TokenField creates a field of tokens, as of tags or the recipients of a // mail: *tokens shows as chips, each with a button taking it out, before // an input where Enter or a comma adds what was typed, and Backspace in // it while empty takes out the last. The suggestions containing what was // typed show below it, those not already tokens: Up and Down move among // them, and Enter or a click adds one. Changed reports a change; name it // with Label. Query binds what is being typed, for suggestions the app // looks up and matches itself as the user types. // // ui.TokenField(c, &app.tags, allTags).Label("Tags") func TokenField(c *Context, tokens *[]string, suggestions []string) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreTokenField(_ctx, tokens, suggestions) _ctx.rt.endBuild() return wrapElement(_e) } // Toolbar creates a row of the controls that fn builds, as along the top // of a window: buttons, toggles, toggle groups, segmented controls and // menu buttons, which take no face of their own until hovered. It is one // stop of Tab, and Left and Right move the focus among its controls, Home // and End to the first and the last; assistive technology sees a toolbar, // which Label names. Controls that do not fit go, from the last, into a // menu at its end, where choosing one clicks it. Spacer pushes those after // it to the end. // // ui.Toolbar(c, func() { // ui.ToggleGroup(c, func() { // ui.Toggle(c, &app.bold, "Bold") // ui.Toggle(c, &app.italic, "Italic") // }) // ui.Spacer(c) // if ui.Button(c, "Share").Clicked() { // app.share() // } // }).Label("Format") func Toolbar(c *Context, fn func()) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreToolbar(_ctx, fn) _ctx.rt.endBuild() return wrapElement(_e) } // TooltipBase shows a tip without a look by anchor: fn styles the tip and // builds its content. It shows once the pointer has rested on anchor for // 0.6 seconds, at once as anchor gets the keyboard focus from the // keyboard, and at once too within 0.4 seconds of another tip going, as // the pointer moves along a toolbar; the theme's TooltipDelay changes // both. It goes as the pointer leaves anchor // or presses it, as a menu or popover of anchor opens, and with Escape, // until the pointer comes back or the focus does; it does not show while // that menu or popover shows. Over elements inside one another, the // innermost one's tip shows; one shows at a time. // // The tip goes above anchor, centered, or below it where there is no room // above; fn may place it elsewhere with AttachTo, as after it: // // ui.TooltipBase(c, b, func(tip ui.Element) { // tip.AttachTo(b, ui.AnchorEnd, ui.AnchorStart).MarginStart(6) // tip.Padding(4, 8).Radius(6).Background(dark).TextColor(light) // tip.Children(func() { ui.Text(c, "Share") }) // }) // // The pointer goes through the tip, and assistive technology sees it as a // tooltip, which it does not read: give anchor a Description to tell what // the tip does. It returns the tip, or nil while it does not show; // Element.Tooltip is TooltipBase with the theme's look. func TooltipBase(c *Context, anchor Element, fn func(tip Element)) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreTooltipBase(_ctx, anchor.nodeFor(_ctx.rt), func(tip *node) { fn(wrapElement(tip)) }) _ctx.rt.endBuild() return wrapElement(_e) } // Tree creates a tree, whose items TreeItem builds in fn. While an item // has the keyboard focus, Up and Down move it to the items around, Home // and End to the first and the last, Right opens the item or moves to its // first child, Left closes it or moves to its parent, and typing the first // letters of an item moves to it. The tree is one stop of Tab. // // ui.Tree(c, func() { // ui.TreeItem(c, "src", &app.srcOpen, func() { // ui.TreeItem(c, "main.go", nil, nil) // }) // ui.TreeItem(c, "go.mod", nil, nil) // }) // // Tree is TreeBase with the theme's look. func Tree(c *Context, fn func()) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreTree(_ctx, fn) _ctx.rt.endBuild() return wrapElement(_e) } // TreeBase creates a tree without a look, as the web's role="tree": a // column of items that Item makes, each a row the caller styles and fills, // built inside the item it belongs to with Group. The tree is one stop of // Tab, which goes to the item that had the focus last, or the one // Selected; while an item has the focus, Up and Down move it to the items // around, Home and End to the first and the last, Right opens the item or // moves to its first child, Left closes it or moves to its parent (the // other way round right to left), and typing the first letters of an // item moves to it. Build the items in Root: // // tree := ui.TreeBase(c) // tree.Root.Gap(2).Children(func() { // var node func(n *Node) // node = func(n *Node) { // c.Key(n.path) // the focus follows it as items above open // item := tree.Item(n.open) // nil for a leaf // item.Row.Gap(4).Padding(4, 8).PaddingStart(8 + 16*float32(item.Depth())).Radius(6) // if item.Row.FocusVisible() { // item.Row.Background(gray) // } // item.Row.Children(func() { // arrow := ui.Box(c).Size(16, 16) // if n.open != nil && arrow.Clicked() { // *n.open = !*n.open // } // ui.Text(c, n.name) // }) // item.Group(func() { // for _, k := range n.children { // node(k) // } // }) // } // for _, n := range app.roots { // node(n) // } // }) // // Tree is TreeBase with the theme's look. TreeBase builds every item // that shows; for trees of thousands of items, use Outline, which builds // only the rows in view, with a Prefix of your own. func TreeBase(c *Context) TreeParts { _ctx := c.build() if _ctx == nil { return TreeParts{} } _ctx.rt.beginBuild() _p := coreTreeBase(_ctx) _ctx.rt.endBuild() return wrapTreeParts(_p) } // TreeItem creates an item of a Tree showing label, inside the item it is // built in. children builds the items inside it, which show while *open // is true; nil children, or a nil open, makes a leaf. A click on its arrow // opens or closes it; Clicked reports a click elsewhere on it, or Enter, // for choosing it, which Selected shows. func TreeItem(c *Context, label string, open *bool, children func()) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreTreeItem(_ctx, label, open, children) _ctx.rt.endBuild() return wrapElement(_e) } // Video creates an element showing a player's video, by default at its // size as DIPs, scaled to fit when given another size, as Image shows a // bitmap: // // //go:embed waves.gif // var wavesGIF []byte // // d, err := ui.NewGIFDecoder(wavesGIF) // ... // app.waves, err = ui.NewVideoPlayer(d) // app.waves.SetLoop(true) // // ui.Video(c, app.waves).Fill().Fit(ui.Cover) // // The video moves on only while the view builds it and some of the window // shows: one that went out of the view, or a window out of sight, goes on // from where it stood; a system's video with sound plays on, unseen, as a // browser's does. Each frame of the video is a frame of the window, which // After asks for as it comes due. While the desktop asks for less motion // (Preferences.ReduceMotion), a decoder's video, and a system's muted one, // shows its first frame and does not play. func Video(c *Context, p *VideoPlayer) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreVideo(_ctx, p) _ctx.rt.endBuild() return wrapElement(_e) } // View returns the content of a window whose user interface view builds, // for mygo.WindowOptions.Content: // // mygo.NewWindow(mygo.WindowOptions{Title: "Counter", Content: ui.View(app.View)}) // // view runs on the main thread whenever the window needs a frame: after // input, after Context.Invalidate or Window.Invalidate, and while // something animates. A Content can serve several windows, each with its // own state. func View(view func(c *Context)) *Content { return coreView(func(c *context) { view(makeContext(c)) }) } // WebView shows a web view, made with mygo.Window.NewWebView, in the // element's content box. A web view has no size of its own: the element // stretches across its container (AlignSelf(Stretch)), and takes the room // along it with Grow or a size: // // ui.Row(c).Fill().Children(func() { // sidebar(c) // ui.WebView(c, app.docs).Grow(1) // }) // // The web view shows while a frame builds its element and hides when one // does not, keeping its page: a view switching tabs builds the web view // of the tab shown. The element paints a hole through the window's // content (the web view is under it, the system's own view), as rounded // as its Radius and cut by the scroll containers and clips around it, so // that what paints after it shows over the page: its children, popovers, // menus, dialogs, tooltips and toasts. The page takes the pointer where // it shows and nothing painted over it takes it, and the keyboard once // clicked, focused (mygo.WebView.Focus) or tabbed into: Tab stops at the // element. The keys the page leaves unhandled come to the native UI as if // the element had the focus, which the shortcuts around it and the // window's see. Its background and border paint around the page, which // its opacity fades, and assistive technology finds the page inside it. func WebView(c *Context, v NativeWebView) Element { _ctx := c.build() if _ctx == nil { return Element{} } _ctx.rt.beginBuild() _e := coreWebView(_ctx, v) _ctx.rt.endBuild() return wrapElement(_e) } // CheckItem creates an item, as Item does, that assistive technology sees // as a check box item, checked while checked is set: flip what it shows // when it is Clicked. func (_handle MenuParts) CheckItem(checked bool) Element { _parts := _handle.resolve() if _parts == nil { return Element{} } _ctx := _parts.c _ = _ctx _ctx.rt.beginBuild() _e := _parts.CheckItem(checked) _ctx.rt.endBuild() return wrapElement(_e) } // Group creates a group of the items that fn builds in the menu being // built, a row that fn styles: the keys take it as one item, Up and Down // moving onto it at its item checked, else its first, and Left and Right // move among its items, round from the last to the first, the other way // round right to left (Direction), instead of opening and closing // submenus. Its items show, are highlighted by the pointer and are chosen // as the others are; a row of radio items that KeepOpen, as a theme's // Light, Dark and System, switches without closing the menu: // // m.Group(func(row ui.Element) { // row.Gap(4).Label("Theme") // for _, th := range []string{"Light", "Dark", "System"} { // item := m.RadioItem(app.theme == th).KeepOpen().Padding(4, 8) // item.Children(func() { ui.Text(c, th) }) // if item.Clicked() { // app.theme = th // } // } // }) // // Assistive technology sees a group, named by its Label, of the items in // it, which it counts on their own. It returns the group. func (_handle MenuParts) Group(fn func(group Element)) Element { _parts := _handle.resolve() if _parts == nil { return Element{} } _ctx := _parts.c _ = _ctx _ctx.rt.beginBuild() _e := _parts.Group(func(group *node) { fn(wrapElement(group)) }) _ctx.rt.endBuild() return wrapElement(_e) } // Item creates an item of the menu being built in Popup or Submenu: a row // that is Highlighted while the pointer or the keys are on it, and whose // Clicked reports its choice, by the pointer, Enter or Space, which closes // the menu, unless KeepOpen. Give it children; Disabled leaves it out of // the keys' way and of the pointer's. Assistive technology sees a menu // item. func (_handle MenuParts) Item() Element { _parts := _handle.resolve() if _parts == nil { return Element{} } _ctx := _parts.c _ = _ctx _ctx.rt.beginBuild() _e := _parts.Item() _ctx.rt.endBuild() return wrapElement(_e) } // Open reports whether the menu shows. func (_handle MenuParts) Open() bool { _parts := _handle.resolve() if _parts == nil { return false } _ctx := _parts.c _ = _ctx return _parts.Open() } // Popup shows the menu while it is open: below the trigger of a menu // button, lined up with its start, or above it where the window has no // room, and a context menu after where it opened, or before it, as from a // corner. fn styles the panel, a column that scrolls the items past the // room the window has, and builds the items in it. It returns the panel, // or nil while the menu is closed. func (_handle MenuParts) Popup(fn func(panel Element)) Element { _parts := _handle.resolve() if _parts == nil { return Element{} } _ctx := _parts.c _ = _ctx _ctx.rt.beginBuild() _e := _parts.Popup(func(panel *node) { fn(wrapElement(panel)) }) _ctx.rt.endBuild() return wrapElement(_e) } // RadioItem creates an item, as Item does, that assistive technology sees // as a radio item, the one chosen of its group while selected is set. func (_handle MenuParts) RadioItem(selected bool) Element { _parts := _handle.resolve() if _parts == nil { return Element{} } _ctx := _parts.c _ = _ctx _ctx.rt.beginBuild() _e := _parts.RadioItem(selected) _ctx.rt.endBuild() return wrapElement(_e) } // Submenu builds the submenu of item, a SubmenuItem of the menu being // built, while it shows: fn styles its panel, after the item and lined up // with it, and builds its items, as Popup's. func (_handle MenuParts) Submenu(item Element, fn func(panel Element)) { _parts := _handle.resolve() if _parts == nil { return } _ctx := _parts.c _ = _ctx _parts.Submenu(item.nodeFor(_ctx.rt), func(panel *node) { fn(wrapElement(panel)) }) } // SubmenuItem creates an item, as Item does, that opens a submenu instead // of being chosen: as the pointer moves onto it or clicks it, and for // Right, Enter or Space while it is highlighted. Build the submenu with // Submenu. Assistive technology sees a menu item that expands, expanded // while its submenu shows. func (_handle MenuParts) SubmenuItem() Element { _parts := _handle.resolve() if _parts == nil { return Element{} } _ctx := _parts.c _ = _ctx _ctx.rt.beginBuild() _e := _parts.SubmenuItem() _ctx.rt.endBuild() return wrapElement(_e) } // Absolute takes the element out of its parent's layout and places it with // Top, Right, Bottom and Left relative to the parent's padding box, above // its siblings. As in CSS, that box is inside the parent's border but holds // its padding: Top(0) puts the element just below the border, whatever the // padding. func (_handle Element) Absolute() Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Absolute()) } // Access has fn describe the element further to assistive technology, // as it builds the element's node, only while assistive technology reads // the window: what costs too much to give every frame, as the text of a // large document. The node is a type internal to this module, so only // its packages describe elements so, as package ui/editor does. The // elements inside a text field described so show to assistive technology // too, as those of other text fields do not. func (_handle Element) Access(fn func(n *platform.AccessNode)) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Access(fn)) } // AccessChildren has fn add nodes of its own inside the element's, after // Access's fn described it and before the elements inside it, only while // assistive technology reads the window: what stands for parts of the // element that are no elements, as the lines a diff viewer shows, each // read as added or deleted. fn reads the element's node, parent, and adds // each node with add, whose Parent it sets; their IDs must be no // element's, and the same for the same part from frame to frame. Actions // on them do nothing. As Access, it takes the module's internal type. func (_handle Element) AccessChildren(fn func(parent *platform.AccessNode, add func(arg0 platform.AccessNode))) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.AccessChildren(fn)) } // AccessDisabled tells assistive technology that the element and those // inside it are unavailable when off is true, as HTML's aria-disabled // does, while they keep the keyboard focus, their place in the Tab order, // the pointer and their look: a screen reader still reaches them and reads // them, as dimmed or unavailable, with their Description, which can say // why. It is for what the user must still find while it cannot be used, // as a menu item whose action is blocked, a tab disabled but still in the // arrows' order, or a submit button while the form is not valid: // // del := ui.Button(c, "Delete project").AccessDisabled(app.locked) // if app.locked { // del.Description("Unlock the project to delete it") // } // if del.Clicked() && !app.locked { // app.deleteProject() // } // // It only tells: clicks and keys still reach the element, which the view // ignores while it is unavailable, and it does not dim it, which the view // styles itself if it wants. Assistive technology focuses it, but neither // presses nor edits it. Disabled does all of it at once: no clicks, no // focus, and half the opacity. func (_handle Element) AccessDisabled(off bool) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.AccessDisabled(off)) } // AccessHidden leaves the element and those inside it out of what // assistive technology reads when hide is true, while they still show, as // HTML's aria-hidden does: none of them is in its tree, their text names // no element around them, and it can neither press, focus nor edit them. // The pointer and the keyboard still reach them, unless they IgnoreInput // too, which makes them inert, as HTML's inert does; without it, keep the // keyboard focus out of them, where assistive technology cannot follow. // // What shows but is not there to read is so read once, or not at all: a // page sliding out beside the one that replaces it, the cards peeking from // behind the front one of a stack, a copy of a text fading into another: // // if app.leaving >= 0 { // page(c, app.leaving).Absolute().Translate(-x, 0).IgnoreInput(true).AccessHidden(true) // } // page(c, app.tab).Translate(width-x, 0) // // RoleNone leaves out the element but not those inside it. func (_handle Element) AccessHidden(hide bool) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.AccessHidden(hide)) } // AccessSelected tells assistive technology whether the element, a tab, // an option, a row, a cell or an item of a tree of your own, is // selected, as ARIA's aria-selected, without the accent background and // text color Selected paints: for one that shows its choice its own way, // as a tab underlined or a row with a check mark. // // tab := ui.ButtonBase(c).Role(ui.RoleTab).Label(name).AccessSelected(i == app.tab) // if i == app.tab { // tab.Bold() // } // // It sets the state Selected sets, which Checked also sets on these // roles, so every platform reads it as Selected's: a row or a cell saying // whether it is selected, false or true, is one its table or grid // chooses among others (Selectable). It only tells: the view shows the // choice, and changes it as the element is clicked. func (_handle Element) AccessSelected(on bool) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.AccessSelected(on)) } // ActiveDescendant tells assistive technology that d has the keyboard // focus while the element does: the option the arrows are on in a list or // a menu that keeps the focus itself, as a combobox's input does. Call it // once d is built, inside the element or in its popup. func (_handle Element) ActiveDescendant(d Element) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.ActiveDescendant(d.nodeFor(_ctx.rt))) } // AlignContent places the lines of a wrapping container across its main // axis, as CSS's align-content does: Start (the default), Center, End, // Stretch, SpaceBetween, SpaceAround or SpaceEvenly. In a grid it places // the rows, which stretch when it is not set. func (_handle Element) AlignContent(a Align) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.AlignContent(a)) } // AlignItems places the children across the main axis. func (_handle Element) AlignItems(a Align) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.AlignItems(a)) } // AlignSelf places the element across its parent's main axis, overriding // the parent's AlignItems; in a grid, it places the element in its cell // vertically. func (_handle Element) AlignSelf(a Align) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.AlignSelf(a)) } // Animate returns a value that moves to target over d, easing out, and // keeps frames coming while it moves; key tells apart the animations of // the element. The value starts at the first target. When the desktop asks // for less motion (Preferences.ReduceMotion), it goes to target at once. // AnimateTo takes springs and delays too. func (_handle Element) Animate(key any, target float32, d time.Duration) float32 { _node := _handle.node() if _node == nil { return 0 } _ctx := _node.c _ = _ctx return _node.Animate(key, target, d) } // AnimateColor returns a color that goes to target as a says, mixed with // premultiplied alpha as transitions mix colors, so that a color fading // from transparent keeps its hue, in sRGB or, with a's Oklab, in Oklab; // key tells apart the element's animated colors. It starts at the first target. As changing colors moves // nothing, colors still change smoothly while the desktop asks for less // motion; DisableAnimations shows them at once. func (_handle Element) AnimateColor(key any, target Color, a Animation) Color { _node := _handle.node() if _node == nil { return *new(Color) } _ctx := _node.c _ = _ctx return _node.AnimateColor(key, target, a) } // AnimatePose moves the element to p as a says, after its own transform // (Transform), and fades it, and returns the element. The element keeps // going in frames that only paint, without building the view, as Core // Animation and the Web Animations API run transforms and opacity: the // cheapest motion there is, which a view large or slow to build keeps // smooth. The pointer, carets and overlays follow it as they follow // transforms. While the desktop asks for less motion, it moves at once, // and only fades smoothly. // // card.AnimatePose(ui.Pose{Y: lift, Scale: 1.02}, ui.Snappy) // // It starts at the first pose: an element that the frame before did not // pose, as one built for the first time, shows at p at once, and moves // only when a later frame poses it elsewhere. To come in from a pose, as // a flyout's panel rising as it shows, pose the element there in one // build, ask for another frame (Context.Invalidate), and pose it at its // place in the next: // // entered := ui.Local(panel, "entered", func() bool { return false }) // p := ui.Pose{} // if !*entered { // p, *entered = ui.Pose{Y: 8, Fade: 1}, true // c.Invalidate() // } // panel.AnimatePose(p, ui.Snappy) // // An element appearing in a parent that the frame before showed comes in // with the Enter of its Transition too. func (_handle Element) AnimatePose(p Pose, a Animation) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.AnimatePose(p, a)) } // AnimateTo returns a value that goes to target as a says, and keeps // frames coming while it moves; key tells apart the animated values of // the element, which Animate, AnimateWith and Spring share. The value // starts at the first target (Jump sets it elsewhere first). A new target // on the way, or a new kind of Animation, takes over from where the value // is: a spring keeps its velocity, even that of a curve. When the desktop // asks for less motion (Preferences.ReduceMotion), the value goes to its // target at once, unless a's NonMotion says it moves nothing, as a fade: // // op := e.AnimateTo("fade", target, ui.Animation{Duration: 200 * time.Millisecond, NonMotion: true}) func (_handle Element) AnimateTo(key any, target float32, a Animation) float32 { _node := _handle.node() if _node == nil { return 0 } _ctx := _node.c _ = _ctx return _node.AnimateTo(key, target, a) } // AnimateWith returns a value that moves to target over d as Animate does, // along ease. func (_handle Element) AnimateWith(key any, target float32, d time.Duration, ease Easing) float32 { _node := _handle.node() if _node == nil { return 0 } _ctx := _node.c _ = _ctx return _node.AnimateWith(key, target, d, ease) } // Arrived reports whether the value animated under key came to rest at // its target in this frame, after moving there: true in that frame only, // for the view to go on, as by removing what faded out. func (_handle Element) Arrived(key any) bool { _node := _handle.node() if _node == nil { return false } _ctx := _node.c _ = _ctx return _node.Arrived(key) } // AspectRatio makes the height the width divided by r. func (_handle Element) AspectRatio(r float32) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.AspectRatio(r)) } // Attach takes the element out of its parent's layout, as Absolute does, // and puts its point self on the point at of the parent's padding box: // Attach(ui.AnchorTopRight, ui.AnchorCenter) centers a badge on the top // right corner of its parent, and Attach(ui.AnchorBottomRight, // ui.AnchorBottomRight) puts a button in the bottom right corner. Top, // Right, Bottom and Left then move it from there; the element keeps its // own size. func (_handle Element) Attach(at Anchor, self Anchor) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Attach(at, self)) } // AttachEdgeMargin sets how far an element placed with AttachTo stays // from the window's edges, v DIPs on each side, where it is 4 unless set: // a panel that must not touch the edges of a small window keeps 12 from // them, as the inset-modified containing block of CSS Anchor Positioning // keeps a positioned box inside the insets given to it. It is the room // the element flips and moves to stay in, and that one scrolling is // limited to. func (_handle Element) AttachEdgeMargin(v float32) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.AttachEdgeMargin(v)) } // AttachTo takes the element out of its parent's layout, as Attach does, // and puts its point self on the point at of target's box, wherever target // is in the window: built in an Overlay, a panel goes below a button with // AttachTo(button, ui.AnchorBottomLeft, ui.AnchorTopLeft), and to its // right with AttachTo(button, ui.AnchorRight, ui.AnchorLeft). Where it // would overflow the window, it goes to the other side of target, or the // other way along it, if that overflows less, then moves along target into // the window. Its margins keep it apart from target: a top margin below // it, and above it as it goes there. Top, Right, Bottom and Left then move // it; the element keeps its own size. // // The element is target's popover: its elements follow target as Tab // moves, and a press on target is not outside it (PressedOutside). Build // target before it, in the same frame. AttachedAnchors tells the side it // went to. func (_handle Element) AttachTo(target Element, at Anchor, self Anchor) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.AttachTo(target.nodeFor(_ctx.rt), at, self)) } // AttachedAnchors returns the points of its target's box and of its own // that AttachTo put together as the layout placed the element: those // asked for, or, where it went to the other side of target or the other // way along it to stay in the window, those across or down from them, as // Floating UI's placement: AnchorTop and AnchorBottom for a panel asked // below its button, with AttachTo(button, ui.AnchorBottom, ui.AnchorTop), // that went above it. Start and end anchors stay start and end ones. The // view reads the last frame's, which are those asked for until the // element is laid out, as in the frame it first shows; Draw reads this // frame's. From that first frame, AttachedOrigin puts the element's // transform origin on its own point, and a Motion's Flip mirrors its // Enter and Exit, on the side the layout chose. An element not attached // to another returns its Attach anchors, or AnchorTopLeft twice without // them. func (_handle Element) AttachedAnchors() (Anchor, Anchor) { _node := _handle.node() if _node == nil { return *new(Anchor), *new(Anchor) } _ctx := _node.c _ = _ctx return _node.AttachedAnchors() } // AttachedOrigin sets the transform origin on the element's own point // that AttachTo puts on its target, on whichever side of it the layout // puts the element (AttachedAnchors), from the frame it shows: a tooltip // or a menu scaling in, or out, grows from the edge nearest its trigger, // as Radix's popper transform origin. It replaces TransformOrigin on an // element attached to another. func (_handle Element) AttachedOrigin() Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.AttachedOrigin()) } // AutoComplete tells assistive technology what the suggestions of a // text input or a combobox of your own complete as the user types, as // ARIA's aria-autocomplete: AutoCompleteList for a popup of the values // matching what was typed, which screen readers announce with the field // so that the user knows to look there, AutoCompleteInline for the text // completed in place. It only tells it: the view shows the suggestions // itself, as in ComboboxBase's popup. Combobox, Autocomplete, and a // TokenField with suggestions or a Query, tell AutoCompleteList // themselves; AutoCompleteNone takes it back. func (_handle Element) AutoComplete(kind AutoComplete) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.AutoComplete(kind)) } // AutoFocus gives the element the keyboard focus in the frame it appears, // as the first field of a dialog. func (_handle Element) AutoFocus() Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.AutoFocus()) } // Autocorrect turns an on-screen keyboard's corrections and suggestions on // or off for a text input, on by default where the keyboard has them. func (_handle Element) Autocorrect(on bool) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Autocorrect(on)) } // Autofill tells the system what a text input holds, for it to offer it // from its passwords and contacts, as with iOS's Passwords above the // keyboard. func (_handle Element) Autofill(k AutofillKind) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Autofill(k)) } // BackfaceHidden hides the element, and takes it from the pointer, while // its 3D transform turns its back to the viewer, as CSS's // backface-visibility: hidden: the two faces of a card turning over, the // back turned 180 degrees more than the front, show one at a time. // // front.RotateY(turn).Perspective(800).BackfaceHidden() // back.RotateY(turn + 180).Perspective(800).BackfaceHidden() func (_handle Element) BackfaceHidden() Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.BackfaceHidden()) } // Background fills the element, in place of a gradient. func (_handle Element) Background(c Color) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Background(c)) } // Balance wraps the element's text in lines of about the same length, as // CSS's text-wrap: balance does: a heading or a short callout that takes // two lines takes two of half its length each, rather than a full line // and a word alone on the next. The text takes as many lines as it would // without it, at the width layout gives it, and keeps its alignment // within that width. Each paragraph is balanced on its own, once a // layout, as the text system keeps it. func (_handle Element) Balance() Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Balance()) } // Basis sets the size along the parent's main axis before growing or // shrinking. func (_handle Element) Basis(v float32) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Basis(v)) } // BasisPercent sets the basis as a percentage of the parent's size along // its main axis. func (_handle Element) BasisPercent(p float32) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.BasisPercent(p)) } // Blur blurs the element, with its children, by sigma DIPs, the standard // deviation of a Gaussian, as CSS's filter: blur() does: what it draws // spreads that far around, transparent beyond, on the GPU. It renders // into a bitmap first, as Effect does, about 3 sigma larger each way, and // an element with an Effect draws through it instead. Hit testing, focus // and accessibility do not change: only what shows. func (_handle Element) Blur(sigma float32) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Blur(sigma)) } // Bold sets a bold font weight. func (_handle Element) Bold() Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Bold()) } // Border draws a border of width DIPs inside the element's edges, on every // side; BorderWidth sets different widths. As in CSS, the border takes room // within the element's size: the padding and the children are inside it. func (_handle Element) Border(width float32, c Color) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Border(width, c)) } // BorderColor sets the color of the border. func (_handle Element) BorderColor(c Color) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.BorderColor(c)) } // BorderConicGradient paints the element's border (Border, BorderWidth) // with a conic gradient around the element, in place of its color: a ring // of colors, as SwiftUI's strokeBorder with an AngularGradient draws. // // ui.Box(c).Size(120, 80).Radius(16).Border(4, ui.Color{}).BorderConicGradient(ui.ConicGradient{Stops: rainbow}) func (_handle Element) BorderConicGradient(g ConicGradient) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.BorderConicGradient(g)) } func (_handle Element) BorderEndWidth(v float32) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.BorderEndWidth(v)) } // BorderLinearGradient paints the element's border (Border, BorderWidth) // with a linear gradient across the element, in place of its color. func (_handle Element) BorderLinearGradient(g LinearGradient) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.BorderLinearGradient(g)) } // BorderStartWidth and BorderEndWidth set the width of the border on the // side lines start and on the other, as PaddingStart does: a line // between a sidebar and the content is BorderEndWidth(1) on the sidebar. func (_handle Element) BorderStartWidth(v float32) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.BorderStartWidth(v)) } // BorderStyle sets whether the border is solid, as by default, or dashed. func (_handle Element) BorderStyle(s BorderStyle) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.BorderStyle(s)) } // BorderWidth sets the widths of the border on each side, CSS style: all // sides, vertical and horizontal, or top, right, bottom and left. A line // below a header: // // ui.Row(c).BorderWidth(0, 0, 1, 0).BorderColor(t.Border) func (_handle Element) BorderWidth(v ...float32) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.BorderWidth(v...)) } func (_handle Element) Bottom(v float32) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Bottom(v)) } func (_handle Element) BottomPercent(p float32) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.BottomPercent(p)) } // Bounds returns the previous frame's transformed bounding rectangle in // window DIPs, the content's when zoomed (Context.SetZoom); it is empty // for an element the previous frame lacked. // LayoutBounds returns its box before visual transforms. func (_handle Element) Bounds() Rect { _node := _handle.node() if _node == nil { return *new(Rect) } _ctx := _node.c _ = _ctx return _node.Bounds() } // Browse lets the user move about a Calendar without choosing a day: its // buttons and Page Up and Page Down only show other months, and the // arrows, Home and End only move among the days, until a click, Enter or // Space chooses one, as in a date input's calendar. Changed then reports // only a day chosen, as a calendar in a popover that closes when the // user picks a day needs. The calendar goes back to *date as the app // sets another. func (_handle Element) Browse() Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Browse()) } // Busy tells assistive technology whether the element's content is about // to change, as a region loading, or one updated in several steps: // screen readers wait until it is no longer busy to read what changed in // it. A placeholder standing in for the content, as a skeleton or a // spinner, says what is happening (a RoleStatus labelled "Loading"). func (_handle Element) Busy(on bool) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Busy(on)) } // Cache keeps what the element paints, with its children, in a bitmap of // the GPU that frames draw as one image, as Flutter's RepaintBoundary and // SwiftUI's drawingGroup do: for a still subtree that costs much to draw, // as a card of gradients, blurred images and large shadows, under or // around a drawing that moves. A frame redrawing where something above or // next to it changed then draws the bitmap there, not each of its layers, // and moving or rotating the element (Translate, Rotate, AnimatePose) // moves the bitmap, not what it holds. // // The bitmap holds the element's box, and what it and those inside it // paint around it: shadows, focus rings, and children beyond the box that // it does not clip, as Draw callbacks paint (within the box and the // shadows' reach), in the pixels it shows on: at the window's scale times // the scale the element's transform draws it at (Scale, AnimatePose, // Transition's ScaleContent), so that scaled up it is as sharp as the // subtree laid out larger. At rest it is drawn at that scale itself, on // whole pixels where the transform only scales and moves it; while the // scale changes, as an animation grows it, at steps of about 9% (at or // above the scale), drawn again only as the scale crosses one, and once // more at the scale itself in the frame after it stops. It is drawn // again, too, when what the subtree paints changes: built anew with other // content, laid out at another size, at another window scale or in // another theme, or as something inside it moves on its own // (Painter.AnimationFrame, a pose, a transition), as then it is every // frame. Painting the window still paints the subtree, to tell; frames // that only paint the drawings that asked for them // (Painter.AnimationFrame, Painter.After) do not. // // As in an effect's bitmap (Effect), its text is smoothed in grayscale // where the subtree paints no opaque background under it, web views // inside it do not show, and a subtree larger than 8192 pixels across is // drawn as it is. A bitmap drawn larger than the window's scale is at // most 4096 pixels across, and 8 times the window's scale: beyond, it is // stretched as before. Turned, skewed or in perspective, the bitmap is // resampled, and shows a little softer than the shapes it holds would. func (_handle Element) Cache() Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Cache()) } // Capitalize sets what an on-screen keyboard capitalizes as one types. func (_handle Element) Capitalize(c Capitalization) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Capitalize(c)) } // CaretColor sets the color of the insertion caret of the text inputs in // the element, as CSS's caret-color does, a field's own text color for // one; the theme's accent is the color elsewhere. func (_handle Element) CaretColor(c Color) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.CaretColor(c)) } // CaretWidth sets this input's painted caret width in DIPs for this build. // It defaults to one DIP. Positive widths are rounded to device pixels, // at least one pixel wide; zero and negative widths hide the caret. It does // not change text layout, input-method candidate bounds or caret blinking. // Other elements are unaffected. func (_handle Element) CaretWidth(width float32) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.CaretWidth(width)) } // Center centers the children along and across the main axis. func (_handle Element) Center() Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Center()) } // Changed reports whether this widget's value changed in this build pass, // by the input it took as its constructor returned. func (_handle Element) Changed() bool { _node := _handle.node() if _node == nil { return false } _ctx := _node.c _ = _ctx return _node.Changed() } // Checked tells assistive technology whether the element, as a check box, // switch, radio button, toggle button or menu item of your own, is on, or // whether an option (RoleOption) is selected. Bases set it from their // value. func (_handle Element) Checked(on bool) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Checked(on)) } // ChildExit says where the children of the element that leave in this // frame go, in place of the Exit of their Transitions: those whose // Transition has an Exit, which are copied as they go. It suits an exit // decided as they leave, as a calendar, a wizard or a carousel stepping // forward or back, whose page going goes the way of the step that sent // it, even when the step turned around in the frame it went: // // dir := float32(app.dir) // 1 forward, -1 back // ui.Box(c).Fill().ChildExit(ui.Motion{X: -40 * dir}).Children(func() { // ui.Column(c.Key(app.page)).Absolute().Fill().Transition(ui.ElementTransition{ // Enter: &ui.Motion{X: 40 * dir}, // Exit: &ui.Motion{X: -40 * dir}, // }) // }) // // Copies already on their way go on as they went. func (_handle Element) ChildExit(m Motion) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.ChildExit(m)) } // ClickModifiers returns the modifier keys held as the element was last // clicked, none for a click by the keyboard: with Clicked, a click with // Shift or Cmd does something else, as extending a choice. func (_handle Element) ClickModifiers() Modifiers { _node := _handle.node() if _node == nil { return 0 } _ctx := _node.c _ = _ctx return _node.ClickModifiers() } // Clicked reports whether the element was clicked, with the primary // button or by Enter or Space while focused, since the last frame. func (_handle Element) Clicked() bool { _node := _handle.node() if _node == nil { return false } _ctx := _node.c _ = _ctx _ctx.rt.applyInputs() return _node.Clicked() } // Clicks returns how many times the element was clicked since the last // frame. func (_handle Element) Clicks() int { _node := _handle.node() if _node == nil { return 0 } _ctx := _node.c _ = _ctx _ctx.rt.applyInputs() return _node.Clicks() } // Clip hides what the children draw outside the element. func (_handle Element) Clip() Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Clip()) } // ClipInset clips the element and what is inside it, its background, // shadows, border and children, to its box inset by top, right, bottom and // left DIPs, with corners rounded by radius, as CSS's clip-path: inset() // does. A negative inset reaches beyond the box on that side, as a clip // along one axis that leaves a shadow whole along the other. The insets // may change every frame, as values an element animates do: // // hidden := float32(100) // if app.open { // hidden = 0 // } // card.ClipInsetPercent(0, card.AnimateTo("wipe", hidden, ui.Smooth), 0, 0, 0) // // What the clip hides takes no clicks. func (_handle Element) ClipInset(top float32, right float32, bottom float32, left float32, radius float32) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.ClipInset(top, right, bottom, left, radius)) } // ClipInsetPercent is ClipInset with insets in percent of the box: top // and bottom of its height, right and left of its width, as CSS's inset() // takes percentages. An inset going from 100 to 0 wipes the element in // from the other side. func (_handle Element) ClipInsetPercent(top float32, right float32, bottom float32, left float32, radius float32) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.ClipInsetPercent(top, right, bottom, left, radius)) } // ClipX hides what the children draw left and right of the element, and // ClipY what they draw above and below it. func (_handle Element) ClipX() Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.ClipX()) } func (_handle Element) ClipY() Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.ClipY()) } // Column lays the children out from top to bottom. func (_handle Element) Column() Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Column()) } // ColumnCount tells assistive technology how many columns a table, grid // or tree grid of your own has, built or not (aria-colcount). func (_handle Element) ColumnCount(n int) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.ColumnCount(n)) } // ColumnIndex tells assistive technology the place of a cell or a column // header among all the columns of its table, grid or tree grid, from 1 // (aria-colindex): for one that builds only the columns in view, or // leaves some out. Cells without one follow the one before them, after // the columns it covers (ColumnSpan). func (_handle Element) ColumnIndex(i int) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.ColumnIndex(i)) } // ColumnSpan makes the element span n columns of its grid, or, for a // negative n, every column from its start to the grid's last, as a header // across a grid does. A cell of a table or a grid (RoleCell, // RoleColumnHeader, RoleRowHeader) tells assistive technology it covers // them, as ARIA's aria-colspan, whether or not its row lays it out in a // grid: screen readers read a cell covering two columns as one. func (_handle Element) ColumnSpan(n int) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.ColumnSpan(n)) } // ColumnStart puts the element in column n of its grid, counting from 1. func (_handle Element) ColumnStart(n int) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.ColumnStart(n)) } // ColumnTracks sets the grid's columns, as a sidebar and the rest: // // ui.Grid(c).ColumnTracks(ui.Fixed(220), ui.Fr(1)) func (_handle Element) ColumnTracks(tracks ...Track) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.ColumnTracks(tracks...)) } // Columns gives the grid n columns of equal width, Fr(1) each. func (_handle Element) Columns(n int) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Columns(n)) } // Composing reports whether an input method composes text in a text // input, as Pinyin before a candidate is chosen: its value holds the text // once composed. Keys typed meanwhile are the input method's, as Enter // choosing a candidate: they submit nothing and press no shortcut. func (_handle Element) Composing() bool { _node := _handle.node() if _node == nil { return false } _ctx := _node.c _ = _ctx return _node.Composing() } // ConicGradient fills the element with a conic gradient, its colors // turning around a point (CSS's conic-gradient()): // // ui.Box(c).Size(80, 80).Radius(40).ConicGradient(ui.ConicGradient{ // Stops: []ui.GradientStop{{red, 0}, {yellow, 1.0 / 3}, {blue, 2.0 / 3}, {red, 1}}, // }) func (_handle Element) ConicGradient(g ConicGradient) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.ConicGradient(g)) } // ContentTransition animates the element's content as it changes, as t // says: the text of a Text, the icon of an Icon, the picture of an Image. // Changes animate from frame to frame while the element is painted, in // frames that only paint. While the desktop asks for less motion, content // fades without moving. // // ui.Text(c, strconv.Itoa(app.count)).ContentTransition(ui.ContentTransition{Numeric: true, Down: app.decreased}) func (_handle Element) ContentTransition(t ContentTransition) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.ContentTransition(t)) } // ContextMenu gives the element a context menu, which build fills with // items. The system shows it where the element is clicked with the // secondary button, or Control-clicked on macOS, and, while the element or // one inside it has the focus, below it when the menu key or Shift+F10 is // pressed; in a list, while the list has the focus and the element's row // is chosen. build runs when the menu opens, and again in the frame after an // item was chosen, where the item's Chosen reports it: // // row.ContextMenu(func(m *ui.Menu) { // if m.Item("Rename").Chosen() { // app.renaming = i // } // m.Separator() // if m.Item("Delete").Disabled(app.locked).Chosen() { // app.delete(i) // } // }) // // The innermost element with a context menu gets the click. Text inputs // and selectable text have one with their editing commands, which // ContextMenu replaces: on a text input, on a selectable text, or on the // Selectable container whose text was clicked. EditItems puts those // commands in a menu of one's own: // // message.Selectable().ContextMenu(func(m *ui.Menu) { // if m.Item("Reply").Chosen() { // app.reply(msg) // } // m.Separator() // m.EditItems() // }) // // PopoverMenu draws the same menu in the window, with the theme's look, as // ContextMenu does while the window draws its menus (SetMenuPresentation). func (_handle Element) ContextMenu(build func(m *Menu)) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.ContextMenu(build)) } // Controls tells assistive technology that the element controls the // content or the presence of target, as ARIA's aria-controls: the // region a disclosure button opens, or the list a filter's input // narrows. Screen readers offer to move to it. Call it once target is // built, once for each element it controls. func (_handle Element) Controls(target Element) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Controls(target.nodeFor(_ctx.rt))) } // CopyData sets what Copy, its shortcut and the context menu's put on // the clipboard for the selection of a Selectable container: fn gets its // parts, as SelectedTexts returns them, and returns the data, as a // document copies its paragraphs with blank lines between them as text // (transfer.TextData), and as HTML too to keep their formatting. func (_handle Element) CopyData(fn func(parts []SelectedText) transfer.Data) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.CopyData(fn)) } // Current tells assistive technology that the element is the current one // of the items around it, as the page the user is on in a breadcrumb // trail or a navigation bar, which screen readers read with it ("current // page"). CurrentNone takes it back. func (_handle Element) Current(kind Current) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Current(kind)) } // Cursor sets the pointer's shape over the element. func (_handle Element) Cursor(c Cursor) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Cursor(c)) } // Debug outlines the element and every element inside it, with their // padding and margins, to see the layout. func (_handle Element) Debug() Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Debug()) } // DecorationColor sets the color of underlines and strikethroughs, which // is the text's otherwise. func (_handle Element) DecorationColor(c Color) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.DecorationColor(c)) } // DecorationThickness sets the thickness of underlines and strikethroughs // in DIPs, which follows the font size otherwise. func (_handle Element) DecorationThickness(v float32) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.DecorationThickness(v)) } // DescribedBy has desc, an element the view draws, as a hint below a // field or a help text beside it, describe the element to assistive // technology, as ARIA's aria-describedby does: screen readers read desc's // text after the element's name and value, as a Description, which it // follows. The text is desc's Label, else the texts inside it, as a // sentence with a link in it, read as one; it counts even when desc is // hidden from assistive technology (AccessHidden). Call it once both are // built, before or after the element, once for each element describing // it, in the order to read them. On a Field, it describes the field's // control. // // hint := ui.Text(c, "16 digits, no spaces").TextColor(t.TextMuted) // ui.TextInput(c, &app.card).Label("Card number").DescribedBy(hint) func (_handle Element) DescribedBy(desc Element) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.DescribedBy(desc.nodeFor(_ctx.rt))) } // Description tells assistive technology more about the element than its // name, as help text it reads after it. On a Field, the text shows below // the control, and describes it. func (_handle Element) Description(s string) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Description(s)) } // DimDisabled sets whether the element shows at half its opacity, with // what is inside it, while Disabled disables it, as it does by default, // bases too; an element disabled by one around it dims with that one. A // widget of your own that shows being disabled in a look of its own, as // a card that keeps the reason it is unavailable readable, turns it off // and styles itself while IsDisabled. func (_handle Element) DimDisabled(dim bool) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.DimDisabled(dim)) } // Direction lays the element and what is inside it out in d, whatever the // direction around it: Direction(ui.LeftToRight) keeps a code sample, a // phone number or a media player's controls left to right in a // right-to-left window, as Flutter's Directionality and SwiftUI's // layoutDirection environment do. The elements built inside it inherit it, // as do the popups attached to it. // // Give it right after creating the element, before its children, logical // edges and the parts that read it, as widgets do as they are built: // elements already inside take it, and logical edges move to the other // side, but what read the old direction keeps it. func (_handle Element) Direction(d Direction) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Direction(d)) } // Disabled disables the element and those inside it when d is true: they // report no clicks, take no focus, and show at half their opacity, unless // DimDisabled turns that off. AccessDisabled keeps their clicks and their // focus, for what assistive technology must still reach. func (_handle Element) Disabled(d bool) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Disabled(d)) } // Dismissed reports whether pressing Escape or clicking outside closed the // dialog or popover (Modal, DialogBase, Popover, PopoverBase) returning the // element, in the frame it did, setting its *open to false: one that must // stay open sets it back to true. // // if ui.Modal(c, &app.editing, edit).Dismissed() && app.unsaved { // app.editing = true // } func (_handle Element) Dismissed() bool { _node := _handle.node() if _node == nil { return false } _ctx := _node.c _ = _ctx return _node.Dismissed() } // Dividers draws a line width DIPs thick in color c between each two // children of a row, a column or a List (between their rows), across the // element, inside its border: in the middle of the room between them, // which the lines do not take, so give the element a Gap at least as // wide. A row that wraps draws them between the children of each line; // grids draw none. func (_handle Element) Dividers(width float32, c Color) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Dividers(width, c)) } // DottedUnderline underlines text with a line of dots, as links mark // hover. func (_handle Element) DottedUnderline() Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.DottedUnderline()) } // DoubleClicked reports a double click on the element. func (_handle Element) DoubleClicked() bool { _node := _handle.node() if _node == nil { return false } _ctx := _node.c _ = _ctx _ctx.rt.applyInputs() return _node.DoubleClicked() } // Drag makes the element the source of value, dragged within the window // once the pointer pressing the element moves a few DIPs: a copy of the // element follows the pointer, and the element taking the value under it // gets it when the pointer is released (Drop). A press dragging is no // click. Dragging reports the drag. func (_handle Element) Drag(value any) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Drag(value)) } // DragData makes e a native drag source after a primary press moves a few // DIPs. Data can go to other windows and applications. A source also given // Drag(value) offers that value to typed targets in this process only. // The default operation is copy and the default preview is the element. func (_handle Element) DragData(data transfer.Data, options ...transfer.DragOptions) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.DragData(data, options...)) } // DragDataFrom obtains a transfer when the gesture starts, useful for a // changing selection. The function and options.Done run on the main thread. // See transfer.Lazy for deferring individual serialized representations. func (_handle Element) DragDataFrom(data func() transfer.Data, options ...transfer.DragOptions) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.DragDataFrom(data, options...)) } // DragEnded reports whether the pointer pressing the element with the // primary button, and moving, let go since the last frame, with how fast // it moved then, as DragVelocity: a spring taking over // (SpringOptions.Velocity) keeps the fling going. A click, which does not // move, ends no drag, nor does a drag with another button, nor a press // the system canceled (PressCanceled). func (_handle Element) DragEnded() (float32, float32, bool) { _node := _handle.node() if _node == nil { return 0, 0, false } _ctx := _node.c _ = _ctx return _node.DragEnded() } // DragMissed reports, in the frame after, that the value the element // drags (Drag) was let go over no element taking it, and where, in the // window's coordinates: outside the window when it was let go past its // edge, as to tear a tab out into a window of its own. A drag given up, // with Escape, is not missed. func (_handle Element) DragMissed() (Point, bool) { _node := _handle.node() if _node == nil { return *new(Point), false } _ctx := _node.c _ = _ctx return _node.DragMissed() } // DragOffset returns where Draggable shows the element in this frame, // from its place in the layout: following the pointer, or on its way to // rest. Reading it builds the view in every frame the element moves in, // as AnimateTo does, which the element otherwise moves in without: for // what follows the element, as a backdrop fading as a sheet goes down. // Call it after Draggable. func (_handle Element) DragOffset() Point { _node := _handle.node() if _node == nil { return *new(Point) } _ctx := _node.c _ = _ctx return _node.DragOffset() } // DragVelocity returns how fast, in DIPs per second along the element's // local axes, the pointer pressing the element moves now: zero once it // stops for a moment, or while nothing presses the element with the // primary button (Dragged). func (_handle Element) DragVelocity() (float32, float32) { _node := _handle.node() if _node == nil { return 0, 0 } _ctx := _node.c _ = _ctx return _node.DragVelocity() } // DragWindow makes the element a handle that moves the window, such as the // title bar of a frameless window. A double click on it maximizes the // window, as on a title bar. func (_handle Element) DragWindow() Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.DragWindow()) } // Draggable lets the pointer move the element from its place in the // layout, by *offset, and returns the element. As the pointer drags it, // the element follows the pointer, along its parent's axes, and *offset // with it; once the pointer lets go, *offset is where the element comes to // rest, as o says, and it goes there. Setting *offset moves the element // there as well, as o.Animation says. A nil offset is kept in the element. // // The element moves after its own transform (Transform) and its pose // (AnimatePose), and goes to rest in frames that only paint, without // building the view, as AnimatePose moves it. Dragging reports that the // pointer drags it, once the pointer moved a few DIPs, Transitioning that // it moves, and DragOffset where it shows. A press dragging it is no // click; a press catches it as it moves. A press the system cancels // (PressCanceled) throws nothing, and the element goes back to where the // press took it. While the desktop asks for less motion // (Preferences.ReduceMotion), it goes to rest at once. // // sheet.Draggable(&app.sheet, ui.DraggableOptions{ // Axis: ui.Vertical, // Bounds: &ui.Rect{H: 400}, // Snap: ui.Nearest(ui.Point{}, ui.Point{Y: 200}, ui.Point{Y: 400}), // }) func (_handle Element) Draggable(offset *Point, o DraggableOptions) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Draggable(offset, o)) } // Dragged reports how far the pointer moved in the element's local axes // since the last frame while pressing it with the primary button, as // Pressed: a drag with another button moves nothing (PressedButton). The // moves just before the pointer let go come while the element is still // pressed, and the press ends in the build after. func (_handle Element) Dragged() (float32, float32, bool) { _node := _handle.node() if _node == nil { return 0, 0, false } _ctx := _node.c _ = _ctx return _node.Dragged() } // Dragging reports whether the element is dragging its value (Drag), or // the pointer is dragging the element (Draggable). func (_handle Element) Dragging() bool { _node := _handle.node() if _node == nil { return false } _ctx := _node.c _ = _ctx return _node.Dragging() } // Draw paints on the element with p after its background, before its // children; r is its box. fn only paints: it may run more than once a // frame. func (_handle Element) Draw(fn func(p *Painter, r Rect)) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Draw(fn)) } // DrawObjects paints the inline objects of a text (Span.ObjectWidth) // with p, after its glyphs: fn gets each one that shows, its rune in // the text, the text elements' inside it included, and its box, in // window DIPs, ObjectHeight above the baseline and ObjectDescent below. // It paints in the text's clip and in the transform of the element // holding the object. fn only paints: it may run more than once a frame. // // ui.RichText(c, ui.Span{Text: "area "}, ui.Span{Text: "\uFFFC", ObjectWidth: w, ObjectHeight: h, ObjectDescent: d}). // DrawObjects(func(p *ui.Painter, at int, r ui.Rect) { formula.Draw(p, r) }) func (_handle Element) DrawObjects(fn func(p *Painter, at int, r Rect)) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.DrawObjects(fn)) } // DrawOver paints on the element with p after its children. func (_handle Element) DrawOver(fn func(p *Painter, r Rect)) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.DrawOver(fn)) } // DroppedFiles returns the paths of the files dropped on the element since // the last frame, nil when none, and makes the element take files dragged // over it. func (_handle Element) DroppedFiles() []string { _node := _handle.node() if _node == nil { return nil } _ctx := _node.c _ = _ctx return _node.DroppedFiles() } // Effect draws the element, with its children, through fx, an effect of // package ui/shader, in place of drawing it as it is; nil draws it as it // is: // // ui.Text(c, "Wavy").Effect(wave.Effect(shader.Options{ // Uniforms: map[string]any{"Time": t}, // MaxSampleOffset: ui.Point{Y: 8}, // })) // // What the element renders, with its children, shadows and what its Draw // callbacks paint, renders into a bitmap of the GPU, the size of its box // and the effect's margin (Effect.EffectMargin) around it, every frame // the element paints, which the effect then draws over the box and the // margin, transformed, clipped and faded as the element would be. Web views // inside the element do not show through an effect. func (_handle Element) Effect(fx Effect) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Effect(fx)) } // Ellipsis sets what ends text that MaxLines or SingleLine cuts, "…" by // default. func (_handle Element) Ellipsis(s string) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Ellipsis(s)) } func (_handle Element) End(v float32) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.End(v)) } func (_handle Element) EndPercent(p float32) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.EndPercent(p)) } // Error marks the element's value as not valid, for msg, which assistive // technology reads with it; an empty msg leaves it valid. On a Field, the // message shows below the control in the theme's Danger color, and marks // the control, whose border text inputs draw in that color. func (_handle Element) Error(msg string) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Error(msg)) } // ErrorMessage has msg, an element the view draws holding the message of // the element's error, tell assistive technology why its value is not // valid, as ARIA's aria-errormessage does: while the element is invalid // (Invalid, Error), screen readers read msg's text with it, first in its // description, and those that follow the relation go to msg. While it is // valid, msg says nothing of it, so the view may keep msg built, empty or // hidden. Call it once both are built, once for each element holding a // message. On a Field, it is the field's control's message. // // in := ui.TextInput(c, &app.email).Label("Email").Invalid(app.emailError != "") // if app.emailError != "" { // in.ErrorMessage(ui.Text(c, app.emailError).TextColor(t.Danger)) // } func (_handle Element) ErrorMessage(msg Element) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.ErrorMessage(msg.nodeFor(_ctx.rt))) } // Expanded tells assistive technology whether what the element opens // shows, as the popup of a button or the section below a header. func (_handle Element) Expanded(open bool) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Expanded(open)) } // FileDragOver reports whether files dragged from another app are over // the element, which takes them if they are dropped, for showing it would. func (_handle Element) FileDragOver() bool { _node := _handle.node() if _node == nil { return false } _ctx := _node.c _ = _ctx return _node.FileDragOver() } // Fill makes the element as large as its parent's content. func (_handle Element) Fill() Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Fill()) } // FillEqually makes a Segmented or a ToggleGroup as wide as its parent's // content, as FillWidth does, and shares that width equally among its // segments, as AppKit's fillEqually distribution: the one chosen takes // its share, its label in the middle, and a label longer than its share // ends with an ellipsis. The segments look and behave as they do // otherwise, disabled ones too. Call it on SegmentedBase's Track after // building its segments; on other elements it is FillWidth. A width set // after it sets the control's, which its segments share still. // // ui.Segmented(c, &app.theme, "Light", "Dark", "System").FillEqually().Label("Appearance") func (_handle Element) FillEqually() Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.FillEqually()) } // FillHeight makes the element as tall as its parent's content. func (_handle Element) FillHeight() Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.FillHeight()) } // FillWidth makes the element as wide as its parent's content. func (_handle Element) FillWidth() Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.FillWidth()) } // Fit sets how an Image fills its box. func (_handle Element) Fit(f Fit) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Fit(f)) } // FixedLineHeight sets the height of lines of text in DIPs, whatever the // font size, as for rows of text that line up with a grid. func (_handle Element) FixedLineHeight(v float32) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.FixedLineHeight(v)) } // Focus gives the element the keyboard focus. Called in every frame, it // keeps it there; AutoFocus gives it once. A field around an input, as // SearchField's, gives it to its input, where typing goes. When the focus // moves to it, it scrolls the containers around it as little as shows it, // as Tab does and the web's focus() does; ScrollIntoView lines it up // otherwise. While a pointer button is held it scrolls nothing: what a // press focuses, as the line a grip moves, is under the pointer. // // Its options, as the web's focus() options, keep the scroll where the // user left it: the focus returned to a cell of a grid when a dialog // closes, without scrolling the grid. // // cell.Focus(ui.FocusOptions{PreventScroll: true}) func (_handle Element) Focus(options ...FocusOptions) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Focus(options...)) } // FocusGroup makes the elements inside the element that take the focus one // stop of Tab, as the controls of a toolbar, a radio group or a tab list // are: Tab moves the focus into the group, to the element of it that had // it last (else the radio button or tab chosen, else the first; in a // radio group or a tab list, the one chosen first), and on out of it; the // arrows that o names move it among them, round from the last to the // first, and Home and End to the first and the last. An element inside // that takes those keys itself, as a slider or a text input does, keeps // them. Groups inside a group are part of it. func (_handle Element) FocusGroup(o Orientation) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.FocusGroup(o)) } // FocusLeft reports whether the keyboard focus left the element since the // last frame: it was on the element or inside it, and is now outside it, // or nowhere, as the window lost the keyboard. That is the web's focusout // whose relatedTarget the element does not contain. The overlays attached // to the element and to those inside it (AttachTo), as a combobox's list // or a button's popover, count as inside it, as does the element it is // attached to, as PressedOutside has them: a combobox closes as the focus // leaves its field, but not as it moves into its list. // // field := ui.TextInput(c, &app.query) // if field.FocusLeft() { // app.open = false // } // // Where the focus went is what the elements tell as they are built // (Focused, FocusWithin), and a Handle's FocusWithin before its control // is. func (_handle Element) FocusLeft() bool { _node := _handle.node() if _node == nil { return false } _ctx := _node.c _ = _ctx return _node.FocusLeft() } // FocusRing sets whether MyGo rings the element when it has the keyboard // focus from the keyboard, as it does by default. Widgets that ring a part // of themselves instead, as a check box its box, turn it off and draw // their own with Painter.FocusRing while FocusVisible. func (_handle Element) FocusRing(show bool) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.FocusRing(show)) } // FocusRingColor sets the color of the element's focus ring, in place of // the theme's Focus, as for an element on a background the theme's ring // does not stand out on. func (_handle Element) FocusRingColor(color Color) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.FocusRingColor(color)) } // FocusRingOffset sets how far outside the element's edge its focus ring // goes, in DIPs, in place of the theme's FocusRingOffset: 0 puts it on // the edge, and a negative offset inside it, as for an element whose // ancestor clips what goes past it, as a header in an accordion's box. // Its corners follow the element's, as CSS's outline does. The widgets // that ring a part of themselves, as a check box its box, ring it so. func (_handle Element) FocusRingOffset(d float32) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.FocusRingOffset(d)) } // FocusVisible reports whether the element has the keyboard focus and // should show it, because it came from the keyboard. func (_handle Element) FocusVisible() bool { _node := _handle.node() if _node == nil { return false } _ctx := _node.c _ = _ctx return _node.FocusVisible() } // FocusWithin reports whether the element or one of its descendants has // the keyboard focus. func (_handle Element) FocusWithin() bool { _node := _handle.node() if _node == nil { return false } _ctx := _node.c _ = _ctx return _node.FocusWithin() } // Focusable lets the element take the keyboard focus, by a click or Tab. func (_handle Element) Focusable() Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Focusable()) } // Focused reports whether the element has the keyboard focus: for a field // around an input, as SearchField's, whether its input has it. func (_handle Element) Focused() bool { _node := _handle.node() if _node == nil { return false } _ctx := _node.c _ = _ctx return _node.Focused() } // Font sets the font family, a comma-separated list: the first family the // system or the app has draws the text, and the others, in order, what it // lacks, before the system's choice. "monospace" and "system-ui" are the // system's own fonts. func (_handle Element) Font(family string) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Font(family)) } // FontFeatures turns on OpenType features of the font, by tag, or sets // them with tag=value: // // ui.Textf(c, "%d items", n).FontFeatures("tnum") // digits of one width // ui.Text(c, "office").FontFeatures("liga=0") // no ligatures // // A font without a feature ignores it. func (_handle Element) FontFeatures(features ...string) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.FontFeatures(features...)) } // FontSize sets the size of text in DIPs, for the element's text and its // descendants'. func (_handle Element) FontSize(v float32) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.FontSize(v)) } // FontWeight sets the weight of text from 100 (thin) to 900 (black). func (_handle Element) FontWeight(w int) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.FontWeight(w)) } // Gap puts space between children, and between the lines of a wrapping // container or the tracks of a grid. func (_handle Element) Gap(v float32) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Gap(v)) } // GapX sets the horizontal space between children, lines or columns. func (_handle Element) GapX(v float32) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.GapX(v)) } // GapY sets the vertical space between children, lines or rows. func (_handle Element) GapY(v float32) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.GapY(v)) } // Gradient fills the element with a linear gradient from one color to // another, at angle degrees clockwise from upwards as in CSS: 180 goes // from top to bottom, 90 from left to right. func (_handle Element) Gradient(from Color, to Color, angle float32) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Gradient(from, to, angle)) } // Grayscale draws the element's image, or icon, in shades of gray. func (_handle Element) Grayscale() Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Grayscale()) } // Grid lays the children out in a grid, as the function Grid does. func (_handle Element) Grid() Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Grid()) } // Grow gives the element a share f of the free space along its parent's // main axis: Grow(1) on one child makes it take all of it. Like CSS flex: // f, the element then starts from no size (unless Basis says otherwise) and // may shrink below its content in a column, which suits a list or editor // filling the rest of a window. func (_handle Element) Grow(f float32) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Grow(f)) } // HandleInput has fn take the element's input as it comes, on the main // thread, before the next frame is built: keys, text and edit commands // while the element has the keyboard focus, the pointer pressed on it, // moving over it, scrolling or pinching over it. fn reports whether it took the // event; one it leaves goes on as it would without fn, to shortcuts, Tab, // context menus and scroll containers. Keys that the window or an element // around the focus handles as a Shortcut go to the shortcut first. A frame // follows the events fn takes. // // It is for widgets that need every key as it is pressed, such as a // terminal, or the scrolling and pinching over them, such as a chart that // zooms and pans; most widgets ask about their input as they are built // instead (Clicked, Shortcut, Dragged). func (_handle Element) HandleInput(fn func(ev InputEvent) bool) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.HandleInput(fn)) } // HandleTextInput connects an element to the system's text-input services. // Pair it with HandleInput for keys, pointer selection and Edit-menu commands, // and Draw for rendering. It adds focus and the text cursor without creating // a text buffer, formatting UI or undo history. A nil client disconnects it. // Existing TextInput/TextArea widgets and TextCaret handlers are unchanged. func (_handle Element) HandleTextInput(client TextInputClient) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.HandleTextInput(client)) } // HasPopup tells assistive technology the kind of popup the element // opens, as a button opening a list of options (PopupListBox) or a menu // (PopupMenu), which Expanded says shows: screen readers read it with the // element ("pop-up button", "menu button") and offer to open it. // PopupNone takes it back. Menu buttons (Menu, PopoverMenuButton, // MenuButton, MenuBase) tell PopupMenu themselves; HasPopup, before or // after, wins over it. func (_handle Element) HasPopup(kind Popup) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.HasPopup(kind)) } // Height sets the height in DIPs. func (_handle Element) Height(v float32) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Height(v)) } // HeightPercent sets the height as a percentage of the parent's. func (_handle Element) HeightPercent(p float32) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.HeightPercent(p)) } // Hidden hides the element and its children when hide is true, as CSS's // display: none does: unlike an Invisible element, it takes no room in // the layout, nor a gap between its siblings, and draws nothing, takes // neither the pointer nor the focus, and is not read by assistive // technology. It is still built, so that what is inside it keeps its // state (scroll offsets, text being edited, animations) while it is // hidden, and shows as it was once hide is false again: // // ui.Column(c).Hidden(!app.showDetails).Children(func() { ... }) // // The focus leaves it as it hides, and what is attached to it // (AttachTo) hides with it. A List's rows are built as the list lays out, // so a hidden List builds none. func (_handle Element) Hidden(hide bool) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Hidden(hide)) } // Highlighted reports whether an option of a select, or an item of a menu // (MenuBase), is the one the pointer or the arrows are on. func (_handle Element) Highlighted() bool { _node := _handle.node() if _node == nil { return false } _ctx := _node.c _ = _ctx return _node.Highlighted() } // HitTest sets where in its box the element takes the pointer: where fn // reports true for the pointer at (x, y), in the coordinates Draw paints // in, r being its box as Draw gets it. Elsewhere the pointer reaches what // is under it, as with PassThrough, so that a pie's segment, a map's // region or a ring takes a press, the hover and the cursor only where it // paints, as SVG's pointer-events: visiblePainted. The elements inside it // take the pointer as they would; fn runs as the pointer moves and // presses, on the window's thread, and only tests: // // ring := func(r ui.Rect) *ui.Path { // var p ui.Path // cx, cy := r.X+r.W/2, r.Y+r.H/2 // return p.Circle(cx, cy, r.W/2).Circle(cx, cy, r.W/2-12).FillRule(ui.EvenOdd) // } // ui.Box(c).Size(120, 120). // Draw(func(p *ui.Painter, r ui.Rect) { p.FillPath(ring(r), accent) }). // HitTest(func(x, y float32, r ui.Rect) bool { return ring(r).Contains(x, y) }). // OnClick(func() { … }) func (_handle Element) HitTest(fn func(x float32, y float32, r Rect) bool) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.HitTest(fn)) } // Hovered reports whether the pointer is over the element. While the // pointer presses an element, the elements it was over as the press began, // as those around the element pressed, stay hovered as long as it is over // them, as in CSS, and the others hover no more: a button that shows over // a row stays as it is pressed, and dragging over other elements does not // light them up. // // Read as the view builds, the pointer coming over the element or leaving // it builds the view anew, every element of it; read in a Draw callback, // as the window paints, it only paints the last frame's elements again, // as the toolkit's controls do for their hovered looks. func (_handle Element) Hovered() bool { _node := _handle.node() if _node == nil { return false } _ctx := _node.c _ = _ctx return _node.Hovered() } // ID returns the element's identity, stable from frame to frame. func (_handle Element) ID() uint64 { _node := _handle.node() if _node == nil { return 0 } _ctx := _node.c _ = _ctx return _node.ID() } // IgnoreInput makes the element and those inside it ignore the pointer // and the keyboard when ignore is true, while they still show and read to // assistive technology. The pointer goes through to what is under them, // as PassThrough lets it: hovering, pressing, scrolling, dragging and the // cursor are those of what is under them. Neither Tab nor a click gives // them the focus, and they lose it as they start ignoring input. Assistive // technology still finds them, with their roles and names, and presses // them, which Clicked reports; it can neither focus them nor move a // slider among them with its keys. A WebView inside them still takes the // pointer, which the system gives its view. // // A control a row shows while it is hovered, as a button deleting it, can // stay built and described at rest, without taking a press meant for the // row: // // row := ui.Row(c).Padding(8) // hovered := row.Hovered() // row.Children(func() { // ui.Text(c, item.Title).Grow(1) // del := ui.Button(c, "Delete").IgnoreInput(!hovered) // if !hovered { // del.Opacity(0) // } // if del.Clicked() { // removed = item.ID // } // }) // // Unlike HTML's inert, it leaves them to assistive technology. Invisible // and Hidden hide them from it too, and Disabled takes their press away; // AccessHidden hides them from it alone. func (_handle Element) IgnoreInput(ignore bool) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.IgnoreInput(ignore)) } // InView reports whether some of the element showed in the window in the // frame before, within the scroll containers and clips around it: to // animate it in as it scrolls into view, as Motion's whileInView. When // what it answers from changes, as a scroll brings the element in, MyGo // builds another frame, so that the view reads the new answer. func (_handle Element) InView() bool { _node := _handle.node() if _node == nil { return false } _ctx := _node.c _ = _ctx return _node.InView() } // InViewAmount reports whether at least amount of the element's area, // from 0 to 1, showed in the frame before, within the window and the // scroll containers and clips around it, grown by margin as InViewMargin // grows them: as IntersectionObserver's threshold, and Motion's amount // for whileInView and useInView, and builds another frame when what it // answers from changes, as InView does. An impression counts once half of a // card shows with 0.5, an animation starts at a fifth of it with 0.2, // and 1 waits for all of it; 0 is InViewMargin. Its area is that of its // box as transforms move it, the box holding them as InView's clips do. // // card := ui.Column(c).Key(ad.ID) // if card.InViewAmount(0.5) { // app.counted(ad.ID) // } func (_handle Element) InViewAmount(amount float32, margin ...float32) bool { _node := _handle.node() if _node == nil { return false } _ctx := _node.c _ = _ctx return _node.InViewAmount(amount, margin...) } // InViewMargin reports whether some of the element showed in the frame // before, as InView does, with the window and the scroll containers // around it grown by margin, in DIPs, CSS style as Padding: all sides, // vertical and horizontal, or top, right, bottom and left. As // IntersectionObserver's rootMargin and scrollMargin, a margin of 200 // has the element in view once it is within 200 DIPs of showing, to load // what it shows before it scrolls in, and a negative one only once it is // that far inside; other clips around it clip it as they do. As InView // does, it has MyGo build another frame when what it answers from changes. func (_handle Element) InViewMargin(margin ...float32) bool { _node := _handle.node() if _node == nil { return false } _ctx := _node.c _ = _ctx return _node.InViewMargin(margin...) } // InputMethod sets whether the system's input methods compose text for the // element while it has the keyboard focus, as they do by default for one // that takes text (HandleTextInput, TextCaret). Turned off, keys type the // characters of the keyboard's layout, which come as InputText, and // nothing is composed: a mode that reads letters as commands, as Vim's // normal mode, gets j as j with a Chinese input method on, as Neovide and // winit's set_ime_allowed(false) have it. Browsers cannot turn input // methods off, and compose still. func (_handle Element) InputMethod(on bool) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.InputMethod(on)) } // InsetShadow adds an inner box shadow, as CSS's box-shadow: inset: offset // by x and y, blurred by blur and grown inward by spread DIPs. It shows // only inside the box's padding edge, within its border and rounded // corners, above the background and below the content. Inner shadows // stack in the order they are added, as outer ones do. func (_handle Element) InsetShadow(x float32, y float32, blur float32, spread float32, c Color) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.InsetShadow(x, y, blur, spread, c)) } // Invalid marks the element's value as not valid, as ARIA's aria-invalid, // without a message: assistive technology reads the element as invalid, // and a text input draws its border in the theme's Danger color, but its // description stays as it is. It suits a required field marked as the // user leaves it empty, whose message waits for the form to be submitted, // or a control whose message is an element of its own (ErrorMessage). On // a Field, it marks the field's control. false leaves the element as it // is: valid, unless Error, or the control's own check of what is typed // into it, marks it. // // ui.TextInput(c, &app.card).Label("Card number"). // Invalid(app.cardTouched && app.card == "") func (_handle Element) Invalid(on bool) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Invalid(on)) } // Invisible hides the element and its children, which keep their room in // the layout but draw nothing and take neither the pointer nor the focus, // as CSS's visibility: hidden does. Hidden takes the room away too. func (_handle Element) Invisible() Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Invisible()) } // IsDisabled reports whether the element or an ancestor is disabled. func (_handle Element) IsDisabled() bool { _node := _handle.node() if _node == nil { return false } _ctx := _node.c _ = _ctx return _node.IsDisabled() } // Italic sets an italic font. func (_handle Element) Italic() Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Italic()) } // Jump sets the value animated under key to value at once, as a drag // moves it under the pointer, and returns it. The value's velocity // follows the jumps from frame to frame, so that a spring taking over // from the last (AnimateTo) keeps going the way it went. func (_handle Element) Jump(key any, value float32) float32 { _node := _handle.node() if _node == nil { return 0 } _ctx := _node.c _ = _ctx return _node.Jump(key, value) } // Justify places the children along the main axis. func (_handle Element) Justify(a Align) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Justify(a)) } // JustifyItems places the children of a grid in their cells horizontally: // Stretch (the default), Start, Center or End. AlignItems places them // vertically. func (_handle Element) JustifyItems(a Align) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.JustifyItems(a)) } // JustifySelf places the element in its grid cell horizontally, overriding // its grid's JustifyItems. func (_handle Element) JustifySelf(a Align) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.JustifySelf(a)) } // KeepFocus leaves the keyboard focus where it is while the element, or // what is inside it, is pressed: the popups and bars of a control that // keeps typing while the user picks in them, as a combobox's options or a // code editor's completions and find buttons. func (_handle Element) KeepFocus() Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.KeepFocus()) } // KeepOpen keeps a menu open as its item is chosen (MenuBase, // ContextMenuBase): by the pointer, Enter or Space, the item reports // Clicked and stays highlighted, as a check box item flipping a setting // one may flip again, or a radio item of a Group switching the theme // while the menu shows it. func (_handle Element) KeepOpen() Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.KeepOpen()) } // KeepScrollbars keeps this scroll container's scroll bars showing while its // content overflows it, with the pointer over it or not, rather than only // while it is hovered or a bar is dragged: a view whose place in its content // matters, as a long diff filling a window, shows how far down it is. The // bars look and take presses as they do on hover; Scrollbars(false) and // ScrollbarAxes still hide them. It applies where Scrollbars does (a code // editor's State has KeepScrollbars), and is not inherited. func (_handle Element) KeepScrollbars(keep bool) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.KeepScrollbars(keep)) } // KeyShortcuts tells assistive technology a key, with exactly the // modifiers mods, that presses or focuses the element, as ARIA's // aria-keyshortcuts: the window's shortcut that runs a toolbar button's // command, or opens a command palette, which screen readers read with the // element's name. It is written as the platform's menus write it ("⌘K" // for Cmd+K on macOS, "Ctrl+K" elsewhere). It only tells the key: handle // it with Shortcut on the context, or OnWindowShortcut. Call it once for // each key that does. func (_handle Element) KeyShortcuts(mods Modifiers, key Key) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.KeyShortcuts(mods, key)) } // Keyboard chooses the on-screen keyboard's layout for a text input, on // phones and tablets. func (_handle Element) Keyboard(k KeyboardType) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Keyboard(k)) } // Keyframes plays a sequence, holding its last value when done. It starts // on the first call, with the first frame's value. Keep the element and // key stable, and change Run when changing the sequence. Only active // playback asks for animation frames. Reduced motion completes playback at // its final value, including when the preference changes mid-sequence, // unless the options' NonMotion says the sequence moves nothing. func (_handle Element) Keyframes(key any, frames []Keyframe, options ...KeyframeOptions) float32 { _node := _handle.node() if _node == nil { return 0 } _ctx := _node.c _ = _ctx return _node.Keyframes(key, frames, options...) } // Label names the element for assistive technology and for finding it in // tests, when its text does not. func (_handle Element) Label(s string) Element { _node := _handle.node() if _node == nil { return Element{} } _ctx := _node.c _ = _ctx return wrapElement(_node.Label(s)) } // LabelledBy has label, a text the view draws as the element's caption, // name the element for assistive technology, in place of its Label or the // text inside it, as ARIA's aria-labelledby does, and gives a click on // label to the element, as HTML's