Switch from Asuka to MyGo, keeping the API client and the feature set: - servers: saved servers, passwordless and password login, proxy, self-signed certificates, per-server device tokens (Keystore), connect form, instance list sheet with switch/disconnect - sessions: virtualized list, search, new session, rename/archive/delete, running indicator, event stream keeps it live - chat: pushed window with system back bar, streaming Markdown via ui/markdown, reasoning and tool rows with image previews, footer menu (read aloud via a Kotlin TTS plugin, copy, fork), user message menu (copy, revert, fork), context usage ring and detail sheet, attachments (photos/files via the document picker), permissions - release builds allow plain http:// LAN servers (Go's net/http dials directly, no cleartext manifest needed) - a local fork of MyGo (third_party/mygo) lowers the Android host's minSdk to 24 (Android 7.0); Go 1.27.4 via mise Version 0.3.0.
9397 lines
306 KiB
Go
9397 lines
306 KiB
Go
// 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 <label for> does: the click focuses it,
|
||
// as a text input, or in a group of controls, as a RadioGroup, the one
|
||
// chosen, else the first, and clicks a check box, a switch or a radio
|
||
// button, as a Field's label does. Call it once both are built, before or
|
||
// after the element:
|
||
//
|
||
// label := ui.Text(c, "Card number").TextColor(t.TextMuted)
|
||
// ui.TextInput(c, &app.card).LabelledBy(label)
|
||
//
|
||
// A label that is no text names the element by its Label.
|
||
func (_handle Element) LabelledBy(label Element) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.LabelledBy(label.nodeFor(_ctx.rt)))
|
||
}
|
||
|
||
// Lang sets the language of the element's text, and of the text of the
|
||
// elements inside it, as a BCP 47 tag, as HTML's lang attribute does: the
|
||
// system's text stack draws the glyphs of that language, as the Han
|
||
// characters Chinese and Japanese draw apart, and falls back to its
|
||
// fonts. Text is in the language the app shows (mygo.App.Locale) unless
|
||
// told otherwise: a Japanese quote in a Chinese app,
|
||
//
|
||
// ui.Text(c, "直").Lang("ja")
|
||
//
|
||
// Korean text ("ko", "ko-KR") breaks its lines between words, at spaces
|
||
// and after punctuation, as Korean is written and as CSS's word-break:
|
||
// keep-all has it, rather than between any two syllables; a word longer
|
||
// than a line still breaks within it. "" takes the language of the
|
||
// elements around it. Browsers draw text in the page's language whatever
|
||
// the element's.
|
||
func (_handle Element) Lang(tag string) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Lang(tag))
|
||
}
|
||
|
||
// LayoutBounds returns the previous frame's border box before transforms,
|
||
// in the layout's window coordinates. Draw callbacks use these coordinates.
|
||
func (_handle Element) LayoutBounds() Rect {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return *new(Rect)
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return _node.LayoutBounds()
|
||
}
|
||
|
||
func (_handle Element) Left(v float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Left(v))
|
||
}
|
||
|
||
func (_handle Element) LeftPercent(p float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.LeftPercent(p))
|
||
}
|
||
|
||
// LetterSpacing adds v DIPs after every character of text, or tightens it
|
||
// with a negative v, as for labels in capitals; 0 takes away that of the
|
||
// text around it, as for a number within such a label.
|
||
func (_handle Element) LetterSpacing(v float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.LetterSpacing(v))
|
||
}
|
||
|
||
// Level tells assistive technology the rank of a heading, from 1 for the
|
||
// highest, or how deep an item of a tree is, from 1 at the top.
|
||
func (_handle Element) Level(n int) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Level(n))
|
||
}
|
||
|
||
// LineHeight sets the height of lines of text as a multiple of the font
|
||
// size.
|
||
func (_handle Element) LineHeight(m float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.LineHeight(m))
|
||
}
|
||
|
||
// LinearGradient fills the element with a gradient, of which Gradient sets
|
||
// only the colors and the angle.
|
||
func (_handle Element) LinearGradient(g LinearGradient) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.LinearGradient(g))
|
||
}
|
||
|
||
// Lines makes a text area as high as its text, wrapped at its width, from
|
||
// min lines up to max, past which it scrolls, as a message field grows with
|
||
// what is typed: TextArea(c, &draft).Lines(1, 8). Without it, a text area is
|
||
// as high as its paragraphs, three lines at least, unless given a height.
|
||
func (_handle Element) Lines(min int, max int) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Lines(min, max))
|
||
}
|
||
|
||
// LocalToWindow maps a point in the previous frame's border box to the window.
|
||
func (_handle Element) LocalToWindow(x float32, y float32) (float32, float32) {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return 0, 0
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return _node.LocalToWindow(x, y)
|
||
}
|
||
|
||
// LongPressed reports whether a finger held the element still for half a
|
||
// second since the last frame, on a touch screen. The press then clicks
|
||
// nothing as it lifts.
|
||
func (_handle Element) LongPressed() bool {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return false
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return _node.LongPressed()
|
||
}
|
||
|
||
// Loop returns the progress of an animation that starts over every
|
||
// period, from 0 to 1 along ease, and keeps frames coming while the
|
||
// element is built; key tells apart the animations of the element. A
|
||
// spinner turns with Loop("spin", time.Second, ui.Linear) * 360, and a
|
||
// placeholder pulses with an opacity of 0.5 + 0.5*Loop("pulse", d,
|
||
// ui.Bounce(ui.EaseInOut)).
|
||
func (_handle Element) Loop(key any, period time.Duration, ease Easing) float32 {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return 0
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return _node.Loop(key, period, ease)
|
||
}
|
||
|
||
// Margin sets the space around the element, as Padding does. Auto
|
||
// margins take the free space on their side.
|
||
func (_handle Element) Margin(v ...float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Margin(v...))
|
||
}
|
||
|
||
func (_handle Element) MarginEnd(v float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.MarginEnd(v))
|
||
}
|
||
|
||
// MarginStart and MarginEnd set the margin on the side lines start and
|
||
// on the other, as PaddingStart does: Auto takes the free space there, so
|
||
// that a Row's child with MarginStart(ui.Auto) goes to its end.
|
||
func (_handle Element) MarginStart(v float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.MarginStart(v))
|
||
}
|
||
|
||
// MarginX sets the left and right margins.
|
||
func (_handle Element) MarginX(v float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.MarginX(v))
|
||
}
|
||
|
||
// MarginY sets the top and bottom margins.
|
||
func (_handle Element) MarginY(v float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.MarginY(v))
|
||
}
|
||
|
||
// MaskConicGradient masks the element and what is inside it by a conic
|
||
// gradient, as MaskLinearGradient does by a linear one: a ring revealed
|
||
// as its stops turn.
|
||
func (_handle Element) MaskConicGradient(g ConicGradient) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.MaskConicGradient(g))
|
||
}
|
||
|
||
// MaskLinearGradient masks the element and what is inside it by a linear
|
||
// gradient across its box, as CSS's mask-image: linear-gradient() does:
|
||
// each point shows as much as the gradient's alpha there, whatever its
|
||
// colors, and nothing shows outside the box (or the inset of ClipInset).
|
||
// A list whose rows fade out at its top and bottom edges:
|
||
//
|
||
// black := ui.RGB(0, 0, 0)
|
||
// fade := []ui.GradientStop{{ui.Transparent, 0}, {black, 0.1}, {black, 0.9}, {ui.Transparent, 1}}
|
||
// list.MaskLinearGradient(ui.LinearGradient{Angle: 180, Stops: fade})
|
||
//
|
||
// Each thing drawn is masked on its own, rather than the element drawn
|
||
// into a layer first, as Opacity fades a group: where the mask lets a
|
||
// part through, a row's background shows what is under it too.
|
||
func (_handle Element) MaskLinearGradient(g LinearGradient) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.MaskLinearGradient(g))
|
||
}
|
||
|
||
// MaskRadialGradient masks the element and what is inside it by a radial
|
||
// gradient, as MaskLinearGradient does by a linear one: a vignette, or a
|
||
// spotlight.
|
||
func (_handle Element) MaskRadialGradient(g RadialGradient) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.MaskRadialGradient(g))
|
||
}
|
||
|
||
// Masks masks the element and what is inside it by layers of masks, the
|
||
// first on top, each composited with those after it as its Composite
|
||
// says, as CSS's mask-image with mask-composite does: each point shows as
|
||
// much as the result's alpha there, and nothing shows outside the box (or
|
||
// the inset of ClipInset). It replaces MaskLinearGradient and the others,
|
||
// which make one layer, and they replace it. A ring 1.5 DIPs wide, of a
|
||
// gradient, its middle cut out by a layer over the content box:
|
||
//
|
||
// black := ui.RGB(0, 0, 0)
|
||
// solid := ui.LinearGradient{From: black, To: black}
|
||
// ui.Box(c).Size(120, 40).Radius(20).Padding(1.5).Gradient(pink, violet, 90).Masks(
|
||
// ui.Mask{Image: solid, Box: ui.MaskContentBox, Composite: ui.MaskExclude},
|
||
// ui.Mask{Image: solid},
|
||
// )
|
||
//
|
||
// and a crescent, a disc less one beside it:
|
||
//
|
||
// disc := func(x, y float32) ui.RadialGradient {
|
||
// return ui.RadialGradient{Center: ui.Point{X: x, Y: y}, Radius: 40,
|
||
// Stops: []ui.GradientStop{{black, 0.98}, {ui.Transparent, 1}}}
|
||
// }
|
||
// moon.Masks(ui.Mask{Image: disc(0.5, 0.5), Composite: ui.MaskSubtract}, ui.Mask{Image: disc(0.7, 0.35)})
|
||
//
|
||
// Layers that are not one gradient across the border box make a mask of
|
||
// their alpha, drawn once for each size the element paints at.
|
||
func (_handle Element) Masks(layers ...Mask) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Masks(layers...))
|
||
}
|
||
|
||
func (_handle Element) MaxHeight(v float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.MaxHeight(v))
|
||
}
|
||
|
||
func (_handle Element) MaxHeightPercent(p float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.MaxHeightPercent(p))
|
||
}
|
||
|
||
// MaxLength keeps the user from making a text input's value longer than n,
|
||
// counted as HTML's maxlength counts it, in UTF-16 code units, a newline
|
||
// as one: text typed, pasted or committed by an input method is cut to
|
||
// what fits at the caret, and replacing a selection takes what fits in its
|
||
// place. A value the app sets is not cut. n <= 0 means no limit.
|
||
// Like ReadOnly, it holds for the input that comes until the next frame.
|
||
func (_handle Element) MaxLength(n int) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.MaxLength(n))
|
||
}
|
||
|
||
// MaxLines shows at most n lines of the element's text, ending it with an
|
||
// ellipsis.
|
||
func (_handle Element) MaxLines(n int) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.MaxLines(n))
|
||
}
|
||
|
||
func (_handle Element) MaxWidth(v float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.MaxWidth(v))
|
||
}
|
||
|
||
func (_handle Element) MaxWidthPercent(p float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.MaxWidthPercent(p))
|
||
}
|
||
|
||
// MaximizeButton marks the element as the window's maximize button, which
|
||
// the view draws in a window with a hidden title bar without the system's
|
||
// (mygo.WindowOptions.HideWindowButtons): on Windows 11, holding the
|
||
// pointer over it shows the snap layouts, as over the system's. It takes
|
||
// the pointer as any element does, and the view maximizes the window when
|
||
// it is clicked (mygo.Window.Maximize). The first such element of a frame
|
||
// counts; elsewhere it does nothing.
|
||
func (_handle Element) MaximizeButton() Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.MaximizeButton())
|
||
}
|
||
|
||
// Menu makes the element a menu button: it opens a menu below it, which
|
||
// build fills with items, as the pointer goes down on it, as a pop-up
|
||
// button does, and for Enter, Space or Down while it has the focus. It
|
||
// takes the focus. build runs when the menu opens, and again in the frame
|
||
// after an item was chosen, where the item's Chosen reports it, as for
|
||
// ContextMenu. MenuButton is a button with a menu:
|
||
//
|
||
// more := ui.ButtonBase(c).Label("More").Padding(4).Radius(6)
|
||
// more.Children(func() { ui.Icon(c, moreIcon).Size(16, 16) })
|
||
// more.Menu(func(m *ui.Menu) {
|
||
// if m.Item("Duplicate").Chosen() {
|
||
// app.duplicate()
|
||
// }
|
||
// })
|
||
//
|
||
// PopoverMenuButton draws the same menu in the window, with the theme's
|
||
// look, as Menu does while the window draws its menus
|
||
// (SetMenuPresentation).
|
||
func (_handle Element) Menu(build func(m *Menu)) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Menu(build))
|
||
}
|
||
|
||
func (_handle Element) MinHeight(v float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.MinHeight(v))
|
||
}
|
||
|
||
func (_handle Element) MinHeightPercent(p float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.MinHeightPercent(p))
|
||
}
|
||
|
||
// MinWidth, MinHeight, MaxWidth and MaxHeight bound the size in DIPs.
|
||
func (_handle Element) MinWidth(v float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.MinWidth(v))
|
||
}
|
||
|
||
// MinWidthPercent, MinHeightPercent, MaxWidthPercent and MaxHeightPercent
|
||
// bound the size by a percentage of the parent's. With a bound in DIPs
|
||
// too, both apply: the larger minimum and the smaller maximum, as CSS's
|
||
// max-width: min(78%, 34rem) for a chat bubble:
|
||
//
|
||
// ui.Box(c).MaxWidthPercent(78).MaxWidth(544)
|
||
func (_handle Element) MinWidthPercent(p float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.MinWidthPercent(p))
|
||
}
|
||
|
||
// Mixed tells assistive technology that the element, a check box, is
|
||
// partly on, as one checking a group whose boxes differ.
|
||
func (_handle Element) Mixed() Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Mixed())
|
||
}
|
||
|
||
// Modal makes the element, built in an Overlay, a dialog's backdrop, as
|
||
// DialogBase's: while it shows, the focus moves into it, Tab goes round
|
||
// the elements inside it, the window's shortcuts built outside it wait,
|
||
// and assistive technology sees it and what shows above it alone, as what
|
||
// is behind it is inert. Build the dialog inside it.
|
||
func (_handle Element) Modal() Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Modal())
|
||
}
|
||
|
||
// Multiline tells assistive technology that an element of the text box
|
||
// role (Role(RoleTextField)) that MyGo does not edit takes several lines,
|
||
// as ARIA's aria-multiline. Text inputs and text areas know it
|
||
// themselves, from the control they are, and other roles ignore it.
|
||
func (_handle Element) Multiline(on bool) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Multiline(on))
|
||
}
|
||
|
||
// Multiselectable tells assistive technology whether the user chooses
|
||
// several of the items of the element, a list, grid, tree or tree grid
|
||
// of your own, as ARIA's aria-multiselectable: screen readers offer to
|
||
// choose more than one. Its rows or items say which are chosen with
|
||
// Checked, or Selected, which shows it too. Lists, tables and grid views
|
||
// with a Selection tell it themselves.
|
||
func (_handle Element) Multiselectable(on bool) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Multiselectable(on))
|
||
}
|
||
|
||
// NoShadow takes off the outer and inner shadows added so far, as CSS's
|
||
// box-shadow: none, so that the Shadow and InsetShadow calls after it
|
||
// start afresh.
|
||
func (_handle Element) NoShadow() Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.NoShadow())
|
||
}
|
||
|
||
// NoWrap keeps each line of the element's text whole, breaking it only at
|
||
// newlines, even where it overflows the element.
|
||
func (_handle Element) NoWrap() Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.NoWrap())
|
||
}
|
||
|
||
// ObjectPosition places an Image's picture in its box where Fit leaves
|
||
// room around it, or crops it, as CSS's object-position: x and y are
|
||
// fractions of that room across and down, 0 by the left or top edge, 1 by
|
||
// the right or bottom one, and 0.5, as by default, in the middle. An
|
||
// avatar's face, near the top of its photo, stays in view with
|
||
//
|
||
// ui.Image(c, photo).Size(40, 40).Fit(ui.Cover).ObjectPosition(0.5, 0.15)
|
||
//
|
||
// as object-position: 50% 15%; the edge keywords are 0 and 1, as
|
||
// ObjectPosition(1, 0) for right top. Values beyond 0 and 1 move the
|
||
// picture further, past the box's edges.
|
||
func (_handle Element) ObjectPosition(x float32, y float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.ObjectPosition(x, y))
|
||
}
|
||
|
||
// ObserveInput has fn see the input that comes to the element or to an
|
||
// element inside it, without taking it, as an ancestor listening to the
|
||
// keydown events that bubble up to it from the focus: keys pressed and
|
||
// released (with Repeat), text typed and composed, and the edit commands
|
||
// of the menus while the element or one of its descendants has the
|
||
// keyboard focus, and the pointer pressed and released over it. fn runs on
|
||
// the main thread before the element the input goes to gets it (the
|
||
// capture phase of UI Events), the outermost of the elements observing
|
||
// first, with X and Y relative to its own box; the input then goes on as
|
||
// it would without fn, to HandleInput, the text inputs, shortcuts, Tab and
|
||
// the rest, which may move the focus. A frame follows the input fn sees.
|
||
//
|
||
// fn sees what HandleInput would see at the focus, whatever takes it,
|
||
// keys a Shortcut takes and Tab among them, but not the keys the system or
|
||
// the menus take before the window gets them (an edit command of the menus
|
||
// comes instead, InputCommand), the keys a web view takes while it has the
|
||
// focus, nor the input of the popovers, menus and dialogs the element
|
||
// opens, which are not inside it. A key that moved the focus, as Tab,
|
||
// comes up where the focus went, as with UI Events. A disabled element
|
||
// observes nothing.
|
||
//
|
||
// It is for a region that reacts to any input in it, such as a demo that
|
||
// stops playing at the first key pressed in it, or a panel that closes a
|
||
// hint as soon as one of its fields is typed in.
|
||
func (_handle Element) ObserveInput(fn func(ev InputEvent)) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.ObserveInput(fn))
|
||
}
|
||
|
||
// OnPaste has fn see a paste into a text input, by Cmd+V, Ctrl+V or a
|
||
// Paste menu item, before it is inserted, on the main thread as the paste
|
||
// comes: text is the clipboard's text, empty when it holds none, as with
|
||
// an image, which fn reads with Services.ReadClipboardData. fn reports
|
||
// whether it took the paste; a paste taken changes nothing, its selection
|
||
// and undo history included, as when a web page prevents a paste's
|
||
// default and attaches a large block instead of inserting it. Like
|
||
// ReadOnly, it holds for the input that comes until the next frame.
|
||
//
|
||
// fn runs between frames, where an Element kept from the view is no
|
||
// longer valid, and the input writes what it holds over its bound value,
|
||
// so setting the value from fn is lost. To put text of its own in place
|
||
// of the paste, as a link to an image it attaches, fn keeps the text and
|
||
// the view inserts it with ReplaceText as it is built again, which a
|
||
// paste seen by fn does at once:
|
||
//
|
||
// svc := c.Services()
|
||
// in := ui.TextArea(c, &app.draft).OnPaste(func(string) bool {
|
||
// img := svc.ReadClipboardData(transfer.PNG)
|
||
// if len(img.Items()) == 0 {
|
||
// return false // text pastes as usual
|
||
// }
|
||
// app.insert = app.attach(img) // ""
|
||
// return true
|
||
// })
|
||
// if app.insert != "" {
|
||
// start, end := in.TextSelection()
|
||
// in.ReplaceText(start, end, app.insert) // a step of undo
|
||
// app.insert = ""
|
||
// }
|
||
func (_handle Element) OnPaste(fn func(text string) bool) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.OnPaste(fn))
|
||
}
|
||
|
||
// OnTextKey has fn see a key pressed in the text input before the input
|
||
// takes it, on the main thread as the key comes, with the text typed
|
||
// before it in place, as AppKit's doCommandBySelector and a web page's
|
||
// keydown on a text field: Enter that sends a message, Up that edits the
|
||
// last one, Tab that accepts a completion, Escape that cancels, Cmd+Enter.
|
||
// fn reports whether it took the key; one taken changes nothing but what
|
||
// fn sets: a text area inserts no newline, a single-line input does not
|
||
// submit, Tab does not move the focus. One left goes on as it would
|
||
// without fn.
|
||
//
|
||
// fn sees the keys that type no text: those with Cmd or Ctrl, and Enter,
|
||
// Tab, Escape, Backspace, Delete, the arrows and the other keys that move
|
||
// the caret, as pressed (macOS's Control keys that move the caret too).
|
||
// While an input method composes, its keys are its own. Keys that the
|
||
// window or an element around the focus handles as a Shortcut go to the
|
||
// shortcut first, as with HandleInput, unless the input edits with them,
|
||
// as with Enter and the arrows. Like ReadOnly, OnTextKey holds for the
|
||
// input that comes until the next frame.
|
||
//
|
||
// fn runs between frames, where an Element kept from the view is no longer
|
||
// valid: it reads and replaces the text through k instead, as a chat
|
||
// composer sends with Enter, clears what it sent, and breaks the line with
|
||
// Shift+Enter:
|
||
//
|
||
// ui.TextArea(c, &app.draft).OnTextKey(func(k ui.TextKey) bool {
|
||
// if k.Key != ui.KeyEnter || k.Mods != 0 {
|
||
// return false // Shift+Enter breaks the line
|
||
// }
|
||
// app.send(k.Text())
|
||
// k.SetText("")
|
||
// return true
|
||
// })
|
||
func (_handle Element) OnTextKey(fn func(k TextKey) bool) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.OnTextKey(fn))
|
||
}
|
||
|
||
// OnUnmount has fn run when the element goes: once, on the main thread,
|
||
// after the first frame that no longer builds it, as a Local that is an
|
||
// io.Closer closes, without a type to give a Close. A view stops in fn
|
||
// the work it started, as a streaming request, a ticker or a
|
||
// subscription:
|
||
//
|
||
// e := ui.Column(c)
|
||
// cancel := ui.Local(e, "feed", func() context.CancelFunc {
|
||
// ctx, cancel := context.WithCancel(context.Background())
|
||
// go read(ctx, url)
|
||
// return cancel
|
||
// })
|
||
// e.OnUnmount(*cancel)
|
||
//
|
||
// Call it as the element is built, after Key: each call replaces the
|
||
// function, and the last one given runs. A frame that does not call it
|
||
// keeps the one given before, and a nil fn takes it away. An element
|
||
// leaving with an exit transition runs fn once its exit ended, and every
|
||
// element as its window closes. fn may change the app's state; ask for
|
||
// the frame that shows it with Window.Invalidate, or Invalidate of the
|
||
// c.Services() the view kept.
|
||
func (_handle Element) OnUnmount(fn func()) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.OnUnmount(fn))
|
||
}
|
||
|
||
// Opacity makes the element and its children translucent as one group,
|
||
// as CSS's opacity does: what they paint is composited first and then
|
||
// faded, so that children overlapping one another, or the element's
|
||
// background under them, never show through each other. Where nothing
|
||
// they paint overlaps, they paint faded each on its own, which looks the
|
||
// same and costs nothing more; otherwise they render into a layer of the
|
||
// GPU first, in which text is smoothed in grayscale, as in Cache's. A web
|
||
// view or a material reading its backdrop inside the element shows
|
||
// through no layer: there each thing fades on its own. Disabled's dimming
|
||
// fades each thing on its own too.
|
||
func (_handle Element) Opacity(o float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Opacity(o))
|
||
}
|
||
|
||
// Orientation tells assistive technology which way the element runs, as
|
||
// ARIA's aria-orientation: Vertical for a slider, separator, splitter,
|
||
// toolbar, tab list or menu of your own going up and down, which screen
|
||
// readers then read as vertical, Horizontal for one going across. It only tells it: the view lays the element out and
|
||
// handles its keys itself (FocusGroup). A slider or a separator told
|
||
// neither runs across, a separator taller than wide up and down; other
|
||
// elements have no orientation. A SliderBase going up says so itself
|
||
// (Vertical).
|
||
//
|
||
// ui.Box(c).Size(4, 200).Draw(drawTrack).
|
||
// Role(ui.RoleSlider).Label("Volume").Range(0, 100, app.volume).
|
||
// Focusable().Orientation(ui.Vertical)
|
||
//
|
||
// Any other value, as Horizontal|Vertical, takes it back.
|
||
func (_handle Element) Orientation(o Orientation) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Orientation(o))
|
||
}
|
||
|
||
// OverlayShortcut reports whether the key with exactly the modifiers mods
|
||
// was pressed for the element, an overlay, which gets the keys the focused
|
||
// element and those around it leave, wherever the focus is: the overlay
|
||
// built last first, so that Escape closes the one on top. Overlays close
|
||
// with it, as PopoverBase and DialogBase do:
|
||
//
|
||
// if panel.OverlayShortcut(0, ui.KeyEscape) {
|
||
// app.open = false
|
||
// }
|
||
func (_handle Element) OverlayShortcut(mods Modifiers, key Key) bool {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return false
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
_ctx.rt.applyInputs()
|
||
return _node.OverlayShortcut(mods, key)
|
||
}
|
||
|
||
// Padding sets the space inside the element's edges, CSS style: all
|
||
// sides, vertical and horizontal, or top, right, bottom and left.
|
||
func (_handle Element) Padding(v ...float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Padding(v...))
|
||
}
|
||
|
||
func (_handle Element) PaddingEnd(v float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.PaddingEnd(v))
|
||
}
|
||
|
||
// PaddingStart sets the padding on the side lines start: the left, or
|
||
// the right of an element laid out right to left, as CSS's
|
||
// padding-inline-start does. PaddingEnd sets the other side's.
|
||
func (_handle Element) PaddingStart(v float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.PaddingStart(v))
|
||
}
|
||
|
||
// PaddingX sets the left and right padding.
|
||
func (_handle Element) PaddingX(v float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.PaddingX(v))
|
||
}
|
||
|
||
// PaddingY sets the top and bottom padding.
|
||
func (_handle Element) PaddingY(v float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.PaddingY(v))
|
||
}
|
||
|
||
// PassThrough lets the pointer reach what is under the element.
|
||
func (_handle Element) PassThrough() Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.PassThrough())
|
||
}
|
||
|
||
// Password hides what a text input holds, in the frames that call it: an
|
||
// input that stops calling it shows its text again, as a field's eye
|
||
// button does. It does nothing to a text area: as on every platform, only
|
||
// single-line fields hide their text.
|
||
func (_handle Element) Password() Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Password())
|
||
}
|
||
|
||
// Perspective sees the element's transform in 3D from distance DIPs in
|
||
// front of its origin (Perspective).
|
||
func (_handle Element) Perspective(distance float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Perspective(distance))
|
||
}
|
||
|
||
// Placeholder shows s in an empty text input. On a field around an input,
|
||
// as SearchField, TokenField and Combobox, it shows in the field's input,
|
||
// in place of the field's own: SearchField shows Search without one.
|
||
func (_handle Element) Placeholder(s string) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Placeholder(s))
|
||
}
|
||
|
||
// PlaceholderColor sets the color of this input's placeholder for this build.
|
||
// When unset it uses the theme's TextMuted. It does not change entered text,
|
||
// other inputs or the theme. A transparent color hides the placeholder.
|
||
func (_handle Element) PlaceholderColor(color Color) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.PlaceholderColor(color))
|
||
}
|
||
|
||
// PointerPosition returns the pointer's position relative to the
|
||
// element's box and whether it is over the element. Elements asking for it
|
||
// get a frame whenever the pointer moves over them. The build that reads
|
||
// the last moves of a press on the element sees where the pointer let go.
|
||
func (_handle Element) PointerPosition() (float32, float32, bool) {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return 0, 0, false
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return _node.PointerPosition()
|
||
}
|
||
|
||
// PopoverMenu gives the element a context menu, as ContextMenu does, which
|
||
// MyGo draws in the window with the theme's look, as a popover, rather
|
||
// than the system showing one of its own. It opens 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. build fills it with the items
|
||
// ContextMenu's function takes, and the item chosen reports Chosen as
|
||
// there:
|
||
//
|
||
// row.PopoverMenu(func(m *ui.Menu) {
|
||
// if m.Item("Rename").Shortcut(0, ui.KeyF2).Chosen() {
|
||
// app.renaming = i
|
||
// }
|
||
// if m.Item("Pinned").Checked(note.pinned).Chosen() {
|
||
// note.pinned = !note.pinned
|
||
// }
|
||
// m.Separator()
|
||
// if m.Item("Delete").Disabled(note.locked).Chosen() {
|
||
// app.delete(i)
|
||
// }
|
||
// })
|
||
//
|
||
// The menu takes the focus as it opens and gives it back as it closes, to
|
||
// the element that had it. Up and Down move 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 a press outside the menu closes it. It shows below
|
||
// and after where it opened, and on the other side where the window has
|
||
// no room. Assistive technology sees a menu of items, check box items and
|
||
// radio items, as the system's. ContextMenuBase is such a menu without a
|
||
// look, for items of a layout of one's own.
|
||
//
|
||
// PopoverMenuButton draws the menu of a menu button so.
|
||
//
|
||
// Its options style the panel of the menu and of its submenus, and the
|
||
// rows of their items, as a menu button's (PopoverMenuOptions): a context
|
||
// menu that unfolds from where it opened, as the app's drawn menu buttons
|
||
// do.
|
||
func (_handle Element) PopoverMenu(build func(m *Menu), options ...PopoverMenuOptions) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.PopoverMenu(build, options...))
|
||
}
|
||
|
||
// PopoverMenuButton makes the element a menu button, as Menu does, whose
|
||
// menu MyGo draws in the window with the theme's look, as PopoverMenu
|
||
// draws a context menu, rather than the system showing one of its own. It
|
||
// opens below the element, or above it where the window has no room, as
|
||
// the pointer goes down on it, and for Enter, Space, Up or Down while it has
|
||
// the focus, which it takes. build fills it with the items Menu's
|
||
// function takes, and the item chosen reports Chosen as there:
|
||
//
|
||
// more := ui.ButtonBase(c).Label("More").Padding(4).Radius(6)
|
||
// more.Children(func() { ui.Icon(c, moreIcon).Size(16, 16) })
|
||
// more.PopoverMenuButton(func(m *ui.Menu) {
|
||
// if m.Item("Duplicate").Chosen() {
|
||
// app.duplicate()
|
||
// }
|
||
// if m.Item("Delete").Disabled(app.locked).Chosen() {
|
||
// app.delete()
|
||
// }
|
||
// })
|
||
//
|
||
// The menu has the keys of PopoverMenu's, and takes the focus as it opens
|
||
// and gives it back as it closes, as there; a press on the element closes
|
||
// it too. Opened by the keyboard, it starts on its first item. Assistive
|
||
// technology sees a menu button, expanded while its menu shows, and the
|
||
// menu as PopoverMenu's. The function PopoverMenuButton is a button with
|
||
// such a menu, as MenuButton is one with a menu of the system's, and
|
||
// MenuBase a menu button without a look.
|
||
//
|
||
// Its options place the menu elsewhere along the button, let the app open
|
||
// and close it, and style its panel (PopoverMenuButtonOptions): the menu
|
||
// of a toolbar's button at the window's end lines up with the button's
|
||
// end, and closes from an event of the app's:
|
||
//
|
||
// more.PopoverMenuButton(build, ui.PopoverMenuButtonOptions{
|
||
// At: ui.AnchorBottomEnd, Self: ui.AnchorTopEnd, Open: &app.moreOpen,
|
||
// })
|
||
func (_handle Element) PopoverMenuButton(build func(m *Menu), options ...PopoverMenuButtonOptions) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.PopoverMenuButton(build, options...))
|
||
}
|
||
|
||
// PositionInSet tells assistive technology which item of its set the
|
||
// element is, pos from 1, and how many items the set has, size, as ARIA's
|
||
// aria-posinset and aria-setsize: for an item of a list, list box, tree,
|
||
// menu or tab list of your own whose set is not what is built around it,
|
||
// as one built only where it shows, or a tree laid out flat in one
|
||
// column (with Level), so that screen readers read "3 of 50". Either at
|
||
// 0 or less is not given: the place the element's widget gives it, if
|
||
// any, stands.
|
||
//
|
||
// for i := app.first; i < app.last; i++ { // only those in view
|
||
// ui.Row(c).Role(ui.RoleOption).PositionInSet(i+1, len(app.results)).
|
||
// Children(func() { ui.Text(c, app.results[i]) })
|
||
// }
|
||
//
|
||
// It wins over the place a ComboboxBase, SelectBase, MenuBase, Tree or
|
||
// GridView gives its items, which counts those it builds, as for a
|
||
// combobox showing the first 50 of 1,000 results. A List's rows keep
|
||
// theirs, which say which of all its rows they are, built or not, and
|
||
// place the rows of its table on macOS and Windows; a row or a cell of a
|
||
// grid of your own says its place with RowIndex and ColumnIndex.
|
||
func (_handle Element) PositionInSet(pos int, size int) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.PositionInSet(pos, size))
|
||
}
|
||
|
||
// PreserveSpaces keeps the spaces the element's text ends its lines with,
|
||
// and a text of only spaces, with their advance, as CSS's white-space:
|
||
// break-spaces does: a gap made of spaces between two texts in a row, or
|
||
// the padding a monospaced column is aligned with. Without it spaces
|
||
// ending a line take no room, as with white-space: normal.
|
||
func (_handle Element) PreserveSpaces() Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.PreserveSpaces())
|
||
}
|
||
|
||
// PressCanceled reports whether the press of the element ended since the
|
||
// last frame without the pointer letting go, as Pointer Events'
|
||
// pointercancel: the system took it (a browser turning a touch into the
|
||
// page's scrolling, the window losing the mouse capture or the pointer's
|
||
// grab, a menu taking the release), or the window lost the keyboard. Such
|
||
// a press clicks nothing (Clicked) and ends no drag (DragEnded), and
|
||
// Pressed turns false: undo what the press began, as a preview a drag
|
||
// showed, rather than commit it.
|
||
//
|
||
// dx, _, held := handle.Dragged()
|
||
// switch {
|
||
// case held:
|
||
// app.preview += dx
|
||
// case handle.PressCanceled():
|
||
// app.preview = 0
|
||
// case app.preview != 0:
|
||
// app.width, app.preview = app.width+app.preview, 0
|
||
// }
|
||
func (_handle Element) PressCanceled() bool {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return false
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return _node.PressCanceled()
|
||
}
|
||
|
||
// Pressed reports whether the element is being pressed with the pointer's
|
||
// primary button, unless it is disabled. A press of another button, as a
|
||
// right-click's, is no press here, as CSS's :active and drags on the web
|
||
// have it: PressedButton tells which button presses the element.
|
||
func (_handle Element) Pressed() bool {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return false
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return _node.Pressed()
|
||
}
|
||
|
||
// PressedButton returns the button of the pointer pressing the element, 0
|
||
// for the primary, 1 the secondary and 2 the middle, while the press
|
||
// lasts, wherever the pointer goes, as Dragged; ok is false while nothing
|
||
// presses it, or it is disabled. Pressed, Dragged, DragVelocity and
|
||
// DragEnded follow the primary button alone; an element that pans with
|
||
// the middle button, as a canvas, reads the button here and where the
|
||
// pointer goes with PointerPosition.
|
||
func (_handle Element) PressedButton() (int, bool) {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return 0, false
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return _node.PressedButton()
|
||
}
|
||
|
||
// PressedInside reports whether the pointer went down since the last
|
||
// frame on the element, inside it, or in a popover attached to it, as
|
||
// PressedOutside reports one outside. Unlike Pressed and Clicked, the
|
||
// element does not take the pointer.
|
||
func (_handle Element) PressedInside() bool {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return false
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return _node.PressedInside()
|
||
}
|
||
|
||
// PressedOutside reports whether the pointer went down since the last
|
||
// frame outside the element: on neither it, nor what it holds, nor the
|
||
// element it is attached to (AttachTo), nor the overlays attached to
|
||
// elements inside it, as the popover of one of its buttons. A popover
|
||
// closes then, the press going on to what is under the pointer, as
|
||
// PopoverBase does. The last press decides: one on the button opening a
|
||
// popover after a press elsewhere, as on a web view's page, in the same
|
||
// frame, keeps it open. A press before the element showed, as the one
|
||
// opening it, is not outside it: an Overlay opened by a press stays.
|
||
func (_handle Element) PressedOutside() bool {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return false
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return _node.PressedOutside()
|
||
}
|
||
|
||
// PressedPointer returns the device pressing the element and how hard it
|
||
// presses, from 0 to 1, as of the press's last move, while the press
|
||
// lasts, as PressedButton; ok is false while nothing presses it, or it is
|
||
// disabled. As InputEvent.Pressure, a device that tells no pressure, as a
|
||
// mouse, presses 0.5. A signature pad widens its stroke with a pen's
|
||
// pressure, and goes by the pointer's speed for a mouse. Elements asking
|
||
// for it get a frame whenever the pointer moves or the pressure changes.
|
||
func (_handle Element) PressedPointer() (PointerType, float32, bool) {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return *new(PointerType), 0, false
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return _node.PressedPointer()
|
||
}
|
||
|
||
// Pretty keeps the last line of each paragraph of the element's text from
|
||
// holding a single word, as CSS's text-wrap: pretty does at least: the
|
||
// line before gives it a word, and the lines before stay as they are. A
|
||
// paragraph of body text then ends on more than one word, at no cost to
|
||
// the rest of its lines; Balance balances them all instead.
|
||
func (_handle Element) Pretty() Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Pretty())
|
||
}
|
||
|
||
// PullToRefresh lets a finger pull a scroll container's content past its top
|
||
// to refresh it, as with iOS's UIRefreshControl and Android's swipe to
|
||
// refresh, each drawn as on its system: an indicator shows, spinning while
|
||
// s.Refreshing. It reports whether the finger just asked to refresh: fetch
|
||
// what's new, and set s.Refreshing to false.
|
||
//
|
||
// list := ui.Scroll(c).Fill()
|
||
// if list.PullToRefresh(&app.refresh) {
|
||
// go func() {
|
||
// items := fetch()
|
||
// win.Update(func() { app.items, app.refresh.Refreshing = items, false })
|
||
// }()
|
||
// }
|
||
func (_handle Element) PullToRefresh(s *RefreshState) bool {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return false
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return _node.PullToRefresh(s)
|
||
}
|
||
|
||
// Query binds *q to the text being typed in a TokenField's input, for an
|
||
// app that looks up suggestions as the user types, as a mail's recipients
|
||
// in an address book. The field writes the text to *q as Query is called,
|
||
// after its constructor took what was typed; what an input method is
|
||
// composing comes as it is committed, as in a text input's value. Adding
|
||
// a token clears it. Changed, asked after Query, also reports a change of
|
||
// the text, for the app to look up after a pause in typing, and the app
|
||
// passes what it found as the suggestions of a later build. The app
|
||
// matches them itself: the field shows them as given, in their order,
|
||
// leaving out only those already tokens, rather than those containing
|
||
// the text, so that a lookup folding accents finds Émile for "emile".
|
||
// Writing *q sets the input's text, as setting a text input's value does,
|
||
// without a change to report. With Query, assistive technology sees a
|
||
// combo box whose suggestions complete what was typed, even while there
|
||
// are none to show. Elements other than a TokenField ignore it.
|
||
//
|
||
// to := ui.TokenField(c, &app.to, app.found).Label("To").Query(&app.query)
|
||
// if to.Changed() {
|
||
// app.typedAt = c.Now() // look up once typing pauses
|
||
// }
|
||
func (_handle Element) Query(q *string) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Query(q))
|
||
}
|
||
|
||
// RadialGradient fills the element with a radial gradient, its colors
|
||
// spreading out from a point (CSS's radial-gradient()), as a glow:
|
||
//
|
||
// ui.Box(c).Size(160, 100).Radius(16).RadialGradient(ui.RadialGradient{
|
||
// Stops: []ui.GradientStop{{ui.RGBA(99, 102, 241, 0.6), 0}, {ui.Transparent, 1}},
|
||
// })
|
||
func (_handle Element) RadialGradient(g RadialGradient) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.RadialGradient(g))
|
||
}
|
||
|
||
// Radius rounds the corners: one radius for all, or top-left, top-right,
|
||
// bottom-right and bottom-left.
|
||
func (_handle Element) Radius(r ...float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Radius(r...))
|
||
}
|
||
|
||
// Range tells assistive technology the range and the value of a slider,
|
||
// progress bar, meter or stepper of your own: value, from lo to hi. Step
|
||
// tells it how far the keys move the value.
|
||
func (_handle Element) Range(lo float64, hi float64, value float64) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Range(lo, hi, value))
|
||
}
|
||
|
||
// ReadOnly makes a text input show its text without letting the user
|
||
// change it: the text can still be selected and copied, from the keyboard
|
||
// too, as it takes the focus, without a caret; assistive technology reads
|
||
// it as read-only.
|
||
//
|
||
// On an element of your own that MyGo does not edit or operate, a widget
|
||
// that draws its value and handles its keys itself, it only tells
|
||
// assistive technology that the element is read-only, as ARIA's
|
||
// aria-readonly, and takes set-value, increment and decrement from it:
|
||
// for a text box
|
||
// (RoleTextField), combo box, check box, switch, slider, stepper, radio
|
||
// group, list box, grid or tree grid, and for the cells and headers
|
||
// (RoleCell, RoleColumnHeader, RoleRowHeader) of a grid or a tree grid,
|
||
// not of a table. Other roles, and MyGo's own controls but for the text
|
||
// inputs and text areas it is meant for, ignore it.
|
||
func (_handle Element) ReadOnly(on bool) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.ReadOnly(on))
|
||
}
|
||
|
||
// ReplaceText replaces the runes of a text input from start to end with s,
|
||
// as an edit, a step of undo of its own: Undo brings back the text the
|
||
// user had, and Redo s again. A command that writes a message replaces all
|
||
// of it, from 0 to math.MaxInt; a completion, the word before the caret.
|
||
// The offsets are kept within the text, as SetTextSelection's, and what was
|
||
// typed in this frame is applied first. Setting the bound value instead
|
||
// takes the new text into the last step, which suits a reformat of what
|
||
// the user typed, not a text that replaces it (see TextInput). As a paste
|
||
// does, it puts the caret after s, and a single-line input takes line
|
||
// breaks as spaces; MaxLength does not cut it, as it does not cut a value
|
||
// the app sets. Changed reports it. It does nothing when the runes are s
|
||
// already.
|
||
func (_handle Element) ReplaceText(start int, end int, s string) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.ReplaceText(start, end, s))
|
||
}
|
||
|
||
// ReturnKey sets what the return key of an on-screen keyboard says, for a
|
||
// single-line input. It submits the input as Enter does; ReturnNext moves
|
||
// the focus on as well.
|
||
func (_handle Element) ReturnKey(k ReturnKeyType) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.ReturnKey(k))
|
||
}
|
||
|
||
// Reverse lays the children out in the other direction: a Row from right
|
||
// to left, a Column from bottom to top, as CSS's row-reverse and
|
||
// column-reverse do. Justify's Start is then the right or the bottom.
|
||
func (_handle Element) Reverse() Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Reverse())
|
||
}
|
||
|
||
func (_handle Element) Right(v float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Right(v))
|
||
}
|
||
|
||
// RightClicked reports a click with the secondary button, as for a
|
||
// context menu.
|
||
func (_handle Element) RightClicked() bool {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return false
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
_ctx.rt.applyInputs()
|
||
return _node.RightClicked()
|
||
}
|
||
|
||
func (_handle Element) RightPercent(p float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.RightPercent(p))
|
||
}
|
||
|
||
// Role sets what the element is to assistive technology, for an element
|
||
// drawn as a widget it is not built from, such as a custom toggle.
|
||
func (_handle Element) Role(r Role) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Role(r))
|
||
}
|
||
|
||
// RoleDescription tells assistive technology what to call the element's
|
||
// role, in place of its own, as ARIA's aria-roledescription: "carousel"
|
||
// for a group of slides, and "slide" for each. Screen readers read it
|
||
// where they would read the role, so give it in the user's language, and
|
||
// keep the role, which says how to use the element. "" reads the role.
|
||
func (_handle Element) RoleDescription(s string) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.RoleDescription(s))
|
||
}
|
||
|
||
// Rotate rotates an element clockwise around its transform origin, which
|
||
// changes no layout sizes. An Icon keeps turning its SVG artwork around its
|
||
// center, as a spinner does:
|
||
//
|
||
// spin := ui.Icon(c, loader)
|
||
// spin.Rotate(spin.Loop("spin", time.Second, ui.Linear) * 360)
|
||
//
|
||
// Use Transform(Rotation(degrees)) to rotate an icon's entire border box.
|
||
func (_handle Element) Rotate(degrees float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Rotate(degrees))
|
||
}
|
||
|
||
// RotateX turns the element in 3D around the horizontal axis through its
|
||
// origin, after its existing transform, as RotationX: follow it with
|
||
// Perspective to see it in depth.
|
||
//
|
||
// card.RotateX(30).Perspective(800)
|
||
func (_handle Element) RotateX(degrees float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.RotateX(degrees))
|
||
}
|
||
|
||
// RotateY turns the element in 3D around the vertical axis through its
|
||
// origin, after its existing transform, as RotationY: a card turning over
|
||
// shows its back past 90 degrees, mirrored.
|
||
//
|
||
// card.RotateY(flip * 180).Perspective(800)
|
||
func (_handle Element) RotateY(degrees float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.RotateY(degrees))
|
||
}
|
||
|
||
// Row lays the children out from left to right.
|
||
func (_handle Element) Row() Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Row())
|
||
}
|
||
|
||
// RowClicked reports, while a row of a List or a Table builds, that the
|
||
// row was clicked since the last frame with the pointer over the element:
|
||
// a row's content acts on a click this way and leaves the click to the
|
||
// row, which goes on choosing, where Clicked would take it, so that the
|
||
// row's ListState.Label names what takes the click, for typing its first
|
||
// letters, screen readers and Tester.Click alike. It reports each click of
|
||
// the primary button without modifiers, on the row chosen too, and not the
|
||
// keys that move the choice, nor a Shift- or Cmd-click extending it. A
|
||
// double click reports its first click here and its second with
|
||
// RowDoubleClicked, as on the systems' own lists. Assistive technology
|
||
// pressing the row, without the pointer, reports it to the first element
|
||
// asking. In a list that does not choose its rows, asking makes the row
|
||
// take the click.
|
||
//
|
||
// ui.List(c, &app.files, len(app.names), func(i int) {
|
||
// if ui.Text(c, app.names[i]).Padding(6, 12).FillWidth().RowClicked() {
|
||
// app.open(i)
|
||
// }
|
||
// })
|
||
func (_handle Element) RowClicked() bool {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return false
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return _node.RowClicked()
|
||
}
|
||
|
||
// RowCount tells assistive technology how many rows a table, grid or tree
|
||
// grid of your own has, built or not, header rows included, as ARIA's
|
||
// aria-rowcount: one that builds only the rows in view says how many it
|
||
// has, which screen readers read with the rows' RowIndex, as "row 4,121
|
||
// of 10,000". The rows of a List and a Table say which of all they are
|
||
// themselves.
|
||
func (_handle Element) RowCount(n int) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.RowCount(n))
|
||
}
|
||
|
||
// RowDoubleClicked reports, while a row of a List or a Table builds, that
|
||
// the row was double-clicked since the last frame with the pointer over the
|
||
// element: a cell sees its row's double click this way and leaves the click
|
||
// to the row, which chooses, where DoubleClicked would take it.
|
||
//
|
||
// ui.Table(c, &app.list, cols, len(app.rows), func(row, col int) {
|
||
// cell := ui.Box(c).FillWidth().Children(func() { ui.Text(c, app.rows[row][col]) })
|
||
// if cell.RowDoubleClicked() {
|
||
// app.edit(row, col)
|
||
// }
|
||
// })
|
||
func (_handle Element) RowDoubleClicked() bool {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return false
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return _node.RowDoubleClicked()
|
||
}
|
||
|
||
// RowIndex tells assistive technology the place of a row, or of a cell,
|
||
// among all the rows of its table, grid or tree grid, from 1 for the
|
||
// first, header rows included, as ARIA's aria-rowindex: for one that
|
||
// builds only the rows in view, with its RowCount. A cell takes its row's.
|
||
func (_handle Element) RowIndex(i int) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.RowIndex(i))
|
||
}
|
||
|
||
// RowSpan makes the element span n rows of its grid, or, for a negative n,
|
||
// every row from its start to the last the grid sets. A cell of a table
|
||
// or a grid tells assistive technology it covers them, as ARIA's
|
||
// aria-rowspan: the cells of the rows below it then say their columns
|
||
// with ColumnIndex where they follow it.
|
||
func (_handle Element) RowSpan(n int) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.RowSpan(n))
|
||
}
|
||
|
||
// RowStart puts the element in row n of its grid, counting from 1.
|
||
func (_handle Element) RowStart(n int) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.RowStart(n))
|
||
}
|
||
|
||
// RowTracks sets the grid's first rows; those it adds after fit their
|
||
// content.
|
||
func (_handle Element) RowTracks(tracks ...Track) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.RowTracks(tracks...))
|
||
}
|
||
|
||
// RowWidth makes the rows of a List at least w DIPs wide, as the columns
|
||
// of a table ask: where they are wider than the list, it scrolls sideways
|
||
// too, and its rows grow to its width where they are not. A header above
|
||
// the rows goes with them through ScrollWith:
|
||
//
|
||
// head := ui.Row(c).Clip().Padding(0, 8).Children(app.columnTitles)
|
||
// list := ui.List(c, &app.rows, n).Padding(0, 8).RowWidth(app.columnsWidth())
|
||
// list.Rows(app.row)
|
||
// head.ScrollWith(list)
|
||
func (_handle Element) RowWidth(w float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.RowWidth(w))
|
||
}
|
||
|
||
// Rows gives the grid n rows of equal height, Fr(1) each.
|
||
func (_handle Element) GridRows(n int) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Rows(n))
|
||
}
|
||
|
||
// Scale scales the element after its existing transform, around its origin.
|
||
func (_handle Element) Scale(x float32, y float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Scale(x, y))
|
||
}
|
||
|
||
// ScrollIntoView scrolls the containers around the element as little as
|
||
// shows it, once the frame is laid out: an element added in this frame
|
||
// comes into view with it. Call it in the frame it should come into view,
|
||
// as when it is added or chosen: in every frame, it would keep the user
|
||
// from scrolling it away.
|
||
//
|
||
// Its options line the element up elsewhere in the containers, or glide
|
||
// there, as the web's scrollIntoView options do: the current match of a
|
||
// search, centered smoothly.
|
||
//
|
||
// if app.matchMoved {
|
||
// hit.ScrollIntoView(ui.ScrollIntoViewOptions{Block: ui.ScrollCenter, Animation: &ui.Smooth})
|
||
// }
|
||
func (_handle Element) ScrollIntoView(options ...ScrollIntoViewOptions) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.ScrollIntoView(options...))
|
||
}
|
||
|
||
// ScrollSnap makes the scroll container (Scroll, ScrollHorizontal,
|
||
// ScrollBoth, List) come to rest at the places the elements in it mark
|
||
// with SnapAlign, as CSS's scroll-snap-type does, on the axes it scrolls:
|
||
//
|
||
// - a touchpad, its momentum after a fling, and a finger on a
|
||
// touchscreen glide on to the nearest once they have settled, and so
|
||
// does a thumb of a scroll bar once it is let go;
|
||
// - a notch of a wheel, the arrow keys, Page Up and Page Down, Home and
|
||
// End and a press on a scroll bar's track go to the next place that
|
||
// way, past where it was, as far as they scroll.
|
||
//
|
||
// A place lines an element up with the container's content box, inside
|
||
// its padding, so that the first of a strip of cards rests where it
|
||
// starts. An element larger than the view rests anywhere it fills the
|
||
// view. Resting at an element, the container stays at it as the layout
|
||
// moves it, as when the window resizes, and an element of one coming into
|
||
// view (ScrollIntoView, the focus) lines it up. Where the app scrolls the
|
||
// container, with its ScrollState, ScrollTo or a List's ListState, it
|
||
// stays. While the desktop asks for less motion, it rests at once.
|
||
//
|
||
// ui.ScrollHorizontal(c).ScrollSnap(ui.SnapMandatory).Padding(16).Gap(12).Children(func() {
|
||
// for _, card := range app.cards {
|
||
// cardView(c, card).SnapAlign(ui.Start)
|
||
// }
|
||
// })
|
||
func (_handle Element) ScrollSnap(s Snap) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.ScrollSnap(s))
|
||
}
|
||
|
||
// ScrollWith moves the element's content sideways as far as scroller, a
|
||
// scroll container, scrolls its own, as a table's header goes with its
|
||
// rows. Clip the element, so that what goes out of it does not show.
|
||
func (_handle Element) ScrollWith(scroller Element) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.ScrollWith(scroller.nodeFor(_ctx.rt)))
|
||
}
|
||
|
||
// ScrollbarAxes controls the horizontal and vertical indicators and their
|
||
// pointer hit targets independently. Both are enabled by default, showing
|
||
// while the container overflows and is hovered, or as KeepScrollbars says.
|
||
// Hiding the axis being dragged ends that drag. Wheel, TrackScroll, keyboard
|
||
// focus and accessibility still scroll both axes.
|
||
// Scrollbars(false) hides both regardless of call order; Scrollbars(true)
|
||
// preserves the axis settings. It applies where Scrollbars does and is not
|
||
// inherited. Omitting it in the next build enables both axes again.
|
||
func (_handle Element) ScrollbarAxes(horizontal bool, vertical bool) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.ScrollbarAxes(horizontal, vertical))
|
||
}
|
||
|
||
// ScrollbarInsets moves a scroll container's scroll bars in from its
|
||
// edges, CSS style as Padding: the vertical bar runs from top DIPs below
|
||
// its top to bottom DIPs above its bottom, right DIPs in from its right,
|
||
// and the horizontal bar from left to right DIPs in, bottom DIPs up. A bar
|
||
// keeps clear so of what floats over the content, as a toolbar the
|
||
// content scrolls under, which AppKit's scrollerInsets and UIKit's scroll
|
||
// indicator insets do:
|
||
//
|
||
// ui.Scroll(c).Fill().Padding(64, 16, 16).ScrollbarInsets(64, 0, 0)
|
||
func (_handle Element) ScrollbarInsets(v ...float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.ScrollbarInsets(v...))
|
||
}
|
||
|
||
// ScrollbarStyle styles this scroll container's scroll bars, as a theme's
|
||
// ScrollbarStyle does every scroll bar: their track and thumb colors, the
|
||
// widths of their bars and thumbs, their corners and shortest thumb. Its
|
||
// zero fields follow the theme's, so leaving it out draws as the theme
|
||
// does; it applies to Scroll, ScrollHorizontal, ScrollBoth, List and Table,
|
||
// and is not inherited.
|
||
//
|
||
// // As VS Code's editor: a 14 DIP square thumb in a 14 DIP bar, flush
|
||
// // with its ends.
|
||
// ui.Scroll(c).ScrollbarStyle(ui.ScrollbarStyle{
|
||
// TrackWidth: 14, ThumbWidth: 14, Square: true, Flush: true, MinLength: 20,
|
||
// Thumb: ui.RGBA(121, 121, 121, 0.4),
|
||
// Hover: ui.RGBA(100, 100, 100, 0.7),
|
||
// Active: ui.RGBA(191, 191, 191, 0.4),
|
||
// })
|
||
func (_handle Element) ScrollbarStyle(s ScrollbarStyle) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.ScrollbarStyle(s))
|
||
}
|
||
|
||
// Scrollbars controls the overlay indicators and their pointer hit targets on
|
||
// this scroll container. They show on hover by default. With false, scrolling
|
||
// by wheel, TrackScroll, keyboard focus and accessibility remains available.
|
||
// It applies to Scroll, ScrollHorizontal, ScrollBoth, List and Table, not the
|
||
// internal indicators of custom controls such as a code editor (whose State
|
||
// has NoScrollbars), and is not inherited.
|
||
func (_handle Element) Scrollbars(visible bool) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Scrollbars(visible))
|
||
}
|
||
|
||
// Search makes a text input one for searching, in the frames that call
|
||
// it, as ARIA's searchbox and HTML's <input type=search>: assistive
|
||
// technology reads it as a search field, as it reads a SearchField's
|
||
// input, while the view draws it as it likes, with an icon and a clear
|
||
// button of its own, and handles its keys. Name it with Label.
|
||
//
|
||
// ui.TextInput(c, &app.query).Placeholder("Search").Label("Search mail").Search()
|
||
func (_handle Element) Search() Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Search())
|
||
}
|
||
|
||
// Selectable lets the user select and copy text by dragging, double-clicking
|
||
// a word, triple-clicking a paragraph, or using Shift with the arrows. Its
|
||
// context menu has Copy and Select All; Cmd+C copies the selection.
|
||
//
|
||
// On a container, its Text and RichText descendants share one selection.
|
||
// Copy joins their selected text with newlines, in the order they were built.
|
||
// Nested Selectable containers have independent selections. Text inside
|
||
// controls, such as buttons and text inputs, keeps the control's interaction.
|
||
// Unselectable excludes a subtree. On a Text or RichText alone, the selection
|
||
// stays within that paragraph. Inline elements share their paragraph's
|
||
// selection; set Selectable on the paragraph.
|
||
func (_handle Element) Selectable() Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Selectable())
|
||
}
|
||
|
||
// Selected shows the element as chosen among its siblings, in the accent
|
||
// color, as a row of a list, and tells assistive technology it is.
|
||
func (_handle Element) Selected(on bool) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Selected(on))
|
||
}
|
||
|
||
// SelectedTexts returns the parts of the paragraphs that the selection of
|
||
// a Selectable container holds, in the order they were built, or none,
|
||
// as of the last frame: to copy them otherwise, as a context menu's item
|
||
// does.
|
||
func (_handle Element) SelectedTexts() []SelectedText {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return nil
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return _node.SelectedTexts()
|
||
}
|
||
|
||
// SelectionColor sets the highlight of selected text in the element and
|
||
// the text inside it, as text on a colored bubble needs one that shows
|
||
// on it; the theme's Selection is the highlight elsewhere.
|
||
func (_handle Element) SelectionColor(c Color) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.SelectionColor(c))
|
||
}
|
||
|
||
// SetChanged reports the element's value as changed in this build pass,
|
||
// as a widget of your own whose input changed what it edits: Changed
|
||
// returns true for it, as for the widgets' own.
|
||
func (_handle Element) SetChanged() Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.SetChanged())
|
||
}
|
||
|
||
// SetTextSelection selects the runes of a text input from start to end, or
|
||
// puts the caret at start when they are equal, and scrolls it into view: the
|
||
// caret after a word the app completed. The offsets are kept within the text.
|
||
func (_handle Element) SetTextSelection(start int, end int) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.SetTextSelection(start, end))
|
||
}
|
||
|
||
// Settled reports whether the value animated under key, by AnimateTo,
|
||
// Animate, Spring or Keyframes, rests at its target in this frame: true
|
||
// for an unknown key.
|
||
func (_handle Element) Settled(key any) bool {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return false
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return _node.Settled(key)
|
||
}
|
||
|
||
// Shadow adds a box shadow, offset by x and y, blurred by blur and grown by
|
||
// spread DIPs. As CSS's box-shadow, it shows only outside the box: a
|
||
// translucent background does not show it through.
|
||
func (_handle Element) Shadow(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.Shadow(x, y, blur, spread, c))
|
||
}
|
||
|
||
// Shortcut reports whether the key with exactly the modifiers mods was
|
||
// pressed while the element or one of its descendants had the focus. The
|
||
// innermost element handling a key gets it; a disabled one handles none.
|
||
func (_handle Element) Shortcut(mods Modifiers, key Key) bool {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return false
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
_ctx.rt.applyInputs()
|
||
return _node.Shortcut(mods, key)
|
||
}
|
||
|
||
// Shrink sets how much the element gives up when its siblings do not fit
|
||
// (1 by default, 0 never).
|
||
func (_handle Element) Shrink(f float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Shrink(f))
|
||
}
|
||
|
||
// SingleLine keeps the element's text on one line, ending it with an
|
||
// ellipsis when it does not fit.
|
||
func (_handle Element) SingleLine() Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.SingleLine())
|
||
}
|
||
|
||
// Size sets the width and height in DIPs.
|
||
func (_handle Element) Size(w float32, h float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Size(w, h))
|
||
}
|
||
|
||
// Skew slants the element after its existing transform, around its
|
||
// origin, by x degrees along the horizontal axis and y along the vertical.
|
||
func (_handle Element) Skew(x float32, y float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Skew(x, y))
|
||
}
|
||
|
||
// SnapAlign marks a place where the nearest scroll container around the
|
||
// element rests, if it snaps (ScrollSnap): where the element's start,
|
||
// center or end, as a is Start, Center or End, lines up with the
|
||
// container's, on both axes, as CSS's scroll-snap-align. Start is the left
|
||
// of what scrolls sideways, its right right to left (Direction), and the
|
||
// top of what scrolls vertically.
|
||
func (_handle Element) SnapAlign(a Align) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.SnapAlign(a))
|
||
}
|
||
|
||
// SnapAlignX marks a place as SnapAlign does, sideways only: a container
|
||
// that scrolls both ways rests anywhere vertically.
|
||
func (_handle Element) SnapAlignX(a Align) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.SnapAlignX(a))
|
||
}
|
||
|
||
// SnapAlignY marks a place as SnapAlign does, vertically only.
|
||
func (_handle Element) SnapAlignY(a Align) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.SnapAlignY(a))
|
||
}
|
||
|
||
// Sort tells assistive technology the order a table's rows are sorted in
|
||
// by the column whose header the element is (RoleColumnHeader), as ARIA's
|
||
// aria-sort: for a sortable table of your own, whose headers show it.
|
||
// Table's headers tell it from ListState.Sort and SortBy.
|
||
func (_handle Element) Sort(dir SortDirection) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Sort(dir))
|
||
}
|
||
|
||
// SplitReset makes a double click on the divider of a Split put the first
|
||
// pane at v, in the split's own unit: DIPs for Split and SplitVertical, a
|
||
// percentage for SplitPercent and SplitVerticalPercent. A split without it
|
||
// keeps its size on a double click. The value is kept even when the window
|
||
// is too small to show it, so the pane takes it back when there is room
|
||
// again.
|
||
//
|
||
// ui.Split(c, &app.sidebar, app.files, app.editor).SplitReset(220)
|
||
func (_handle Element) SplitReset(v float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.SplitReset(v))
|
||
}
|
||
|
||
// Spring returns a value following target with a spring, as AnimateTo
|
||
// does with Animation{Spring: options}: Smooth's spring without options.
|
||
func (_handle Element) Spring(key any, target float32, options ...SpringOptions) float32 {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return 0
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return _node.Spring(key, target, options...)
|
||
}
|
||
|
||
// Start and End place an Absolute element from the side lines start and
|
||
// from the other, as Left and Right do, as CSS's inset-inline-start and
|
||
// inset-inline-end: from the left and the right, or the right and the
|
||
// left right to left. On an element in its parent's layout, they move it
|
||
// as relative positioning does.
|
||
func (_handle Element) Start(v float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Start(v))
|
||
}
|
||
|
||
// StartPercent and EndPercent place the element as Start and End do, by
|
||
// a percentage of the parent's width.
|
||
func (_handle Element) StartPercent(p float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.StartPercent(p))
|
||
}
|
||
|
||
// Step makes the values of a slider lo and the multiples of step from it,
|
||
// which the arrows move between, as a StepSlider's. Of a range of your own
|
||
// (Range), it tells assistive technology how far the keys move the value.
|
||
func (_handle Element) Step(step float64) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Step(step))
|
||
}
|
||
|
||
// Sticky keeps the element in its parent's flow, where it takes its room,
|
||
// and holds it inside the scroll container around it while its parent is
|
||
// in view, as CSS's position: sticky does: Top, Right, Bottom and Left (or
|
||
// Start and End, and their percentages of the container's size) say how far
|
||
// in from the container's edges, inside its border, it stays. It moves no
|
||
// further than its parent's content box, so the parent leaving the view
|
||
// takes it along, and the next one's comes up in its place: a day's heading
|
||
// at the top of a timeline until the next day pushes it out, or the check
|
||
// box choosing all the rows at the left of a table scrolling sideways.
|
||
//
|
||
// ui.Scroll(c).Fill().Children(func() {
|
||
// for _, day := range app.days {
|
||
// ui.Column(c).Children(func() {
|
||
// ui.Text(c, day.Title).Bold().Background(t.Surface).Sticky().Top(0)
|
||
// for _, ev := range day.Events {
|
||
// eventRow(c, ev)
|
||
// }
|
||
// })
|
||
// }
|
||
// })
|
||
//
|
||
// Each axis follows the nearest container scrolling that way, or one
|
||
// following another sideways (ScrollWith), or else the window: a heading
|
||
// in a table scrolling sideways in a page scrolling down sticks to the
|
||
// page's top and to the table's start. Where both insets of an axis are
|
||
// set and the container is too small for both, Top wins, and Left, or
|
||
// Right right to left. Without insets, the element stays where the flow
|
||
// puts it. It paints above its siblings, as Absolute elements do, and the
|
||
// pointer, assistive technology and the focus ring find it where it shows;
|
||
// the focus and assistive technology still take it in its place among
|
||
// them. Sticky does nothing to an Absolute element, nor to one inside a
|
||
// text.
|
||
func (_handle Element) Sticky() Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Sticky())
|
||
}
|
||
|
||
// Strikethrough strikes text through.
|
||
func (_handle Element) Strikethrough() Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Strikethrough())
|
||
}
|
||
|
||
// Stripes draws stripes of c over the background, width DIPs wide with
|
||
// gap DIPs between them, running at angle degrees clockwise from upwards:
|
||
// 0 draws vertical stripes, 90 horizontal ones, and 45 slanting ones like
|
||
// slashes, as to mark what is unavailable.
|
||
func (_handle Element) Stripes(c Color, width float32, gap float32, angle float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Stripes(c, width, gap, angle))
|
||
}
|
||
|
||
// Submitted reports whether Enter was pressed in a single-line text input
|
||
// in this build pass.
|
||
func (_handle Element) Submitted() bool {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return false
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return _node.Submitted()
|
||
}
|
||
|
||
// TabSize puts the tab stops of the element's text every n spaces of its
|
||
// font from the start of each line, as CSS's tab-size: a tab advances
|
||
// to the next of them, as a code block indents with tabs of 2 or 4
|
||
// columns. A space is as wide as the font's, letter spacing included.
|
||
// Without it, or with n at 0, tabs advance as the system's text stack
|
||
// sets them, which differs between systems.
|
||
func (_handle Element) TabSize(n float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.TabSize(n))
|
||
}
|
||
|
||
// TabStop makes the element focusable, and sets whether Tab and Shift+Tab
|
||
// stop at it, as they do at a Focusable element. One that is no tab stop
|
||
// is HTML's tabindex="-1": it takes the focus from a click, from Focus and
|
||
// AutoFocus, and from assistive technology, while Tab passes over it, on
|
||
// to what is inside it and after it: a container that takes the focus to
|
||
// hold its keys, as a card or a dialog's panel, without coming before its
|
||
// own controls.
|
||
func (_handle Element) TabStop(stop bool) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.TabStop(stop))
|
||
}
|
||
|
||
// TextAlign aligns the lines of text: Start, Center or End.
|
||
func (_handle Element) TextAlign(a Align) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.TextAlign(a))
|
||
}
|
||
|
||
// TextAnchorCaret returns the selection of a text input as offsets in runes
|
||
// into its text, from where it was started to its caret: the anchor is after
|
||
// the caret when the selection was made backwards.
|
||
func (_handle Element) TextAnchorCaret() (int, int) {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return 0, 0
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return _node.TextAnchorCaret()
|
||
}
|
||
|
||
// TextBackground fills the lines of text behind it with c, as a
|
||
// highlight.
|
||
func (_handle Element) TextBackground(c Color) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.TextBackground(c))
|
||
}
|
||
|
||
// TextCaret has the element take text from the system's input methods
|
||
// while it has the keyboard focus, with their composition at r, the caret,
|
||
// relative to the element's box: candidate windows show there. Its
|
||
// InputText and Compose events (HandleInput) bring the text.
|
||
func (_handle Element) TextCaret(r Rect) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.TextCaret(r))
|
||
}
|
||
|
||
// TextColor sets the color of text.
|
||
func (_handle Element) TextColor(c Color) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.TextColor(c))
|
||
}
|
||
|
||
// TextRanges styles runs of a text input's text, in the frames that call
|
||
// it. Ranges may overlap and nest, as the attributes of an attributed
|
||
// string do: where they do, each of Color and Weight is that of the last
|
||
// range given that sets it, across the calls of the frame. They follow the
|
||
// text as it is: an app that finds them in the text finds them again as it
|
||
// changes. A password shows none; an input method's composition shows
|
||
// unstyled between them.
|
||
func (_handle Element) TextRanges(ranges ...TextRange) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.TextRanges(ranges...))
|
||
}
|
||
|
||
// TextSelection returns the selection of a text input as offsets in runes
|
||
// into its text, the caret where start equals end, as the app reads it to
|
||
// complete the word being typed.
|
||
func (_handle Element) TextSelection() (int, int) {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return 0, 0
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return _node.TextSelection()
|
||
}
|
||
|
||
// TextShadow casts a shadow of the element's text, as CSS's text-shadow:
|
||
// the shapes of its glyphs, offset by x and y DIPs, blurred by blur, in c,
|
||
// under the glyphs and their strokes, as a chart's labels over its bars
|
||
// or a caption over a photo take one to stand out. The text of the
|
||
// elements inside takes it too, and theirs where they set one; a
|
||
// transparent c casts none, where those around it cast one. A span's
|
||
// Shadow sets one for its text. The shadow of color glyphs, as emoji, is
|
||
// that of their pixels' shape; underlines and strikethroughs cast none.
|
||
//
|
||
// ui.Text(c, "Golden hour").TextColor(ui.RGB(255, 255, 255)).TextShadow(0, 1, 4, ui.RGBA(0, 0, 0, 0.6))
|
||
func (_handle Element) TextShadow(x float32, y float32, blur float32, c Color) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.TextShadow(x, y, blur, c))
|
||
}
|
||
|
||
// TextStroke strokes the outlines of the glyphs of text width DIPs wide
|
||
// in c, under their fill, as CSS's -webkit-text-stroke with paint-order:
|
||
// stroke fill: the half of the stroke outside the glyphs shows around
|
||
// them, a halo of c, as a chart's labels over its bars take one of the
|
||
// background's color to stand out. A text's strokes all go under all
|
||
// its glyphs, so that one glyph's stroke never covers its neighbor; the
|
||
// stroke goes around the edge of the pixels of color glyphs, as emoji.
|
||
// Underlines and strikethroughs are not stroked. A width of 0 strokes
|
||
// nothing, where the elements around it stroke their text.
|
||
func (_handle Element) TextStroke(width float32, c Color) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.TextStroke(width, c))
|
||
}
|
||
|
||
// Timeline returns the timeline the element keeps under key, playing it
|
||
// as o says. Every tween added to it shares one playhead, and returns the
|
||
// value it shows in this frame.
|
||
//
|
||
// card := ui.Column(c)
|
||
// tl := card.Timeline("intro", ui.TimelineOptions{Run: app.opened})
|
||
// x := tl.Tween(ui.Tween{From: -200, To: 0, Duration: 400 * time.Millisecond})
|
||
// card.Translate(x, 0)
|
||
//
|
||
// Key tells apart the timelines of the element, as it does its Keyframes,
|
||
// and an element asks for each of its timelines once per build. Play the
|
||
// timeline again, or a changed one, by changing o.Run. The *Timeline is
|
||
// valid while the view builds this frame.
|
||
//
|
||
// While the desktop asks for less motion (Preferences.ReduceMotion), a
|
||
// timeline that would play is at once where it would come to rest, unless
|
||
// o's NonMotion says it moves nothing, but Seek, Progress and Paused still
|
||
// put and hold its playhead, as a drag still moves a Draggable element.
|
||
// DisableAnimations does not change a timeline, which plays on its own,
|
||
// as Keyframes do: jump it with Seek.
|
||
func (_handle Element) Timeline(key any, o TimelineOptions) *Timeline {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return nil
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return _node.Timeline(key, o)
|
||
}
|
||
|
||
// Tooltip shows s by the element when the pointer rests on it, or the
|
||
// keyboard focus comes to it, as TooltipBase does: above the element,
|
||
// centered, or below it where there is no room above. It describes the
|
||
// element to assistive technology where Description does not.
|
||
func (_handle Element) Tooltip(s string) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Tooltip(s))
|
||
}
|
||
|
||
// Top, Right, Bottom and Left place an Absolute element. On an element in
|
||
// its parent's layout, they move it from where the layout put it, as CSS's
|
||
// relative positioning does, without moving its siblings.
|
||
func (_handle Element) Top(v float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Top(v))
|
||
}
|
||
|
||
// TopPercent, RightPercent, BottomPercent and LeftPercent place the
|
||
// element as Top, Right, Bottom and Left do, by a percentage of the
|
||
// parent's height or width.
|
||
func (_handle Element) TopPercent(p float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.TopPercent(p))
|
||
}
|
||
|
||
// Touches returns the fingers on a touchscreen that landed on the element
|
||
// or on an element inside it, every one down and those that lifted or
|
||
// were canceled since the last build, in the order they landed, unless the
|
||
// element is disabled. Each keeps its ID for as long as it touches, so that
|
||
// a view tells them apart and recognizes gestures of its own, as a
|
||
// whiteboard turning the page as four fingers swipe or clearing it as five
|
||
// tap:
|
||
//
|
||
// for _, t := range canvas.Touches() {
|
||
// switch t.Phase {
|
||
// case ui.TouchBegan, ui.TouchMoved:
|
||
// strokes.Draw(t.ID, t.X, t.Y)
|
||
// case ui.TouchEnded, ui.TouchCanceled:
|
||
// strokes.End(t.ID)
|
||
// }
|
||
// }
|
||
//
|
||
// The fingers still do what they do without it, which apps that do not ask
|
||
// see alone: a tap clicks, one finger scrolls, two pinch. The window
|
||
// follows its fingers once a view asks: those down before, and lifting
|
||
// later, are not told of. Windows, Linux and browsers report touches;
|
||
// macOS has no touchscreens, and a trackpad's fingers, which are not points
|
||
// on the screen, report none. Elements asking for them get a frame
|
||
// whenever a finger lands, moves or lifts.
|
||
func (_handle Element) Touches() []Touch {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return nil
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return _node.Touches()
|
||
}
|
||
|
||
// TrackLines keeps in l where the text area lays out its lines.
|
||
func (_handle Element) TrackLines(l *TextLines) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.TrackLines(l))
|
||
}
|
||
|
||
// TrackScroll keeps the scrolling of a scroll container (Scroll,
|
||
// ScrollHorizontal, ScrollBoth, List) in *s: the container shows its
|
||
// content from s.X and s.Y, and writes there as the user scrolls it. The
|
||
// app reads where it is, scrolls it by setting them, and keeps a place
|
||
// with a ScrollState of its own for each page the container shows.
|
||
//
|
||
// // A log that follows its end, unless the user scrolled up from it.
|
||
// if app.log.Y >= app.log.MaxY {
|
||
// app.log.Y = math.MaxFloat32
|
||
// }
|
||
// ui.Scroll(c).TrackScroll(&app.log).Children(app.lines)
|
||
//
|
||
// A List keeps its place by its rows instead, and scrolls to a row with
|
||
// its ListState.
|
||
func (_handle Element) TrackScroll(s *ScrollState) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.TrackScroll(s))
|
||
}
|
||
|
||
// Transform sets the element's visual transform, in place of the one it
|
||
// had, TranslatePercent's included. Its origin is the center of its
|
||
// border box unless TransformOrigin changes it.
|
||
func (_handle Element) Transform(t Transform) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Transform(t))
|
||
}
|
||
|
||
// TransformOrigin sets the origin as fractions of the border box:
|
||
// (0,0) is the top-left and (0.5,0.5) the center. Values outside the box
|
||
// are allowed. Translation does not depend on the origin.
|
||
func (_handle Element) TransformOrigin(x float32, y float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.TransformOrigin(x, y))
|
||
}
|
||
|
||
// Transition animates the element as t asks. The element needs the same
|
||
// ID from frame to frame: a Key, or the same place among its siblings.
|
||
// Elements that the change moves as well need a Transition of their own to
|
||
// move smoothly, the same one to move in step with it, as the rows of a
|
||
// list:
|
||
//
|
||
// for _, it := range app.items {
|
||
// ui.Row(c).Key(it.ID).Transition(rowTransition).Children(func() {
|
||
// ui.Text(c, it.Title)
|
||
// })
|
||
// }
|
||
//
|
||
// Changes made by resizing the window do not animate. While the desktop
|
||
// asks for less motion (Preferences.ReduceMotion), nothing moves: colors
|
||
// still change smoothly, and an Enter or Exit that fades or blurs without
|
||
// collapsing fades and blurs in place.
|
||
func (_handle Element) Transition(t ElementTransition) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Transition(t))
|
||
}
|
||
|
||
// Transitioning reports whether the element's Transition was moving it,
|
||
// or changing its colors, or its pose (AnimatePose) or Draggable was
|
||
// moving it, in the frame before: false once it is where it goes.
|
||
func (_handle Element) Transitioning() bool {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return false
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return _node.Transitioning()
|
||
}
|
||
|
||
// Translate moves the element after its existing transform.
|
||
func (_handle Element) Translate(x float32, y float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Translate(x, y))
|
||
}
|
||
|
||
// TranslatePercent moves the element by x and y percent of its own width
|
||
// and height, as CSS's translate(-50%, -50%) does: of its border box as
|
||
// the frame lays it out, so that it is in place from its first frame and
|
||
// follows its size as it changes. It acts after the element's other
|
||
// transforms, wherever it is called among them, and before its pose
|
||
// (AnimatePose), and adds to a TranslatePercent before it. A callout
|
||
// centered above a point:
|
||
//
|
||
// ui.Box(c).Absolute().Left(p.X).Top(p.Y).TranslatePercent(-50, -100)
|
||
func (_handle Element) TranslatePercent(x float32, y float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.TranslatePercent(x, y))
|
||
}
|
||
|
||
// TranslateZ moves the element z DIPs toward the viewer after its
|
||
// existing transform, as TranslationZ: follow it with Perspective to see
|
||
// it nearer or farther. A card lifting toward the viewer as it turns over:
|
||
//
|
||
// card.RotateY(turn).TranslateZ(lift).Perspective(800)
|
||
func (_handle Element) TranslateZ(z float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.TranslateZ(z))
|
||
}
|
||
|
||
// TruncateMiddle puts the ellipsis of text that SingleLine or MaxLines
|
||
// cuts in the middle of its last line rather than at its end, so that it
|
||
// keeps both its start and its end, about as wide each, in the room
|
||
// layout gives it: a list of files shows "src/components/…/picker.go",
|
||
// whose folder and file's name both show. TruncateStart, with it, cuts
|
||
// the start instead.
|
||
func (_handle Element) TruncateMiddle() Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.TruncateMiddle())
|
||
}
|
||
|
||
// TruncateStart puts the ellipsis of text that SingleLine or MaxLines
|
||
// cuts at the start of its last line rather than at its end, so that it
|
||
// keeps as much of its end as fits the room layout gives it: a list of
|
||
// files shows "…/theme/picker.go", whose file's name and nearest folders
|
||
// show where its start does not matter. With TruncateMiddle too, the
|
||
// start is cut.
|
||
func (_handle Element) TruncateStart() Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.TruncateStart())
|
||
}
|
||
|
||
// Underline underlines text.
|
||
func (_handle Element) Underline() Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Underline())
|
||
}
|
||
|
||
// UnderlineOffset puts underlines v DIPs below the baseline, measured to
|
||
// their top, or above it when negative, as CSS's text-underline-offset:
|
||
// a link's underline a few pixels lower than the font puts it, clear of
|
||
// the descenders. Underlines skipping the ink of descenders skip it where
|
||
// they then are. The font places them otherwise.
|
||
func (_handle Element) UnderlineOffset(v float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.UnderlineOffset(v))
|
||
}
|
||
|
||
// Unselectable excludes a paragraph or container subtree from a surrounding
|
||
// Selectable container. A Selectable container nested inside it can provide
|
||
// a selection of its own. For inline elements, set it on their paragraph.
|
||
func (_handle Element) Unselectable() Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Unselectable())
|
||
}
|
||
|
||
// Value sets what assistive technology reads as the element's value, as
|
||
// the choice a button opening a popup shows, or the text of a range's
|
||
// value beside its number (aria-valuetext), as "3 of 10 steps".
|
||
func (_handle Element) Value(s string) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Value(s))
|
||
}
|
||
|
||
// Velocity returns how fast, in its units per second, the value animated
|
||
// under key goes in this frame: zero for one at rest or unknown.
|
||
func (_handle Element) Velocity(key any) float32 {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return 0
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return _node.Velocity(key)
|
||
}
|
||
|
||
// Vertical makes a SliderBase go up, from lo at the bottom of its content
|
||
// box to hi at the top, and tells assistive technology so. Pad it by half
|
||
// the thumb's height, rather than its width. Slider, drawn across, stays
|
||
// so.
|
||
func (_handle Element) Vertical() Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Vertical())
|
||
}
|
||
|
||
// WavyUnderline underlines text with a wave, as spell checkers mark words.
|
||
func (_handle Element) WavyUnderline() Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.WavyUnderline())
|
||
}
|
||
|
||
// Width sets the width in DIPs.
|
||
func (_handle Element) Width(v float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Width(v))
|
||
}
|
||
|
||
// WidthPercent sets the width as a percentage of the parent's.
|
||
func (_handle Element) WidthPercent(p float32) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.WidthPercent(p))
|
||
}
|
||
|
||
// WindowDoubleClicked reports a double click on a DragWindow handle,
|
||
// which then no longer maximizes the window: the view does what a double
|
||
// click there means to it, as a sidebar starting something new. The
|
||
// handle still moves the window, which DoubleClicked would stop.
|
||
func (_handle Element) WindowDoubleClicked() bool {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return false
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
_ctx.rt.applyInputs()
|
||
return _node.WindowDoubleClicked()
|
||
}
|
||
|
||
// WindowToLocal maps a window point into the previous frame's border box.
|
||
// ok is false for singular transforms, which take no pointer input.
|
||
func (_handle Element) WindowToLocal(x float32, y float32) (float32, float32, bool) {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return 0, 0, false
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return _node.WindowToLocal(x, y)
|
||
}
|
||
|
||
// Wrap starts a new line of children when they do not fit.
|
||
func (_handle Element) Wrap() Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.Wrap())
|
||
}
|
||
|
||
// WrapReverse wraps the children onto lines that stack the other way: up
|
||
// in a Row, to the left in a Column.
|
||
func (_handle Element) WrapReverse() Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.WrapReverse())
|
||
}
|
||
|
||
// ZIndex orders the element's painting among its siblings, as CSS's
|
||
// z-index does: those with a higher value paint later, above those with a
|
||
// lower one, whatever their order in the tree, and take the pointer first
|
||
// where they overlap. Siblings with the same value paint as they would
|
||
// without one: those in the flow in the order they were built, then the
|
||
// absolute and sticky ones in theirs. The default is 0; a negative value
|
||
// paints the element under its siblings, still above its parent's
|
||
// background. The copy of an element leaving with its Exit
|
||
// (ElementTransition) keeps the z-index the element had, under its
|
||
// siblings of the same one: a dialog fading out stays above the page.
|
||
//
|
||
// It moves the element with all that is inside it, as one, among its
|
||
// siblings alone: it does not reach past its parent, which still clips it
|
||
// where it clips, nor mix the elements inside it with those of other
|
||
// parents, as if each element with a value other than 0 made a stacking
|
||
// context, as in CSS. Nothing else changes: the layout, the order Tab
|
||
// moves the focus in and what assistive technology reads follow the tree.
|
||
//
|
||
// A stack of overlapping avatars, the first on top:
|
||
//
|
||
// ui.Row(c).Children(func() {
|
||
// for i, u := range users {
|
||
// a := ui.Avatar(c, u.Name, u.Photo).ZIndex(len(users) - i)
|
||
// if i > 0 {
|
||
// a.Margin(0, 0, 0, -8)
|
||
// }
|
||
// }
|
||
// })
|
||
//
|
||
// A cell of a grid growing as the pointer is over it, above the cells
|
||
// after it:
|
||
//
|
||
// cell := ui.Box(c).Size(80, 80)
|
||
// if cell.Hovered() {
|
||
// cell.Scale(1.2, 1.2).ZIndex(1)
|
||
// }
|
||
//
|
||
// The window's content stays under its overlays (Overlay) whatever its
|
||
// z-index, and overlays keep the order they open in; an element inside a
|
||
// text (inline) paints with its text.
|
||
func (_handle Element) ZIndex(z int) Element {
|
||
_node := _handle.node()
|
||
if _node == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _node.c
|
||
_ = _ctx
|
||
return wrapElement(_node.ZIndex(z))
|
||
}
|
||
|
||
// Segment creates segment i: a radio button choosing i. Style it from
|
||
// whether i is the one chosen, and give it children.
|
||
func (_handle SegmentedParts) Segment(i int) Element {
|
||
_parts := _handle.resolve()
|
||
if _parts == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _parts.c
|
||
_ = _ctx
|
||
_ctx.rt.beginBuild()
|
||
_e := _parts.Segment(i)
|
||
_ctx.rt.endBuild()
|
||
return wrapElement(_e)
|
||
}
|
||
|
||
// Highlight moves the highlight to the option of value while the popup
|
||
// shows, unless it is disabled, as a select of your own may do as the
|
||
// user types the option's first letters; Enter then chooses it. Called
|
||
// before Popup as the popup opens, it highlights the option once Popup
|
||
// builds it.
|
||
func (_handle SelectParts[T]) Highlight(value T) {
|
||
_parts := _handle.resolve()
|
||
if _parts == nil {
|
||
return
|
||
}
|
||
_ctx := _parts.c
|
||
_ = _ctx
|
||
_parts.Highlight(value)
|
||
}
|
||
|
||
// Item creates an option choosing value: a row that is Highlighted when
|
||
// the pointer or the arrows are on it, and chooses value and closes the
|
||
// popup when clicked. Disabled leaves it out of the keys' way and of the
|
||
// pointer's. The option the highlight moves to scrolls into view, once,
|
||
// so that the wheel scrolls on past it. Assistive technology reads it as
|
||
// an option of a list box (RoleOption), selected while it is
|
||
// highlighted, as a native select's; focusing it highlights it, and
|
||
// pressing it chooses it.
|
||
func (_handle SelectParts[T]) Item(value T) 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 SelectParts[T]) Open() bool {
|
||
_parts := _handle.resolve()
|
||
if _parts == nil {
|
||
return false
|
||
}
|
||
_ctx := _parts.c
|
||
_ = _ctx
|
||
return _parts.Open()
|
||
}
|
||
|
||
// Popup shows the popup below the trigger, at least as wide, while it is
|
||
// open: fn styles the panel and builds the options in it with Item.
|
||
// Clicking outside it or pressing Escape closes it. It returns the panel,
|
||
// or nil when the popup is closed.
|
||
func (_handle SelectParts[T]) 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, as typing on the closed trigger may
|
||
// open it, or Tab moving on close it. It opens with the highlight on the
|
||
// choice, which Highlight then moves.
|
||
func (_handle SelectParts[T]) SetOpen(o bool) {
|
||
_parts := _handle.resolve()
|
||
if _parts == nil {
|
||
return
|
||
}
|
||
_ctx := _parts.c
|
||
_ = _ctx
|
||
_parts.SetOpen(o)
|
||
}
|
||
|
||
// Tab creates tab i of the list: a row that takes the focus and chooses
|
||
// i when clicked. Style it from whether i is the one chosen. Disabled
|
||
// leaves it out of the keys' way and of the pointer's, and assistive
|
||
// technology sees it disabled.
|
||
func (_handle TabsParts) Tab(i int) Element {
|
||
_parts := _handle.resolve()
|
||
if _parts == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _parts.c
|
||
_ = _ctx
|
||
_ctx.rt.beginBuild()
|
||
_e := _parts.Tab(i)
|
||
_ctx.rt.endBuild()
|
||
return wrapElement(_e)
|
||
}
|
||
|
||
// ActionButton creates a button without a look, as ButtonBase does, that
|
||
// runs the toast's OnAction and closes it. Give it children, as the
|
||
// toast's Action.
|
||
func (_handle ToastParts) ActionButton() Element {
|
||
_parts := _handle.resolve()
|
||
if _parts == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _parts.c
|
||
_ = _ctx
|
||
_ctx.rt.beginBuild()
|
||
_e := _parts.ActionButton()
|
||
_ctx.rt.endBuild()
|
||
return wrapElement(_e)
|
||
}
|
||
|
||
// CloseButton creates a button without a look, as ButtonBase does, that
|
||
// closes the toast. Give it children, and a Label when they are not text.
|
||
func (_handle ToastParts) CloseButton() Element {
|
||
_parts := _handle.resolve()
|
||
if _parts == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _parts.c
|
||
_ = _ctx
|
||
_ctx.rt.beginBuild()
|
||
_e := _parts.CloseButton()
|
||
_ctx.rt.endBuild()
|
||
return wrapElement(_e)
|
||
}
|
||
|
||
// Left returns how long the toast shows still, to count down, or 0 for one
|
||
// that shows until it is closed. It does not move while the time of the
|
||
// toasts stops; ask for frames with Context.AnimationFrame to draw it
|
||
// moving.
|
||
func (_handle ToastParts) Left() time.Duration {
|
||
_parts := _handle.resolve()
|
||
if _parts == nil {
|
||
return 0
|
||
}
|
||
_ctx := _parts.c
|
||
_ = _ctx
|
||
return _parts.Left()
|
||
}
|
||
|
||
// Depth returns how deep the item is: 0 at the top, 1 inside an item at
|
||
// the top, and so on, to indent its row by.
|
||
func (_handle TreeItemParts) Depth() int {
|
||
_parts := _handle.resolve()
|
||
if _parts == nil {
|
||
return 0
|
||
}
|
||
_ctx := _parts.c
|
||
_ = _ctx
|
||
return _parts.Depth()
|
||
}
|
||
|
||
// Group builds the items inside the item, which fn makes with the tree's
|
||
// Item, while it is open, in a column below the item's row. It returns the
|
||
// column, to style, as with a line along it, and nil while the item is
|
||
// closed or a leaf.
|
||
func (_handle TreeItemParts) Group(fn func()) Element {
|
||
_parts := _handle.resolve()
|
||
if _parts == nil {
|
||
return Element{}
|
||
}
|
||
_ctx := _parts.c
|
||
_ = _ctx
|
||
_ctx.rt.beginBuild()
|
||
_e := _parts.Group(fn)
|
||
_ctx.rt.endBuild()
|
||
return wrapElement(_e)
|
||
}
|
||
|
||
// Item creates an item of the tree, at the top or, inside Group, in the
|
||
// item that Group is of. With a nil open it is a leaf; otherwise the items
|
||
// Group builds inside it show while *open is true, which Right and Left
|
||
// set, as does assistive technology. A key given with Context.Key just
|
||
// before keeps its focus on it, and on the items inside it, as items
|
||
// above open and close.
|
||
func (_handle TreeParts) Item(open *bool) TreeItemParts {
|
||
_parts := _handle.resolve()
|
||
if _parts == nil {
|
||
return TreeItemParts{}
|
||
}
|
||
_ctx := _parts.c
|
||
_ = _ctx
|
||
_ctx.rt.beginBuild()
|
||
_p := _parts.Item(open)
|
||
_ctx.rt.endBuild()
|
||
return wrapTreeItemParts(_p)
|
||
}
|
||
|
||
// AccordionParts contains checked handles for the parts of a custom widget.
|
||
type AccordionParts struct {
|
||
Root Element
|
||
part uint32
|
||
}
|
||
|
||
func wrapAccordionParts(p accordionParts) AccordionParts {
|
||
c := p.c
|
||
if c == nil {
|
||
return AccordionParts{}
|
||
}
|
||
_slot := c.rt.keepPart(&p)
|
||
return AccordionParts{part: _slot, Root: wrapElement(p.Root)}
|
||
}
|
||
func (p AccordionParts) resolve() *accordionParts {
|
||
n := p.Root.node()
|
||
if n == nil {
|
||
return nil
|
||
}
|
||
if int(p.part) >= len(n.c.rt.parts) {
|
||
return nil
|
||
}
|
||
return n.c.rt.parts[p.part].(*accordionParts)
|
||
}
|
||
|
||
// CollapsibleParts contains checked handles for the parts of a custom widget.
|
||
type CollapsibleParts struct {
|
||
Trigger Element
|
||
part uint32
|
||
}
|
||
|
||
func wrapCollapsibleParts(p collapsibleParts) CollapsibleParts {
|
||
c := p.c
|
||
if c == nil {
|
||
return CollapsibleParts{}
|
||
}
|
||
_slot := c.rt.keepPart(&p)
|
||
return CollapsibleParts{part: _slot, Trigger: wrapElement(p.Trigger)}
|
||
}
|
||
func (p CollapsibleParts) resolve() *collapsibleParts {
|
||
n := p.Trigger.node()
|
||
if n == nil {
|
||
return nil
|
||
}
|
||
if int(p.part) >= len(n.c.rt.parts) {
|
||
return nil
|
||
}
|
||
return n.c.rt.parts[p.part].(*collapsibleParts)
|
||
}
|
||
|
||
// ComboboxParts contains checked handles for the parts of a custom widget.
|
||
type ComboboxParts struct {
|
||
Input Element
|
||
part uint32
|
||
}
|
||
|
||
func wrapComboboxParts(p *comboboxParts) ComboboxParts {
|
||
if p == nil {
|
||
return ComboboxParts{}
|
||
}
|
||
c := p.c
|
||
if c == nil {
|
||
return ComboboxParts{}
|
||
}
|
||
_slot := c.rt.keepPart(p)
|
||
return ComboboxParts{part: _slot, Input: wrapElement(p.Input)}
|
||
}
|
||
func (p ComboboxParts) resolve() *comboboxParts {
|
||
n := p.Input.node()
|
||
if n == nil {
|
||
return nil
|
||
}
|
||
if int(p.part) >= len(n.c.rt.parts) {
|
||
return nil
|
||
}
|
||
return n.c.rt.parts[p.part].(*comboboxParts)
|
||
}
|
||
|
||
// MenuParts contains checked handles for the parts of a custom widget.
|
||
type MenuParts struct {
|
||
Trigger Element
|
||
part uint32
|
||
}
|
||
|
||
func wrapMenuParts(p *menuParts) MenuParts {
|
||
if p == nil {
|
||
return MenuParts{}
|
||
}
|
||
c := p.c
|
||
if c == nil {
|
||
return MenuParts{}
|
||
}
|
||
_slot := c.rt.keepPart(p)
|
||
return MenuParts{part: _slot, Trigger: wrapElement(p.Trigger)}
|
||
}
|
||
func (p MenuParts) resolve() *menuParts {
|
||
n := p.Trigger.node()
|
||
if n == nil {
|
||
return nil
|
||
}
|
||
if int(p.part) >= len(n.c.rt.parts) {
|
||
return nil
|
||
}
|
||
return n.c.rt.parts[p.part].(*menuParts)
|
||
}
|
||
|
||
// SegmentedParts contains checked handles for the parts of a custom widget.
|
||
type SegmentedParts struct {
|
||
Track Element
|
||
part uint32
|
||
}
|
||
|
||
func wrapSegmentedParts(p segmentedParts) SegmentedParts {
|
||
c := p.c
|
||
if c == nil {
|
||
return SegmentedParts{}
|
||
}
|
||
_slot := c.rt.keepPart(&p)
|
||
return SegmentedParts{part: _slot, Track: wrapElement(p.Track)}
|
||
}
|
||
func (p SegmentedParts) resolve() *segmentedParts {
|
||
n := p.Track.node()
|
||
if n == nil {
|
||
return nil
|
||
}
|
||
if int(p.part) >= len(n.c.rt.parts) {
|
||
return nil
|
||
}
|
||
return n.c.rt.parts[p.part].(*segmentedParts)
|
||
}
|
||
|
||
// SelectParts contains checked handles for the parts of a custom widget.
|
||
type SelectParts[T comparable] struct {
|
||
Trigger Element
|
||
part uint32
|
||
}
|
||
|
||
func wrapSelectParts[T comparable](p *selectParts[T]) SelectParts[T] {
|
||
if p == nil {
|
||
return SelectParts[T]{}
|
||
}
|
||
c := p.c
|
||
if c == nil {
|
||
return SelectParts[T]{}
|
||
}
|
||
_slot := c.rt.keepPart(p)
|
||
return SelectParts[T]{part: _slot, Trigger: wrapElement(p.Trigger)}
|
||
}
|
||
func (p SelectParts[T]) resolve() *selectParts[T] {
|
||
n := p.Trigger.node()
|
||
if n == nil {
|
||
return nil
|
||
}
|
||
if int(p.part) >= len(n.c.rt.parts) {
|
||
return nil
|
||
}
|
||
return n.c.rt.parts[p.part].(*selectParts[T])
|
||
}
|
||
|
||
// SplitButtonParts contains checked handles for the parts of a custom widget.
|
||
type SplitButtonParts struct {
|
||
Group Element
|
||
Button Element
|
||
Arrow Element
|
||
part uint32
|
||
}
|
||
|
||
func wrapSplitButtonParts(p splitButtonParts) SplitButtonParts {
|
||
c := p.c
|
||
if c == nil {
|
||
return SplitButtonParts{}
|
||
}
|
||
_slot := c.rt.keepPart(&p)
|
||
return SplitButtonParts{part: _slot, Group: wrapElement(p.Group), Button: wrapElement(p.Button), Arrow: wrapElement(p.Arrow)}
|
||
}
|
||
func (p SplitButtonParts) resolve() *splitButtonParts {
|
||
n := p.Group.node()
|
||
if n == nil {
|
||
return nil
|
||
}
|
||
if int(p.part) >= len(n.c.rt.parts) {
|
||
return nil
|
||
}
|
||
return n.c.rt.parts[p.part].(*splitButtonParts)
|
||
}
|
||
|
||
// TabsParts contains checked handles for the parts of a custom widget.
|
||
type TabsParts struct {
|
||
List Element
|
||
part uint32
|
||
}
|
||
|
||
func wrapTabsParts(p tabsParts) TabsParts {
|
||
c := p.c
|
||
if c == nil {
|
||
return TabsParts{}
|
||
}
|
||
_slot := c.rt.keepPart(&p)
|
||
return TabsParts{part: _slot, List: wrapElement(p.List)}
|
||
}
|
||
func (p TabsParts) resolve() *tabsParts {
|
||
n := p.List.node()
|
||
if n == nil {
|
||
return nil
|
||
}
|
||
if int(p.part) >= len(n.c.rt.parts) {
|
||
return nil
|
||
}
|
||
return n.c.rt.parts[p.part].(*tabsParts)
|
||
}
|
||
|
||
// ToastParts contains checked handles for the parts of a custom widget.
|
||
type ToastParts struct {
|
||
Root Element
|
||
part uint32
|
||
}
|
||
|
||
func wrapToastParts(p toastParts) ToastParts {
|
||
c := p.c
|
||
if c == nil {
|
||
return ToastParts{}
|
||
}
|
||
_slot := c.rt.keepPart(&p)
|
||
return ToastParts{part: _slot, Root: wrapElement(p.Root)}
|
||
}
|
||
func (p ToastParts) resolve() *toastParts {
|
||
n := p.Root.node()
|
||
if n == nil {
|
||
return nil
|
||
}
|
||
if int(p.part) >= len(n.c.rt.parts) {
|
||
return nil
|
||
}
|
||
return n.c.rt.parts[p.part].(*toastParts)
|
||
}
|
||
|
||
// TreeItemParts contains checked handles for the parts of a custom widget.
|
||
type TreeItemParts struct {
|
||
Row Element
|
||
part uint32
|
||
}
|
||
|
||
func wrapTreeItemParts(p treeItemParts) TreeItemParts {
|
||
c := p.c
|
||
if c == nil {
|
||
return TreeItemParts{}
|
||
}
|
||
_slot := c.rt.keepPart(&p)
|
||
return TreeItemParts{part: _slot, Row: wrapElement(p.Row)}
|
||
}
|
||
func (p TreeItemParts) resolve() *treeItemParts {
|
||
n := p.Row.node()
|
||
if n == nil {
|
||
return nil
|
||
}
|
||
if int(p.part) >= len(n.c.rt.parts) {
|
||
return nil
|
||
}
|
||
return n.c.rt.parts[p.part].(*treeItemParts)
|
||
}
|
||
|
||
// TreeParts contains checked handles for the parts of a custom widget.
|
||
type TreeParts struct {
|
||
Root Element
|
||
part uint32
|
||
}
|
||
|
||
func wrapTreeParts(p treeParts) TreeParts {
|
||
c := p.c
|
||
if c == nil {
|
||
return TreeParts{}
|
||
}
|
||
_slot := c.rt.keepPart(&p)
|
||
return TreeParts{part: _slot, Root: wrapElement(p.Root)}
|
||
}
|
||
func (p TreeParts) resolve() *treeParts {
|
||
n := p.Root.node()
|
||
if n == nil {
|
||
return nil
|
||
}
|
||
if int(p.part) >= len(n.c.rt.parts) {
|
||
return nil
|
||
}
|
||
return n.c.rt.parts[p.part].(*treeParts)
|
||
}
|