Custom widgets
Retained components, low-level drawing, and the API for building text widgets of your own.
Most screens are functions that return ui.View. For a retained component, implement ui.View:
func (p *Page) Layout(c *ui.Ctx) *layout.Element {
return ui.Column(/* … */).Grow(1).Layout(c)
}Chapar-style pages return ui.View from a helper also named Layout and are composed by the shell — that helper is not the ui.View interface (which must return *layout.Element).
Low-level drawing: layout.New(layout.Box().…, children…), attach Paint / OnMouse, wrap with ui.Raw. Hit-test with e.Frame.Contains(m.X, m.Y).
Building text widgets#
Text widgets outside package ui can behave like TextInput:
texteditholds the editing rules:WordLeft/WordRight, character classes,DoubleClickIntervalandMultiClickSlop, and the undo grouping (Merge,UndoMergeGap,StartsWord).syntaxholds token classes, theHighlighterinterface and the registry behindsyntax.ForPathandsyntax.ByName. Themes map the classes to colors (theme.Syntax), and Markdown code blocks use the registry. An engine registers its highlighters withsyntax.RegisterDefaults; an app overrides an extension withsyntax.Register.- Frame resources for painting outside the layout tree:
ui.FrameText(),ui.FrameIcons(),ui.FrameClipboard(), and the drawing helpersui.DrawElevationShadow,ui.PaintFocusRingInsetandui.ClampToViewport. - The standard edit menu:
ui.EditMenuItems(t, ui.EditMenuFlags{Editable: true, Copyable: true})for anyui.TextEditing, shown with aui.EditMenu. - Hosted text inputs: a
TextInputcan live inside another widget's painting, as the code editor's find bar does. The host callsEmbed,PaintIn,HandleMouseInandLayoutHosted. - Scrollbars for your own scroll areas:
ui.NewScrollbar, withHost,Gutter,Strip,HitandTick.
The code editor is built entirely on this API.
Edit this page on GitHub