ui

package
v0.0.20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeyEsc                = platforms.KeyEsc
	KeyF1                 = platforms.KeyF1
	KeyF2                 = platforms.KeyF2
	KeyF3                 = platforms.KeyF3
	KeyF4                 = platforms.KeyF4
	KeyF5                 = platforms.KeyF5
	KeyF6                 = platforms.KeyF6
	KeyF7                 = platforms.KeyF7
	KeyF8                 = platforms.KeyF8
	KeyF9                 = platforms.KeyF9
	KeyF10                = platforms.KeyF10
	KeyF11                = platforms.KeyF11
	KeyF12                = platforms.KeyF12
	KeyF13                = platforms.KeyF13
	KeyF14                = platforms.KeyF14
	KeyF15                = platforms.KeyF15
	KeyF16                = platforms.KeyF16
	KeyF17                = platforms.KeyF17
	KeyF18                = platforms.KeyF18
	KeyF19                = platforms.KeyF19
	KeyF20                = platforms.KeyF20
	KeyF21                = platforms.KeyF21
	KeyF22                = platforms.KeyF22
	KeyF23                = platforms.KeyF23
	KeyF24                = platforms.KeyF24
	KeyGrave              = platforms.KeyGrave
	Key1                  = platforms.Key1
	Key2                  = platforms.Key2
	Key3                  = platforms.Key3
	Key4                  = platforms.Key4
	Key5                  = platforms.Key5
	Key6                  = platforms.Key6
	Key7                  = platforms.Key7
	Key8                  = platforms.Key8
	Key9                  = platforms.Key9
	Key0                  = platforms.Key0
	KeyMinus              = platforms.KeyMinus
	KeyEqual              = platforms.KeyEqual
	KeyBackspace          = platforms.KeyBackspace
	KeyTab                = platforms.KeyTab
	KeyQ                  = platforms.KeyQ
	KeyW                  = platforms.KeyW
	KeyE                  = platforms.KeyE
	KeyR                  = platforms.KeyR
	KeyT                  = platforms.KeyT
	KeyY                  = platforms.KeyY
	KeyU                  = platforms.KeyU
	KeyI                  = platforms.KeyI
	KeyO                  = platforms.KeyO
	KeyP                  = platforms.KeyP
	KeyLeftBracket        = platforms.KeyLeftBracket
	KeyRightBracket       = platforms.KeyRightBracket
	KeyBackslash          = platforms.KeyBackslash
	KeyCapsLock           = platforms.KeyCapsLock
	KeyA                  = platforms.KeyA
	KeyS                  = platforms.KeyS
	KeyD                  = platforms.KeyD
	KeyF                  = platforms.KeyF
	KeyG                  = platforms.KeyG
	KeyH                  = platforms.KeyH
	KeyJ                  = platforms.KeyJ
	KeyK                  = platforms.KeyK
	KeyL                  = platforms.KeyL
	KeySemicolon          = platforms.KeySemicolon
	KeyApostrophe         = platforms.KeyApostrophe
	KeyEnter              = platforms.KeyEnter
	KeyShift              = platforms.KeyShift
	KeyZ                  = platforms.KeyZ
	KeyX                  = platforms.KeyX
	KeyC                  = platforms.KeyC
	KeyV                  = platforms.KeyV
	KeyB                  = platforms.KeyB
	KeyN                  = platforms.KeyN
	KeyM                  = platforms.KeyM
	KeyComma              = platforms.KeyComma
	KeyDot                = platforms.KeyDot
	KeySlash              = platforms.KeySlash
	KeyCtrl               = platforms.KeyCtrl
	KeyWin                = platforms.KeyWin
	KeyAlt                = platforms.KeyAlt
	KeySpace              = platforms.KeySpace
	KeyContextMenu        = platforms.KeyContextMenu
	KeyPrintScreen        = platforms.KeyPrintScreen
	KeyScrollLock         = platforms.KeyScrollLock
	KeyPauseBreak         = platforms.KeyPauseBreak
	KeyInsert             = platforms.KeyInsert
	KeyHome               = platforms.KeyHome
	KeyPageUp             = platforms.KeyPageUp
	KeyDelete             = platforms.KeyDelete
	KeyEnd                = platforms.KeyEnd
	KeyPageDown           = platforms.KeyPageDown
	KeyArrowUp            = platforms.KeyArrowUp
	KeyArrowLeft          = platforms.KeyArrowLeft
	KeyArrowDown          = platforms.KeyArrowDown
	KeyArrowRight         = platforms.KeyArrowRight
	KeyNumLock            = platforms.KeyNumLock
	KeyNumpadSlash        = platforms.KeyNumpadSlash
	KeyNumpadAsterisk     = platforms.KeyNumpadAsterisk
	KeyNumpadMinus        = platforms.KeyNumpadMinus
	KeyNumpadPlus         = platforms.KeyNumpadPlus
	KeyNumpad1            = platforms.KeyNumpad1
	KeyNumpad2            = platforms.KeyNumpad2
	KeyNumpad3            = platforms.KeyNumpad3
	KeyNumpad4            = platforms.KeyNumpad4
	KeyNumpad5            = platforms.KeyNumpad5
	KeyNumpad6            = platforms.KeyNumpad6
	KeyNumpad7            = platforms.KeyNumpad7
	KeyNumpad8            = platforms.KeyNumpad8
	KeyNumpad9            = platforms.KeyNumpad9
	KeyNumpad0            = platforms.KeyNumpad0
	KeyNumpadDot          = platforms.KeyNumpadDot
	KeyCommand            = platforms.KeyCommand
	KeyFunction           = platforms.KeyFunction
	MouseCursorNotDefined = platforms.MouseCursorNotDefined
	MouseCursorArrow      = platforms.MouseCursorArrow
	MouseCursorPointer    = platforms.MouseCursorPointer
	MouseCursorResizeHor  = platforms.MouseCursorResizeHor
	MouseCursorResizeVer  = platforms.MouseCursorResizeVer
	MouseCursorIBeam      = platforms.MouseCursorIBeam
	MouseButtonLeft       = platforms.MouseButtonLeft
	MouseButtonMiddle     = platforms.MouseButtonMiddle
	MouseButtonRight      = platforms.MouseButtonRight
)
View Source
const (
	// FontFamilySans is the font of the interface: Noto Sans
	FontFamilySans = "notosans"
	// FontFamilyMono is a monospaced font for code, logs and aligned
	// columns of numbers: JetBrains Mono (see Widget.SetFontFamily)
	FontFamilyMono = "jetbrainsmono"
)

Font families registered by default

View Source
const ContextMenuItemIconSize = 16

ContextMenuItemIconSize is the size of the item icons

View Source
const ContextMenuSeparatorHeight = 9

ContextMenuSeparatorHeight is the height of a separator line between groups of items

View Source
const (
	DefaultButtonMinWidth = 100
)
View Source
const DefaultComboBoxMinWidth = 150

DefaultComboBoxMinWidth keeps a bare ComboBox (no width ever set by the caller) from collapsing to an unusably thin trigger.

View Source
const DefaultFontSize = 14.0
View Source
const DefaultPrintDPI = 300

DefaultPrintDPI is the resolution the pages are drawn at

View Source
const FontFamilyCJK = "system-cjk"

FontFamilyCJK is the family the system CJK font is registered as, when found.

View Source
const MAX_HEIGHT = 100000
View Source
const MAX_WIDTH = 100000
View Source
const MaxInt = int(^uint(0) >> 1)
View Source
const MaxUint = ^uint(0)
View Source
const MinInt = -MaxInt - 1
View Source
const MinUint = 0
View Source
const ToastDefaultDuration = 3 * time.Second

ToastDefaultDuration is how long ShowToast keeps a toast on the screen

View Source
const (
	// ToolButtonDefaultSize is the default width and height of a ToolButton
	ToolButtonDefaultSize = 48
)
View Source
const TreeViewIconSize = 16

TreeViewIconSize is the size node icons are scaled down to.

Variables

View Source
var (
	PaperA4     = PaperSize{"A4", 210, 297}
	PaperA5     = PaperSize{"A5", 148, 210}
	PaperA3     = PaperSize{"A3", 297, 420}
	PaperLetter = PaperSize{"Letter", 215.9, 279.4}
	PaperLegal  = PaperSize{"Legal", 215.9, 355.6}
)
View Source
var DarkPalette = ThemePalette{
	Window:          ColorFromHex("#2B2B2B"),
	WindowText:      ColorFromHex("#E3E3E3"),
	Base:            ColorFromHex("#1F1F1F"),
	Text:            ColorFromHex("#E3E3E3"),
	Button:          ColorFromHex("#383838"),
	ButtonText:      ColorFromHex("#E3E3E3"),
	Border:          ColorFromHex("#505050"),
	Divider:         ColorFromHex("#3A3A3A"),
	Highlight:       ColorFromHex("#3584C8"),
	HighlightedText: ColorFromHex("#FFFFFF"),
	Selection:       ColorFromHex("#264F78"),
	DisabledText:    ColorFromHex("#7A7A7A"),
	PlaceholderText: ColorFromHex("#8A8A8A"),
	PopupBase:       ColorFromHex("#333333"),
	ToolTipBase:     ColorFromHex("#3A3A3A"),
	ToolTipText:     ColorFromHex("#E3E3E3"),
	Link:            ColorFromHex("#5AA9E6"),
	Error:           ColorFromHex("#EF5350"),
	Warning:         ColorFromHex("#FFB74D"),
	Success:         ColorFromHex("#66BB6A"),
}

DarkPalette is the dark theme: the same structure as the light one, with depth shown by the lightness of the surfaces instead of shadows. Inputs are darker than the window, buttons and popups lighter.

View Source
var DefaultColorPickerPalette = []color.RGBA{
	{0x00, 0x00, 0x00, 0xFF}, {0x42, 0x42, 0x42, 0xFF}, {0x75, 0x75, 0x75, 0xFF}, {0xBD, 0xBD, 0xBD, 0xFF}, {0xFF, 0xFF, 0xFF, 0xFF},
	{0x79, 0x55, 0x48, 0xFF}, {0xF4, 0x43, 0x36, 0xFF}, {0xE9, 0x1E, 0x63, 0xFF}, {0x9C, 0x27, 0xB0, 0xFF}, {0x67, 0x3A, 0xB7, 0xFF},
	{0x3F, 0x51, 0xB5, 0xFF}, {0x21, 0x96, 0xF3, 0xFF}, {0x03, 0xA9, 0xF4, 0xFF}, {0x00, 0xBC, 0xD4, 0xFF}, {0x00, 0x96, 0x88, 0xFF},
	{0x4C, 0xAF, 0x50, 0xFF}, {0x8B, 0xC3, 0x4A, 0xFF}, {0xCD, 0xDC, 0x39, 0xFF}, {0xFF, 0xEB, 0x3B, 0xFF}, {0xFF, 0x98, 0x00, 0xFF},
}

DefaultColorPickerPalette is the palette a new ColorPicker offers.

View Source
var DefaultUiLineHeight = 30

DefaultUiLineHeight is the height of a single-line control at the theme font size (see ThemeControlHeight); ApplyBaseFontSize updates it.

View Source
var ErrNoFileDialog = platforms.ErrNoFileDialog

ErrNoFileDialog is returned when the system has no file dialog to show, e.g. Linux without zenity or kdialog

View Source
var ErrNoPrinting = platforms.ErrNoPrinting

ErrNoPrinting: no printer can be used (no CUPS on Linux or macOS)

View Source
var ErrNotificationsNotSupported = platforms.ErrNotificationsNotSupported

ErrNotificationsNotSupported is returned by ShowNotification where system notifications aren't available (macOS)

View Source
var ErrPrintCanceled = platforms.ErrPrintCanceled

ErrPrintCanceled is given to Form.Print's callback when the user cancels

View Source
var ErrSystemFontNotFound = platforms.ErrSystemFontNotFound

ErrSystemFontNotFound is returned when the system has no font of the name

View Source
var ErrTrayNotSupported = platforms.ErrTrayNotSupported

ErrTrayNotSupported is returned by NewTrayIcon when the system has no tray, e.g. a Linux desktop without StatusNotifierItem support

View Source
var IsDarkTheme = true
View Source
var LightPalette = ThemePalette{
	Window:          ColorFromHex("#EFEFEF"),
	WindowText:      ColorFromHex("#1F1F1F"),
	Base:            ColorFromHex("#FFFFFF"),
	Text:            ColorFromHex("#1F1F1F"),
	Button:          ColorFromHex("#FAFAFA"),
	ButtonText:      ColorFromHex("#1F1F1F"),
	Border:          ColorFromHex("#B5B5B5"),
	Divider:         ColorFromHex("#DCDCDC"),
	Highlight:       ColorFromHex("#2A7DC1"),
	HighlightedText: ColorFromHex("#FFFFFF"),
	Selection:       ColorFromHex("#BFD9EE"),
	DisabledText:    ColorFromHex("#A0A0A0"),
	PlaceholderText: ColorFromHex("#8C8C8C"),
	PopupBase:       ColorFromHex("#FFFFFF"),
	ToolTipBase:     ColorFromHex("#FFFFFF"),
	ToolTipText:     ColorFromHex("#1F1F1F"),
	Link:            ColorFromHex("#1D6FB5"),
	Error:           ColorFromHex("#C62828"),
	Warning:         ColorFromHex("#B26A00"),
	Success:         ColorFromHex("#2E7D32"),
}

LightPalette is the light theme: flat, in the spirit of Qt's Fusion style.

View Source
var NativeFontRendering = true

NativeFontRendering draws the fonts built into nui and those of RegisterFont with the system's text engine where it can take a font file: on Windows with GDI and ClearType, using the hinting of the file, as the system fonts are drawn. Text with characters the font lacks (e.g. Chinese, drawn with a fallback font) is drawn by nui's rasterizer. Set it to false before the first form is shown to draw everything with nui's rasterizer.

PaperSizes are the sizes offered in nui's print dialog

View Source
var SystemFallbackFonts = true

SystemFallbackFonts enables the system CJK font. Set it to false before any CJK text is shown to use only the fonts registered by the application.

View Source
var Theme map[string]interface{}

Functions

func AddFallbackFont

func AddFallbackFont(family string)

AddFallbackFont adds the registered family to the end of the fallback chain: the fonts tried, in order, for characters the requested font doesn't have.

func ApplyBaseFontSize

func ApplyBaseFontSize(fontSize float64)

ApplyBaseFontSize sets the size of the theme font and lays out the open forms again: the heights of controls follow the font (see ThemeControlHeight).

func ApplyDarkTheme

func ApplyDarkTheme()

func ApplyLightTheme

func ApplyLightTheme()

func ApplyPalette

func ApplyPalette(palette ThemePalette, dark bool)

ApplyPalette switches to the palette, e.g. a copy of LightPalette with another Highlight, and repaints the open forms. dark tells whether it's a dark theme, for the window title bars and for the charts.

func ClipboardGetText

func ClipboardGetText() (string, error)

func ClipboardSetText

func ClipboardSetText(text string)

func CohenSutherland

func CohenSutherland(x1, y1, x2, y2, left, top, right, bottom int) (int, int, int, int, bool)

func ColorFromHex

func ColorFromHex(hexStr string) color.RGBA

func ColorToHex

func ColorToHex(col color.Color) string

func DateOnly

func DateOnly(t time.Time) time.Time

DateOnly returns the date of t at midnight in the local time zone.

func DefaultDateLayout

func DefaultDateLayout() string

DefaultDateLayout returns the time.Format layout of a date in the language of the application, e.g. "02.01.2006" for Russian.

func DrawText

func DrawText(rgba *image.RGBA, text string, textColor color.Color, fontFamily string, fontSize float64, x int, y int, clipX int, clipY int, clipWidth int, clipHeight int)

func FirstDayOfWeek

func FirstDayOfWeek() time.Weekday

FirstDayOfWeek returns the day weeks start with in the language of the application: Sunday in the US, Japan, Korea and a few other places, Monday elsewhere.

func GetCharPositions

func GetCharPositions(fontFamily string, fontSize float64, text string) ([]int, error)

GetCharPositions returns the x of each character of text and, last, the width of the whole text. Advances and kerning are added up the same way as in MeasureText and in drawing, so the cursor stays on the characters.

func GetThemeColor

func GetThemeColor(name string, defaultColor color.RGBA) color.RGBA

func GetThemeFloat

func GetThemeFloat(name string, defaultValue float64) float64

func GetThemeInt

func GetThemeInt(name string, defaultValue int) int

func GetThemeString

func GetThemeString(name string, defaultValue string) string

func Invoke

func Invoke(f func())

Invoke runs f on the UI thread and returns at once. Safe to call from any goroutine; called on the UI thread, f runs after the current handler.

func InvokeSync

func InvokeSync(f func())

InvokeSync runs f on the UI thread and waits for it to return; on the UI thread it just calls f. Don't call it from a goroutine the UI thread is waiting for: that would deadlock.

func IsUIThread

func IsUIThread() bool

IsUIThread reports whether the caller runs on the UI thread

func Language

func Language() string

Language returns the language of the application as a tag like "ru" or "zh-TW": the one set by SetLanguage, else the system's.

func MakeLinesFromStringWithWordWrapping

func MakeLinesFromStringWithWordWrapping(text string, maxChars int) []string

func MeasureText

func MeasureText(fontFamily string, fontSize float64, text string) (int, int, error)

func MixColors

func MixColors(a, b color.RGBA, t float64) color.RGBA

MixColors returns the color t of the way from a to b: 0 is a, 1 is b.

func MouseCursorToString

func MouseCursorToString(c MouseCursor) string

func NewComboBoxPopup

func NewComboBoxPopup() *comboBoxPopup

func NewTabWidgetButton

func NewTabWidgetButton(text string) *tabWidgetButton

func OpenURL

func OpenURL(url string) error

OpenURL opens the address (a web page, a file, "mailto:...") with the system's default application.

func ParseHexColor

func ParseHexColor(s string) (color.RGBA, bool)

ParseHexColor parses "#RGB", "#RRGGBB" or "#RRGGBBAA", with or without the "#", in any case.

func PopEvent

func PopEvent()

func PrintAllWidgets

func PrintAllWidgets()

func PushEvent

func PushEvent(p any)

func RecentColors

func RecentColors() []color.RGBA

RecentColors returns the colors chosen recently in the application's color pickers, newest first.

func RegisterFont

func RegisterFont(family string, data []byte) error

RegisterFont adds a font family from a TrueType or OpenType file. The family name is case-insensitive; registering it again replaces the font.

func RegisterSystemFont

func RegisterSystemFont(family, name string) error

RegisterSystemFont makes the font family drawn with the system font of the name (e.g. "Segoe UI", "Consolas", "DejaVu Sans"), for Widget.SetFontFamily or the theme. ErrSystemFontNotFound if the system has no such font.

func RegisterUIStrings

func RegisterUIStrings(lang string, s UIStrings)

RegisterUIStrings adds or replaces the library's texts for a language.

func SetAppIcon

func SetAppIcon(img image.Image)

SetAppIcon sets the default icon for all windows of the application. Call it at startup, before showing any form - forms that are already shown keep their current icon. A nil image is ignored.

func SetLanguage

func SetLanguage(lang string)

SetLanguage switches the application to the language: the open forms update their texts (see SetTextFunc and Form.SetOnLanguageChanged) and are laid out again. Chinese, Japanese and Korean also pick their variant of the system CJK font.

func ShowMessageBox

func ShowMessageBox(parentWidget Widgeter, title string, text string)

func ShowQuestionMessageBoxOKCancel

func ShowQuestionMessageBoxOKCancel(parentWidget Widgeter, title string, text string, onOK func(), onCancel func())

func ShowQuestionMessageBoxYesNo

func ShowQuestionMessageBoxYesNo(parentWidget Widgeter, title string, text string, onYes func(), onNo func())

func ShowToast

func ShowToast(w Widgeter, text string, kind ToastKind)

ShowToast shows a toast in the form of the widget (see Form.ShowToast)

func SystemLanguage

func SystemLanguage() string

SystemLanguage returns the language of the system's user interface, "en" if unknown.

func SystemUIFontName

func SystemUIFontName() string

SystemUIFontName returns the name of the font the system uses for its interface: "Segoe UI" on Windows, the desktop's sans-serif font on Linux, the system font on macOS

func ThemeBackgroundColor

func ThemeBackgroundColor(elevation int, role string) color.RGBA

ThemeBackgroundColor returns the background of a widget with the role and the elevation (summed over its parents, see Widget.SetElevation).

Roles: "" or "surface" - the window; "base" - input fields and lists; "popup" - menus and dropdowns; "primary" and "secondary" - the accent. A positive elevation shades the surface towards the text color, a negative one sinks it towards the input field background.

func ThemeBackgroundColorDarkTheme

func ThemeBackgroundColorDarkTheme(elevation int, role string) color.RGBA

ThemeBackgroundColorDarkTheme is ThemeBackgroundColor for the dark palette.

func ThemeBackgroundColorLightTheme

func ThemeBackgroundColorLightTheme(elevation int, role string) color.RGBA

ThemeBackgroundColorLightTheme is ThemeBackgroundColor for the light palette.

func ThemeControlHeight

func ThemeControlHeight() int

ThemeControlHeight returns the height of buttons, input fields, combo boxes, check boxes and other single-line controls.

func ThemeFontFamily

func ThemeFontFamily() string

func ThemeFontSize

func ThemeFontSize() float64

func ThemeForegroundColor

func ThemeForegroundColor(role string) color.RGBA

func ThemeForegroundColorDisabled

func ThemeForegroundColorDisabled() color.RGBA

func ThemeIndicatorSize

func ThemeIndicatorSize() int

ThemeIndicatorSize returns the size of a check box or radio button indicator.

func ThemeLineHeight

func ThemeLineHeight() int

ThemeLineHeight returns the height of a line of text in the theme font.

func ThemeRowHeight

func ThemeRowHeight() int

ThemeRowHeight returns the height of table rows and of menu and dropdown items.

func UseBuiltinFont

func UseBuiltinFont()

UseBuiltinFont draws the interface with the font built into nui (Noto Sans) again, after UseSystemFont

func UseSystemFont

func UseSystemFont(name string) error

UseSystemFont draws the whole interface with the system font of the name: it becomes the theme font, and the open forms are laid out again for it. ErrSystemFontNotFound if the system has no such font.

Types

type Accordion

type Accordion struct {
	Widget
	// contains filtered or unexported fields
}

Accordion is a column of expanders (sections). By default only one section is expanded at a time: expanding one collapses the others.

acc := ui.NewAccordion()
general := acc.AddSection("General")
general.Content().AddLabel(0, 0, "Name")
acc.AddSection("Network")

func NewAccordion

func NewAccordion() *Accordion

func (*Accordion) AddSection

func (c *Accordion) AddSection(title string) *Expander

AddSection adds a collapsed section at the bottom and returns it. In an exclusive accordion the first section is expanded.

func (*Accordion) Exclusive

func (c *Accordion) Exclusive() bool

func (*Accordion) Expand

func (c *Accordion) Expand(index int)

Expand expands the section at index; in an exclusive accordion it collapses the others. A negative index collapses all the sections.

func (*Accordion) ExpandedIndex

func (c *Accordion) ExpandedIndex() int

ExpandedIndex returns the index of the first expanded section, -1 if none

func (*Accordion) Sections

func (c *Accordion) Sections() []*Expander

func (*Accordion) SetExclusive

func (c *Accordion) SetExclusive(exclusive bool)

SetExclusive sets whether only one section may be expanded at a time.

func (*Accordion) SetOnSectionChanged

func (c *Accordion) SetOnSectionChanged(f func(index int))

SetOnSectionChanged sets the function called when the user expands or collapses a section; index is the section the user clicked.

type Button

type Button struct {
	Widget
	// contains filtered or unexported fields
}

func NewButton

func NewButton(text string) *Button

func (*Button) ProcessKeyDown

func (c *Button) ProcessKeyDown(key Key, mods KeyModifiers) bool

func (*Button) ProcessPropChange

func (c *Button) ProcessPropChange(key string, value interface{})

func (*Button) Push

func (c *Button) Push()

Push simulates a click on the button, triggering the "onclick" handler programmatically (used e.g. by Form's accept/cancel buttons on Enter/Esc).

func (*Button) SetText

func (c *Button) SetText(text string)

func (*Button) SetTextFunc

func (c *Button) SetTextFunc(f func() string)

func (*Button) Text

func (c *Button) Text() string

type ButtonImage

type ButtonImage struct {
	Widget
	// contains filtered or unexported fields
}

func NewButtonImage

func NewButtonImage(img image.Image) *ButtonImage

func (*ButtonImage) Image

func (c *ButtonImage) Image() image.Image

func (*ButtonImage) ImageHAlign

func (c *ButtonImage) ImageHAlign() HAlign

ImageHAlign returns the horizontal alignment of the image within the button.

func (*ButtonImage) ImageVAlign

func (c *ButtonImage) ImageVAlign() VAlign

ImageVAlign returns the vertical alignment of the image within the button.

func (*ButtonImage) Press

func (c *ButtonImage) Press()

func (*ButtonImage) ProcessPropChange

func (c *ButtonImage) ProcessPropChange(key string, value interface{})

ProcessPropChange repaints when an alignment prop (or any other prop) changes.

func (*ButtonImage) SetImage

func (c *ButtonImage) SetImage(img image.Image)

func (*ButtonImage) SetImageHAlign

func (c *ButtonImage) SetImageHAlign(align HAlign)

SetImageHAlign sets the horizontal alignment of the image within the button.

func (*ButtonImage) SetImageVAlign

func (c *ButtonImage) SetImageVAlign(align VAlign)

SetImageVAlign sets the vertical alignment of the image within the button.

func (*ButtonImage) SetOnButtonClick

func (c *ButtonImage) SetOnButtonClick(fn func(btn *ButtonImage))

type Calendar

type Calendar struct {
	Widget
	// contains filtered or unexported fields
}

Calendar shows a month as a grid of days to choose a date. The arrows in the header (and PageUp/PageDown, the mouse wheel) change the month; the arrow keys move the selection by a day or a week, Ctrl+PageUp/PageDown by a year, Home/End to the month's first/last day. Month and day names, and the first day of the week, follow the language (UIText, FirstDayOfWeek).

cal := ui.NewCalendar()
cal.SetOnDateChanged(func(d time.Time) { status.SetText(d.Format("2006-01-02")) })

func NewCalendar

func NewCalendar() *Calendar

func (*Calendar) Date

func (c *Calendar) Date() time.Time

Date returns the selected date, at midnight local time.

func (*Calendar) ProcessKeyDown

func (c *Calendar) ProcessKeyDown(key Key, mods KeyModifiers) bool

func (*Calendar) SetDate

func (c *Calendar) SetDate(date time.Time)

SetDate selects the date (kept within SetMinDate/SetMaxDate) and shows its month, without calling SetOnDateChanged's function.

func (*Calendar) SetFirstDayOfWeek

func (c *Calendar) SetFirstDayOfWeek(day time.Weekday)

SetFirstDayOfWeek overrides the language's first day of the week.

func (*Calendar) SetMaxDate

func (c *Calendar) SetMaxDate(date time.Time)

func (*Calendar) SetMinDate

func (c *Calendar) SetMinDate(date time.Time)

SetMinDate and SetMaxDate limit the dates that can be chosen; a zero time removes the limit.

func (*Calendar) SetOnDateActivated

func (c *Calendar) SetOnDateActivated(f func(date time.Time))

SetOnDateActivated sets the function called on a double click on a day or Enter.

func (*Calendar) SetOnDateChanged

func (c *Calendar) SetOnDateChanged(f func(date time.Time))

SetOnDateChanged sets the function called when the user selects another date: by a click, the keyboard or the Today button.

func (*Calendar) ShowMonth

func (c *Calendar) ShowMonth(year int, month time.Month)

ShowMonth shows the month without changing the selection; the month may be out of 1..12 (it's normalized, as by time.Date).

func (*Calendar) ShownMonth

func (c *Calendar) ShownMonth() time.Time

ShownMonth returns the first day of the month shown.

type Canvas

type Canvas struct {
	// contains filtered or unexported fields
}

func NewCanvas

func NewCanvas(rgba *image.RGBA) *Canvas

func NewCanvasScaled

func NewCanvasScaled(rgba *image.RGBA, scale float64) *Canvas

NewCanvasScaled makes a canvas that draws on rgba with the scale: the coordinates and sizes given to it are logical, and every logical pixel takes scale pixels of rgba, so the drawing is sharp on a HiDPI screen

func (*Canvas) ClipH

func (c *Canvas) ClipH() int

func (*Canvas) ClipW

func (c *Canvas) ClipW() int

func (*Canvas) ClipX

func (c *Canvas) ClipX() int

ClipX, ClipY, ClipW and ClipH return the clip rectangle in pixels of the image

func (*Canvas) ClipY

func (c *Canvas) ClipY() int

func (*Canvas) DrawImage

func (c *Canvas) DrawImage(x int, y int, img image.Image)

func (*Canvas) DrawLine

func (c *Canvas) DrawLine(x1 int, y1 int, x2 int, y2 int, width int, color color.Color)

func (*Canvas) DrawLineF

func (c *Canvas) DrawLineF(x1, y1, x2, y2 float64, col color.Color)

DrawLineF draws an antialiased line one pixel wide between points with fractional coordinates, both ends included. Integer coordinates are the centers of the pixels, so a line between them is as sharp as DrawLine's; a line between fractional ones is spread over the neighbor pixels, e.g. for a chart that scrolls smoothly.

func (*Canvas) DrawRect

func (c *Canvas) DrawRect(x int, y int, width int, height int)

func (*Canvas) DrawRoundedRect

func (c *Canvas) DrawRoundedRect(x int, y int, width int, height int, radius int)

func (*Canvas) DrawText

func (c *Canvas) DrawText(x int, y int, width int, height int, text string)

func (*Canvas) FillFrame

func (c *Canvas) FillFrame(x, y, width, height, radius int, fill, border color.Color)

FillFrame draws a control's frame: a rounded rectangle filled with fill and outlined with a 1px border. fill must be opaque.

func (*Canvas) FillRect

func (c *Canvas) FillRect(x int, y int, width int, height int, colr color.Color)

func (*Canvas) FillRoundedRect

func (c *Canvas) FillRoundedRect(x int, y int, width int, height int, radius int)

func (*Canvas) FillRoundedRectAA

func (c *Canvas) FillRoundedRectAA(x, y, width, height, radius int, col color.RGBA)

FillRoundedRectAA fills a rounded rectangle with antialiased corners. Unlike FillRoundedRect it doesn't go through gg, which builds a clip mask of the whole canvas on every call, so it's cheap enough for every control.

func (*Canvas) FillTriangle

func (c *Canvas) FillTriangle(x1, y1, x2, y2, x3, y3 int, colr color.Color)

FillTriangle fills the triangle with corners (x1,y1), (x2,y2), (x3,y3).

func (*Canvas) Height

func (c *Canvas) Height() int

Height returns the height of the canvas in logical pixels

func (*Canvas) MakeScriptLine

func (c *Canvas) MakeScriptLine(x1, y1, x2, y2, width float64) *DrawScript

func (*Canvas) MakeScriptLineBresenham

func (c *Canvas) MakeScriptLineBresenham(x1 float64, y1 float64, x2 float64, y2 float64) *DrawScript

func (*Canvas) MakeScriptLineWu

func (c *Canvas) MakeScriptLineWu(x1, y1, x2, y2 float64) *DrawScript

func (*Canvas) MixPixel

func (c *Canvas) MixPixel(x int, y int, rgba color.Color)

MixPixel blends the color over the pixel (x, y) of the image: in pixels, with no translation, unlike the other methods

func (*Canvas) RGBA

func (c *Canvas) RGBA() *image.RGBA

func (*Canvas) Restore

func (c *Canvas) Restore()

func (*Canvas) Save

func (c *Canvas) Save()

func (*Canvas) Scale

func (c *Canvas) Scale() float64

Scale returns how many pixels of the image a logical pixel takes: 1 on an ordinary screen, e.g. 2 on a Retina one

func (*Canvas) SetColor

func (c *Canvas) SetColor(col color.Color)

func (*Canvas) SetDirectTranslateAndClip

func (c *Canvas) SetDirectTranslateAndClip(x, y, w, h int)

func (*Canvas) SetFontFamily

func (c *Canvas) SetFontFamily(fontFamily string)

func (*Canvas) SetFontSize

func (c *Canvas) SetFontSize(fontSize float64)

func (*Canvas) SetHAlign

func (c *Canvas) SetHAlign(hAlign HAlign)

func (*Canvas) SetPixel

func (c *Canvas) SetPixel(x, y int)

func (*Canvas) SetUnderline

func (c *Canvas) SetUnderline(underline bool)

func (*Canvas) SetVAlign

func (c *Canvas) SetVAlign(vAlign VAlign)

func (*Canvas) TranslateAndClip

func (c *Canvas) TranslateAndClip(x, y int, w, h int)

func (*Canvas) TranslatedX

func (c *Canvas) TranslatedX() int

TranslatedX returns the logical x of the current origin

func (*Canvas) TranslatedY

func (c *Canvas) TranslatedY() int

TranslatedY returns the logical y of the current origin

func (*Canvas) Width

func (c *Canvas) Width() int

Width returns the width of the canvas in logical pixels

type Chart

type Chart struct {
	Widget
	// contains filtered or unexported fields
}

func NewChart

func NewChart() *Chart

func (*Chart) Data

func (c *Chart) Data() []ChartPoint

func (*Chart) SetData

func (c *Chart) SetData(points []ChartPoint)

type ChartPoint

type ChartPoint struct {
	X float64
	Y float64
}

type Checkbox

type Checkbox struct {
	Widget
}

func NewCheckbox

func NewCheckbox(text string) *Checkbox

func (*Checkbox) Checked

func (c *Checkbox) Checked() bool

func (*Checkbox) Indeterminate

func (c *Checkbox) Indeterminate() bool

func (*Checkbox) SetChecked

func (c *Checkbox) SetChecked(checked bool)

func (*Checkbox) SetIndeterminate

func (c *Checkbox) SetIndeterminate(indeterminate bool)

SetIndeterminate puts the checkbox into the third state (drawn with a dash); Checked is false then. SetChecked leaves it

func (*Checkbox) SetOnStateChanged

func (c *Checkbox) SetOnStateChanged(fn func())

func (*Checkbox) SetText

func (c *Checkbox) SetText(text string)

func (*Checkbox) SetTextFunc

func (c *Checkbox) SetTextFunc(f func() string)

func (*Checkbox) SetTristate

func (c *Checkbox) SetTristate(tristate bool)

SetTristate lets a click put the checkbox into the third, indeterminate state ("leave as it is", "mixed"): unchecked -> checked -> indeterminate

func (*Checkbox) Text

func (c *Checkbox) Text() string

func (*Checkbox) Tristate

func (c *Checkbox) Tristate() bool

type ColorPicker

type ColorPicker struct {
	Widget
	// contains filtered or unexported fields
}

ColorPicker is a field showing a color; a click (or Enter, Space, Down, F4) opens a panel to choose another one: a saturation/brightness square, a hue bar, an optional opacity bar, a hex code, a palette and the colors chosen recently.

picker := ui.NewColorPicker()
picker.SetColor(ui.ColorFromHex("#1E88E5"))
picker.SetOnColorChanged(func(col color.RGBA) { preview.SetBackgroundColor(col) })

The color changes live while it's being chosen; Escape in the panel returns to the color it was opened with, a click outside keeps the new one.

Colors are color.RGBA with a straight (not premultiplied) alpha, as ColorFromHex returns them.

func NewColorPicker

func NewColorPicker() *ColorPicker

func (*ColorPicker) AlphaEnabled

func (c *ColorPicker) AlphaEnabled() bool

func (*ColorPicker) ClosePopup

func (c *ColorPicker) ClosePopup()

ClosePopup closes the panel keeping the chosen color.

func (*ColorPicker) Color

func (c *ColorPicker) Color() color.RGBA

Color returns the chosen color.

func (*ColorPicker) IsPopupOpen

func (c *ColorPicker) IsPopupOpen() bool

IsPopupOpen reports whether the panel is open.

func (*ColorPicker) OpenPopup

func (c *ColorPicker) OpenPopup()

OpenPopup opens the panel below the field (above it when it doesn't fit).

func (*ColorPicker) Palette

func (c *ColorPicker) Palette() []color.RGBA

func (*ColorPicker) ProcessKeyDown

func (c *ColorPicker) ProcessKeyDown(key Key, mods KeyModifiers) bool

func (*ColorPicker) SetAlphaEnabled

func (c *ColorPicker) SetAlphaEnabled(enabled bool)

SetAlphaEnabled lets the user choose the opacity too; the hex code then has 8 digits.

func (*ColorPicker) SetColor

func (c *ColorPicker) SetColor(col color.Color)

SetColor sets the color without calling SetOnColorChanged's function. A color.RGBA is taken as it is (straight alpha); other colors are converted. Without SetAlphaEnabled the color is made opaque.

func (*ColorPicker) SetOnColorChanged

func (c *ColorPicker) SetOnColorChanged(f func(col color.RGBA))

SetOnColorChanged sets the function called whenever the user changes the color, also while dragging in the panel.

func (*ColorPicker) SetPalette

func (c *ColorPicker) SetPalette(colors []color.RGBA)

SetPalette sets the colors offered in the panel; nil hides the palette.

type ComboBox

type ComboBox struct {
	Widget
	// contains filtered or unexported fields
}

func NewComboBox

func NewComboBox() *ComboBox

func (*ComboBox) AddItem

func (c *ComboBox) AddItem(text string, data interface{})

func (*ComboBox) ItemCount

func (c *ComboBox) ItemCount() int

func (*ComboBox) OpenPopup

func (c *ComboBox) OpenPopup()

func (*ComboBox) SelectedIndex

func (c *ComboBox) SelectedIndex() int

func (*ComboBox) SelectedItemData

func (c *ComboBox) SelectedItemData() interface{}

func (*ComboBox) SelectedItemText

func (c *ComboBox) SelectedItemText() string

func (*ComboBox) SetItemText

func (c *ComboBox) SetItemText(index int, text string)

SetItemText changes the text of the item, e.g. for another language; the item keeps its data and the selection doesn't change.

func (*ComboBox) SetOnSelectedIndexChanged

func (c *ComboBox) SetOnSelectedIndexChanged(f func())

SetOnSelectedIndexChanged sets the function called when the user picks another item.

func (*ComboBox) SetSelectedIndex

func (c *ComboBox) SetSelectedIndex(index int)

SetSelectedIndex selects the item without calling the SetOnSelectedIndexChanged function.

type ComboBoxItem

type ComboBoxItem struct {
	// contains filtered or unexported fields
}

type ContainerGridColumnInfo

type ContainerGridColumnInfo struct {
	// contains filtered or unexported fields
}

type ContainerGridRowInfo

type ContainerGridRowInfo struct {
	// contains filtered or unexported fields
}

type ContextMenu

type ContextMenu struct {
	Widget

	CloseEvent func()
	// contains filtered or unexported fields
}

func NewContextMenu

func NewContextMenu(parent Widgeter) *ContextMenu

func (*ContextMenu) AddItem

func (c *ContextMenu) AddItem(text string, onClick func()) *ContextMenuItem

func (*ContextMenu) AddItemWithSubmenu

func (c *ContextMenu) AddItemWithSubmenu(text string, innerMenu *ContextMenu) *ContextMenuItem

func (*ContextMenu) AddSeparator

func (c *ContextMenu) AddSeparator() *ContextMenuItem

AddSeparator adds a line that separates groups of items

func (*ContextMenu) ClosePopup

func (c *ContextMenu) ClosePopup()

func (*ContextMenu) OnInit

func (c *ContextMenu) OnInit()

func (*ContextMenu) PopupFlipped

func (c *ContextMenu) PopupFlipped() (int, int)

PopupFlipped opens a menu that doesn't fit on the screen to the left of (or above) the point it was opened at, a submenu to the left of its parent menu, and a drop-down menu above its title.

func (*ContextMenu) RemoveAllItems

func (c *ContextMenu) RemoveAllItems()

func (*ContextMenu) SetOnShow

func (c *ContextMenu) SetOnShow(f func())

SetOnShow sets the function called every time before the menu is shown, e.g. to hide the items that don't apply to what is selected now (ContextMenuItem.SetVisible).

func (*ContextMenu) ShowMenu

func (c *ContextMenu) ShowMenu(x int, y int)

type ContextMenuItem

type ContextMenuItem struct {
	Widget

	OnClick func()
	// contains filtered or unexported fields
}

func NewContextMenuItem

func NewContextMenuItem() *ContextMenuItem

func (*ContextMenuItem) ControlType

func (c *ContextMenuItem) ControlType() string

func (*ContextMenuItem) Draw

func (c *ContextMenuItem) Draw(ctx *Canvas)

Draw: the hovered item in the accent color, like in the combo box dropdown

func (*ContextMenuItem) Image

func (c *ContextMenuItem) Image() image.Image

func (*ContextMenuItem) IsSeparator

func (c *ContextMenuItem) IsSeparator() bool

IsSeparator reports whether the item is a separator line

func (*ContextMenuItem) MouseEnter

func (c *ContextMenuItem) MouseEnter()

func (*ContextMenuItem) MouseLeave

func (c *ContextMenuItem) MouseLeave()

func (*ContextMenuItem) MouseMove

func (c *ContextMenuItem) MouseMove(x int, y int, mods KeyModifiers) bool

func (*ContextMenuItem) SetImage

func (c *ContextMenuItem) SetImage(img image.Image) *ContextMenuItem

SetImage sets the icon shown left of the text; a larger image is scaled down to ContextMenuItemIconSize. nil removes the icon. Returns the item for chaining:

menu.AddItem("Edit", onEdit).SetImage(editIcon)

func (*ContextMenuItem) SetInnerMenu

func (c *ContextMenuItem) SetInnerMenu(menu *ContextMenu)

func (*ContextMenuItem) SetShortcut

func (c *ContextMenuItem) SetShortcut(shortcut string) *ContextMenuItem

SetShortcut sets the keys that run the item without opening the menu, shown on the item's right: "Ctrl+S", "Ctrl+Shift+Z", "F5", "Mod+S" (Cmd on macOS, Ctrl elsewhere). Works for the items of the form's main menu. Panics on a wrong shortcut (see ParseShortcut); "" removes it. Returns the item for chaining:

file.AddItem("&Save", onSave).SetShortcut("Mod+S")

func (*ContextMenuItem) SetText

func (c *ContextMenuItem) SetText(text string)

SetText sets the text; "&" marks the mnemonic letter: "&Open" shows "Open" with O underlined, and O chooses the item in the open menu.

func (*ContextMenuItem) SetTextFunc

func (c *ContextMenuItem) SetTextFunc(f func() string)

func (*ContextMenuItem) Shortcut

func (c *ContextMenuItem) Shortcut() Shortcut

Shortcut returns the item's shortcut, zero if none

func (*ContextMenuItem) Text

func (c *ContextMenuItem) Text() string

Text returns the text as shown, without the mnemonic mark

type DatePicker

type DatePicker struct {
	Widget
	// contains filtered or unexported fields
}

DatePicker is a field showing a date; a click (or Enter, Space, F4) drops a Calendar down to choose another one. With the dropdown closed Up/Down change the date by a day, PageUp/PageDown by a month.

due := ui.NewDatePicker()
due.SetDate(time.Now().AddDate(0, 0, 7))
due.SetOnDateChanged(func(d time.Time) { task.Due = d })

func NewDatePicker

func NewDatePicker() *DatePicker

func (*DatePicker) ClosePopup

func (c *DatePicker) ClosePopup()

ClosePopup closes the dropdown without changing the date.

func (*DatePicker) Date

func (c *DatePicker) Date() time.Time

Date returns the chosen date, at midnight local time.

func (*DatePicker) IsPopupOpen

func (c *DatePicker) IsPopupOpen() bool

func (*DatePicker) OpenPopup

func (c *DatePicker) OpenPopup()

OpenPopup drops the calendar down, with the keyboard focus in it.

func (*DatePicker) ProcessKeyDown

func (c *DatePicker) ProcessKeyDown(key Key, mods KeyModifiers) bool

func (*DatePicker) SetDate

func (c *DatePicker) SetDate(date time.Time)

SetDate sets the date (kept within the limits) without calling SetOnDateChanged's function.

func (*DatePicker) SetFormat

func (c *DatePicker) SetFormat(layout string)

SetFormat sets the time.Format layout of the date shown; "" (the default) follows the language, see DefaultDateLayout.

func (*DatePicker) SetMaxDate

func (c *DatePicker) SetMaxDate(date time.Time)

func (*DatePicker) SetMinDate

func (c *DatePicker) SetMinDate(date time.Time)

SetMinDate and SetMaxDate limit the dates; a zero time removes the limit.

func (*DatePicker) SetOnDateChanged

func (c *DatePicker) SetOnDateChanged(f func(date time.Time))

SetOnDateChanged sets the function called when the user chooses another date.

func (*DatePicker) Text

func (c *DatePicker) Text() string

Text returns the date as shown.

type DialogContent

type DialogContent struct {
	Widget

	OnDialogShow   func()
	OnDialogReject func() bool
}

func (*DialogContent) InitWidget

func (c *DialogContent) InitWidget()

func (*DialogContent) RunInParent

func (c *DialogContent) RunInParent(f func())

RunInParent runs f after the current handler of the dialog returns, then updates the window the dialog was shown over. Use it for the dialog's result callbacks: they run once the dialog is closed, and the parent is repainted with the changes they made (see Form.Invoke). Read what f needs from the dialog's widgets before calling RunInParent.

type Dialoger

type Dialoger interface {
	// contains filtered or unexported methods
}

type DragData

type DragData struct {
	// Text is shown next to the mouse while dragging, and may be the data
	// itself
	Text string
	// Files are paths
	Files []string
	// Value is any data of the application
	Value any
	// Source is the widget the drag started from, nil for system files
	Source Widgeter
}

DragData is what is dragged: set the fields that apply. Files are set for files dragged from the system (e.g. from the file manager).

type DrawScript

type DrawScript struct {
	Bounds image.Rectangle
	// contains filtered or unexported fields
}

func NewDrawScript

func NewDrawScript() *DrawScript

func (*DrawScript) DrawToRGBA

func (c *DrawScript) DrawToRGBA(img *image.RGBA, col color.Color)

func (*DrawScript) MixPixel

func (c *DrawScript) MixPixel(img *image.RGBA, x int, y int, rgba color.Color, intensity uint32)

type DrawScriptHorLine

type DrawScriptHorLine struct {
	X1 int
	X2 int
	Y  int
	C  float64
}

type DrawScriptPoint

type DrawScriptPoint struct {
	X int
	Y int
	C float64
}

type EditableComboBox

type EditableComboBox struct {
	Widget
	// contains filtered or unexported fields
}

EditableComboBox is a text field with a list of suggestions: typing shows the items that contain the typed text (the ones that start with it first, the match highlighted); the arrow button or Alt+Down / F4 shows all of them. Up/Down move in the list, Enter or a click takes the item, Escape closes the list. Any text can be entered, not only an item.

city := ui.NewEditableComboBox()
city.SetItems([]string{"Amsterdam", "Berlin", "London", "Paris"})
city.SetOnItemSelected(func(index int, text string) { ... })

func NewEditableComboBox

func NewEditableComboBox() *EditableComboBox

func (*EditableComboBox) AddItem

func (c *EditableComboBox) AddItem(text string)

func (*EditableComboBox) Focus

func (c *EditableComboBox) Focus()

func (*EditableComboBox) IsPopupOpen

func (c *EditableComboBox) IsPopupOpen() bool

func (*EditableComboBox) Items

func (c *EditableComboBox) Items() []string

func (*EditableComboBox) SetAutoComplete

func (c *EditableComboBox) SetAutoComplete(enabled bool)

SetAutoComplete turns the suggestions while typing on (the default) or off; the arrow button still shows the list.

func (*EditableComboBox) SetEnabled

func (c *EditableComboBox) SetEnabled(enabled bool)

func (*EditableComboBox) SetHint

func (c *EditableComboBox) SetHint(hint string)

SetHint sets the gray text shown while the field is empty.

func (*EditableComboBox) SetItems

func (c *EditableComboBox) SetItems(items []string)

SetItems sets the suggestions.

func (*EditableComboBox) SetOnAccept

func (c *EditableComboBox) SetOnAccept(f func(text string))

SetOnAccept sets the function called on Enter while no suggestion is chosen.

func (*EditableComboBox) SetOnItemSelected

func (c *EditableComboBox) SetOnItemSelected(f func(index int, text string))

SetOnItemSelected sets the function called when the user takes an item from the list; index is its position in Items.

func (*EditableComboBox) SetOnTextChanged

func (c *EditableComboBox) SetOnTextChanged(f func())

SetOnTextChanged sets the function called when the user changes the text.

func (*EditableComboBox) SetSize

func (c *EditableComboBox) SetSize(w, h int)

SetSize lays the field out next to the arrow button.

func (*EditableComboBox) SetText

func (c *EditableComboBox) SetText(text string)

SetText sets the text without showing suggestions or calling SetOnTextChanged's function.

func (*EditableComboBox) Text

func (c *EditableComboBox) Text() string

func (*EditableComboBox) TextBox

func (c *EditableComboBox) TextBox() *TextBox

TextBox returns the field, e.g. to make it read-only or focus it.

type Event

type Event struct {
	Parameter any
}

func CurrentEvent

func CurrentEvent() *Event

type EventCheckboxStateChanged

type EventCheckboxStateChanged struct {
	Checkbox *Checkbox
	Checked  bool
}

type EventNumBoxValueChanged

type EventNumBoxValueChanged struct {
	NumBox *NumBox
	Value  float64
}

type EventTableCellMouseDblClick

type EventTableCellMouseDblClick struct {
	Table     *Table
	Row       int
	Col       int
	Processed bool
}

type EventTextboxKeyDown

type EventTextboxKeyDown struct {
	Key       Key
	Mods      KeyModifiers
	Processed bool
}

type Expander

type Expander struct {
	Widget
	// contains filtered or unexported fields
}

Expander is a section with a clickable header that shows or hides its content. The content is a Panel: add the widgets to Content(), laid out on its grid as usual.

adv := ui.NewExpander("Advanced")
adv.Content().AddLabel(0, 0, "Timeout")
adv.Content().AddWidget(0, 1, timeoutBox)

A click on the header, Space or Enter toggles it; Left collapses and Right expands it.

func NewExpander

func NewExpander(title string) *Expander

func (*Expander) AddWidget

func (c *Expander) AddWidget(gridRow int, gridColumn int, w Widgeter)

AddWidget adds the widget to the content panel (see Content)

func (*Expander) Content

func (c *Expander) Content() *Panel

Content is the panel holding the widgets shown when the expander is expanded

func (*Expander) Expanded

func (c *Expander) Expanded() bool

func (*Expander) MaxHeight

func (c *Expander) MaxHeight() int

MaxHeight keeps a collapsed expander at its header's height, and an expanded one at the height of its content unless the content stretches - so extra space in the parent goes to the widgets that can use it.

func (*Expander) ProcessKeyDown

func (c *Expander) ProcessKeyDown(key Key, mods KeyModifiers) bool

func (*Expander) SetExpanded

func (c *Expander) SetExpanded(expanded bool)

SetExpanded expands or collapses the expander without calling the SetOnExpandedChanged function.

func (*Expander) SetOnExpandedChanged

func (c *Expander) SetOnExpandedChanged(f func())

SetOnExpandedChanged sets the function called when the user expands or collapses the expander.

func (*Expander) SetTitle

func (c *Expander) SetTitle(title string)

func (*Expander) SetTitleFunc

func (c *Expander) SetTitleFunc(f func() string)

func (*Expander) Title

func (c *Expander) Title() string

type FileDialogFilter

type FileDialogFilter = platforms.FileDialogFilter

type Form

type Form struct {
	OnClose func() bool
	// contains filtered or unexported fields
}

func NewForm

func NewForm() *Form

func (*Form) AddShortcut

func (c *Form) AddShortcut(shortcut string, f func())

AddShortcut runs f when the shortcut is pressed in the form, whatever widget has the focus (except the keys a focused text field uses itself, like Ctrl+C). Panics on a wrong shortcut, see ParseShortcut.

form.AddShortcut("F5", refresh)
form.AddShortcut("Mod+F", func() { search.Focus() })

func (*Form) Beep

func (c *Form) Beep()

Beep plays the system alert sound

func (*Form) Close

func (c *Form) Close()

Close closes the window at once, without calling OnClose - the same on every platform. It may be called from any goroutine (off the UI thread it is handed over to it, see Invoke). A window that has a modal dialog open closes as soon as the dialog does. To close the window as if the user clicked its close button, so OnClose can veto it, use RequestClose.

func (*Form) CloseTopPopup

func (c *Form) CloseTopPopup()

func (*Form) DrawWidgetDebugInfo

func (c *Form) DrawWidgetDebugInfo(w Widgeter, cnv *Canvas)

func (*Form) Exec

func (c *Form) Exec()

Exec waits until the form is closed. Called from the main goroutine (the UI thread), it runs the event loop of all the forms meanwhile - this is how a program runs its main form:

form.Show()
form.Exec()

Called from a handler, it runs a nested event loop, so the other forms keep working. Called from another goroutine, it just waits.

func (*Form) FocusedWidget

func (c *Form) FocusedWidget() Widgeter

func (*Form) Hide

func (c *Form) Hide()

Hide hides the form's window, taskbar button and all, until the next Show. The form stays open: Exec keeps waiting, the timers keep running. Useful with a TrayIcon, to keep the application in the tray.

func (*Form) Invoke

func (c *Form) Invoke(f func())

Invoke runs f on the UI thread, then updates the form, and returns at once. Safe to call from any goroutine: it is how a background goroutine changes the widgets of the form. Called on the UI thread, f runs after the current handler. See also the package-level Invoke.

func (*Form) IsActive

func (c *Form) IsActive() bool

IsActive reports whether the window has the keyboard focus

func (*Form) IsHidden

func (c *Form) IsHidden() bool

IsHidden reports whether the form is hidden by Hide

func (*Form) IsMaximized

func (c *Form) IsMaximized() bool

func (*Form) KeyModifiers

func (c *Form) KeyModifiers() KeyModifiers

KeyModifiers returns which of Shift, Ctrl, Alt (and Cmd on macOS) are held right now - not only inside a key event. A program can show what the keys do with them, like the function key bar of a file manager that changes while Shift is held: read it in a timer. While another window or application is active nothing is held for this window. Call it on the UI thread. Before the window is shown it returns the state of the last key event.

func (*Form) LayoutingBlockPop

func (c *Form) LayoutingBlockPop()

func (*Form) LayoutingBlockPush

func (c *Form) LayoutingBlockPush()

func (*Form) Maximize

func (c *Form) Maximize()

func (*Form) MenuBar

func (c *Form) MenuBar() *MenuBar

func (*Form) MinSize

func (c *Form) MinSize() (int, int)

layoutMenuBar places the menu bar at the top of the client area and the top widget in the rest of it. MinSize returns the smallest size of the client area the widgets fit in: each of them gets at least its minimum size

func (*Form) Minimize

func (c *Form) Minimize()

func (*Form) Move

func (c *Form) Move(x, y int)

func (*Form) MoveToCenterOfParent

func (c *Form) MoveToCenterOfParent()

MoveToCenterOfParent re-centers the window over the form it was shown modally over (see ShowModal). Useful when a dialog only knows its real size once it's building itself (e.g. from OnDialogShow, after SetSize), i.e. too late for ShowModal's own initial centering to use it. Does nothing if the form was not shown via ShowModal.

func (*Form) OpenPopup

func (c *Form) OpenPopup(w Widgeter)

OpenPopup shows w above the form's widgets, e.g. a dropdown of your own widget. Before calling it, give w its size and its position in the form's client coordinates - RectClientAreaOnWindow tells where a widget is:

x, y := field.RectClientAreaOnWindow()
picker.SetSize(200, 150)
picker.SetPosition(x, y+field.Height())
form.OpenPopup(picker)

The popup is shown in its own window, so it can extend beyond the form, and is kept on the screen. Implement PopupPlacer to choose where it goes when it doesn't fit. Its children are laid out on the grid like in any panel.

The popup closes on a click outside it (see SetCloseByClickOutside), on Escape, when the form loses activation or is moved, and by CloseTopPopup.

func (*Form) Panel

func (c *Form) Panel() *Panel

func (*Form) ParentForm

func (c *Form) ParentForm() *Form

ParentForm returns the form this one was shown modally over, nil if none

func (*Form) Position

func (c *Form) Position() (int, int)

func (*Form) Print

func (c *Form) Print(job *PrintJob, onDone func(err error))

Print prints the job: it shows the print dialog - the system's on Windows, nui's elsewhere, with the printers of CUPS and "Save as PDF" - and prints on the printer the user chose. onDone is called on the UI thread with nil when the job went to the printer (or the PDF is saved), ErrPrintCanceled when the user canceled, or the error.

func (*Form) RemoveShortcut

func (c *Form) RemoveShortcut(shortcut string)

RemoveShortcut removes a shortcut added by AddShortcut

func (*Form) RequestAttention

func (c *Form) RequestAttention()

RequestAttention marks the window in the taskbar/dock until the user looks at it

func (*Form) RequestClose

func (c *Form) RequestClose() bool

RequestClose closes the window as if the user clicked its close button: OnClose is called first and may keep the window open. Returns true if the window is closed. Call it on the UI thread (e.g. from a handler or via Invoke), like OnClose itself runs.

func (*Form) Restore

func (c *Form) Restore()

Restore returns a maximized window to its normal size

func (*Form) SetAcceptButton

func (c *Form) SetAcceptButton(button *Button)

func (*Form) SetAllowMaximize

func (c *Form) SetAllowMaximize(allow bool)

func (*Form) SetAllowMinimize

func (c *Form) SetAllowMinimize(allow bool)

func (*Form) SetAlwaysOnTop

func (c *Form) SetAlwaysOnTop(onTop bool)

SetAlwaysOnTop keeps the window above the other windows; call it once the form is shown

func (*Form) SetCancelButton

func (c *Form) SetCancelButton(button *Button)

func (*Form) SetIcon

func (c *Form) SetIcon(img image.Image)

SetIcon overrides the application icon (see SetAppIcon) for this form. Can be called before or after the window is shown. A nil image is ignored.

func (*Form) SetMainWidget

func (c *Form) SetMainWidget(w Widgeter)

func (*Form) SetMenuBar

func (c *Form) SetMenuBar(bar *MenuBar)

SetMenuBar shows the main menu at the top of the form, above Panel(). nil removes it.

func (*Form) SetOnActivated

func (c *Form) SetOnActivated(f func())

SetOnActivated sets the function called when the window becomes active: shown, or the user came back to it from another window or application

func (*Form) SetOnDeactivated

func (c *Form) SetOnDeactivated(f func())

SetOnDeactivated sets the function called when the window stops being active: the user switched to another window or application

func (*Form) SetOnFilesDropped

func (c *Form) SetOnFilesDropped(f func(files []string, x, y int))

SetOnFilesDropped sets the function called when files dragged from the system are dropped on the form outside every drop target that accepts them. x, y is the point in the form's client coordinates.

func (*Form) SetOnGlobalKeyDown

func (c *Form) SetOnGlobalKeyDown(onGlobalKeyDown func(keyCode Key, mods KeyModifiers) bool)

func (*Form) SetOnLanguageChanged

func (c *Form) SetOnLanguageChanged(f func())

SetOnLanguageChanged sets the function that updates the texts SetTextFunc doesn't cover (table headers, combo box items, texts put together...) when the language changes.

func (*Form) SetSize

func (c *Form) SetSize(width, height int)

SetSize sets the size of the client area; it doesn't get smaller than the widgets need, see MinSize

func (*Form) SetTitle

func (c *Form) SetTitle(title string)

func (*Form) SetTitleFunc

func (c *Form) SetTitleFunc(f func() string)

SetTitleFunc makes the form's title come from f, now and on every language change.

func (*Form) Show

func (c *Form) Show()

Show opens the form as a non-modal window and returns at once; a hidden form (see Hide) comes back. The window lives on the UI thread: called from another goroutine, Show opens it there and waits for it (see InvokeSync).

func (*Form) ShowContextMenu

func (c *Form) ShowContextMenu(menu *ContextMenu, x int, y int)

ShowContextMenu opens a menu at (x, y) of the form's client area, from code: e.g. a list of the recent directories on a hotkey. The menu doesn't have to belong to a widget (see Widget.SetContextMenu)

func (*Form) ShowMaximized

func (c *Form) ShowMaximized()

func (*Form) ShowModal

func (c *Form) ShowModal(parent *Form)

ShowModal opens the form as a modal dialog over parent, which gets no input until the dialog is closed. It returns at once (on macOS, once the dialog is closed). Like Show, it opens the window on the UI thread.

func (*Form) ShowOpenFileDialog

func (c *Form) ShowOpenFileDialog(opts OpenFileDialogOptions, onResult func(paths []string, err error))

ShowOpenFileDialog shows the system "Open File" dialog without blocking the form and calls onResult on the UI thread: paths is empty when the user cancelled. opts.AllowMultiple lets the user pick several files.

func (*Form) ShowSaveFileDialog

func (c *Form) ShowSaveFileDialog(opts SaveFileDialogOptions, onResult func(path string, err error))

ShowSaveFileDialog shows the system "Save File" dialog without blocking the form and calls onResult on the UI thread: path is "" when the user cancelled.

func (*Form) ShowSelectDirectoryDialog

func (c *Form) ShowSelectDirectoryDialog(opts SelectDirectoryDialogOptions, onResult func(path string, err error))

ShowSelectDirectoryDialog shows the system "Select Folder" dialog without blocking the form and calls onResult on the UI thread: path is "" when the user cancelled.

func (*Form) ShowToast

func (c *Form) ShowToast(text string, kind ToastKind)

ShowToast shows a short message in the bottom-right corner of the form for ToastDefaultDuration. A click on it closes it at once. The newest toast is at the bottom; the oldest ones go away when there are too many.

func (*Form) ShowToastFor

func (c *Form) ShowToastFor(text string, kind ToastKind, duration time.Duration)

ShowToastFor is ShowToast with the time the toast stays on the screen

func (*Form) Size

func (c *Form) Size() (int, int)

func (*Form) SystemHandle

func (c *Form) SystemHandle() any

func (*Form) TopPopupWidget

func (c *Form) TopPopupWidget() Widgeter

func (*Form) Update

func (c *Form) Update()

func (*Form) UpdateBlockPop

func (c *Form) UpdateBlockPop()

func (*Form) UpdateBlockPush

func (c *Form) UpdateBlockPush()

func (*Form) UpdateLayout

func (c *Form) UpdateLayout()

func (*Form) WidgetById

func (c *Form) WidgetById(id string) Widgeter

type Frame

type Frame struct {
	Widget
}

func NewFrame

func NewFrame() *Frame

type GroupBox

type GroupBox struct {
	Widget
	// contains filtered or unexported fields
}

GroupBox is a panel framed with a title, grouping related controls. Its children are laid out on the grid like in a Panel:

group := ui.NewGroupBox("Connection")
group.AddLabel(0, 0, "Host")
group.AddWidget(0, 1, hostBox)

func NewGroupBox

func NewGroupBox(title string) *GroupBox

func (*GroupBox) SetTitle

func (c *GroupBox) SetTitle(title string)

func (*GroupBox) SetTitleFunc

func (c *GroupBox) SetTitleFunc(f func() string)

func (*GroupBox) Title

func (c *GroupBox) Title() string

type HAlign

type HAlign int
const HAlignCenter HAlign = 1
const HAlignLeft HAlign = 0
const HAlignRight HAlign = 2

func (*HAlign) String

func (c *HAlign) String() string

type HSpacer

type HSpacer struct {
	Widget
}

func NewHSpacer

func NewHSpacer() *HSpacer

type ImageBox

type ImageBox struct {
	Widget
	// contains filtered or unexported fields
}

func NewImageBox

func NewImageBox() *ImageBox

func (*ImageBox) Image

func (c *ImageBox) Image() image.Image

func (*ImageBox) MaxHeight

func (c *ImageBox) MaxHeight() int

func (*ImageBox) MaxWidth

func (c *ImageBox) MaxWidth() int

func (*ImageBox) MinHeight

func (c *ImageBox) MinHeight() int

func (*ImageBox) MinWidth

func (c *ImageBox) MinWidth() int

func (*ImageBox) Scaling

func (c *ImageBox) Scaling() ImageBoxScale

func (*ImageBox) SetImage

func (c *ImageBox) SetImage(img image.Image)

func (*ImageBox) SetScaling

func (c *ImageBox) SetScaling(scaling ImageBoxScale)

type ImageBoxScale

type ImageBoxScale int
const (
	ImageBoxScaleNoScaleAdjustBox           ImageBoxScale = 0
	ImageBoxScaleNoScaleImageInLeftTop      ImageBoxScale = 1
	ImageBoxScaleNoScaleImageInCenter       ImageBoxScale = 2
	ImageBoxScaleStretchImage               ImageBoxScale = 3
	ImageBoxScaleAdjustImageKeepAspectRatio ImageBoxScale = 4
)

type Key

type Key = platforms.Key

type KeyModifiers

type KeyModifiers = platforms.KeyModifiers

type Label

type Label struct {
	Widget
}

func NewLabel

func NewLabel(text string) *Label

////////////////////////////////////////////////////////////////////////////////// NewLabel creates a new Label widget with the specified text.

func (*Label) IsUnderline

func (c *Label) IsUnderline() bool

IsUnderline returns whether the Label's text is underlined.

func (*Label) ProcessPropChange

func (c *Label) ProcessPropChange(key string, value interface{})

/////////////////////////////////////////////////////////////////////////////// Props

func (*Label) SetText

func (c *Label) SetText(text string)

SetText sets the text of the Label.

func (*Label) SetTextAlign

func (c *Label) SetTextAlign(align HAlign)

SetTextAlign sets the horizontal alignment of the Label's text.

func (*Label) SetTextFunc

func (c *Label) SetTextFunc(f func() string)

func (*Label) SetUnderline

func (c *Label) SetUnderline(underline bool)

SetUnderline sets whether the Label's text is underlined.

func (*Label) Text

func (c *Label) Text() string

Text returns the text of the Label.

func (*Label) TextAlign

func (c *Label) TextAlign() HAlign

TextAlign returns the horizontal alignment of the Label's text.

type Link struct {
	Widget
	// contains filtered or unexported fields
}

Link is a clickable text, like a hyperlink: underlined under the mouse, activated by a click, Enter or Space. It calls its function, or opens its URL in the browser when it has no function.

help := ui.NewLink("Documentation", nil)
help.SetURL("https://example.com/docs")
func NewLink(text string, onClick func()) *Link

func (*Link) Activate

func (c *Link) Activate()

Activate does what a click does.

func (*Link) ProcessKeyDown

func (c *Link) ProcessKeyDown(key Key, mods KeyModifiers) bool

func (*Link) SetOnClick

func (c *Link) SetOnClick(f func())

SetOnClick sets the function called when the link is activated.

func (*Link) SetText

func (c *Link) SetText(text string)

func (*Link) SetTextFunc

func (c *Link) SetTextFunc(f func() string)

func (*Link) SetURL

func (c *Link) SetURL(url string)

SetURL sets the address opened in the browser when the link has no function; it's also shown as the tooltip unless one is set.

func (*Link) Text

func (c *Link) Text() string

func (*Link) URL

func (c *Link) URL() string

func (*Link) Visited

func (c *Link) Visited() bool

Visited reports whether the link was activated; it's drawn in a softer color.

type MenuBar struct {
	Widget
	// contains filtered or unexported fields
}

MenuBar is the main menu of a form: a row of titles at the top of the window, each opening a ContextMenu that drops down below it. Install it with Form.SetMenuBar:

bar := ui.NewMenuBar()
file := bar.AddMenu("File")
file.AddItem("Open", onOpen)
file.AddSeparator()
file.AddItem("Exit", func() { form.Close() })
form.SetMenuBar(bar)

While one of its menus is open, moving the mouse to another title opens that title's menu instead, as in the usual desktop menus.

func NewMenuBar

func NewMenuBar() *MenuBar
func (c *MenuBar) AddMenu(text string) *ContextMenu

AddMenu adds a title and returns its menu, to be filled like any ContextMenu (items, separators, submenus, icons).

func (c *MenuBar) AddMenuItem(text string, menu *ContextMenu) *MenuBarItem

AddMenuItem adds a title that opens an existing menu. Returns the title, e.g. to give it a text that follows the language (SetTextFunc).

func (c *MenuBar) Items() []*MenuBarItem

Items returns the titles of the bar.

type MenuBarItem struct {
	Widget
	// contains filtered or unexported fields
}

MenuBarItem is a title in a MenuBar. "&" in its text marks the mnemonic letter: "&File" opens with Alt+F, F underlined while Alt is held.

func (c *MenuBarItem) Menu() *ContextMenu

Menu returns the menu the title opens.

func (c *MenuBarItem) SetText(text string)
func (c *MenuBarItem) SetTextFunc(f func() string)
func (c *MenuBarItem) SetVisible(visible bool)

SetVisible hides or shows the title; the titles after it move over.

func (c *MenuBarItem) Text() string

type MouseButton

type MouseButton = platforms.MouseButton

type MouseCursor

type MouseCursor = platforms.MouseCursor

func MouseCursorFromString

func MouseCursorFromString(s string) MouseCursor

type NumBox

type NumBox struct {
	Widget
	// contains filtered or unexported fields
}

NumBox is a single-line numeric input for float64 with min/max clamp, fixed decimals formatting and spin buttons (up/down).

func NewNumBox

func NewNumBox() *NumBox

func (*NumBox) Decimals

func (c *NumBox) Decimals() int

func (*NumBox) GetValue

func (c *NumBox) GetValue() float64

func (*NumBox) IsCanBeFocused

func (c *NumBox) IsCanBeFocused() bool

IsCanBeFocused: a disabled box is skipped, e.g. by Tab

func (*NumBox) Max

func (c *NumBox) Max() float64

func (*NumBox) Min

func (c *NumBox) Min() float64

func (*NumBox) MouseCursor

func (c *NumBox) MouseCursor() MouseCursor

MouseCursor: no text cursor over a disabled box

func (*NumBox) ProcessPropChange

func (c *NumBox) ProcessPropChange(key string, value interface{})

func (*NumBox) SetDecimals

func (c *NumBox) SetDecimals(decimals int)

func (*NumBox) SetMax

func (c *NumBox) SetMax(max float64)

func (*NumBox) SetMin

func (c *NumBox) SetMin(min float64)

func (*NumBox) SetOnChanged

func (c *NumBox) SetOnChanged(f func())

SetOnChanged is an alias for SetOnValueChanged, kept for consistency with other controls.

func (*NumBox) SetOnValueChanged

func (c *NumBox) SetOnValueChanged(f func())

func (*NumBox) SetStep

func (c *NumBox) SetStep(step float64)

func (*NumBox) SetText

func (c *NumBox) SetText(text string)

func (*NumBox) SetValue

func (c *NumBox) SetValue(v float64)

func (*NumBox) Step

func (c *NumBox) Step() float64

func (*NumBox) Text

func (c *NumBox) Text() string

func (*NumBox) Value

func (c *NumBox) Value() float64

type OpenFileDialogOptions

type OpenFileDialogOptions = platforms.OpenFileDialogOptions

type Panel

type Panel struct {
	Widget
}

func NewPanel

func NewPanel() *Panel

type PaperSize

type PaperSize struct {
	Name          string
	Width, Height float64
}

PaperSize is a paper size in millimeters, portrait

type PopupCanceler

type PopupCanceler interface {
	CancelPopup()
}

PopupCanceler is implemented by popup widgets that undo what was done in them when Escape closes them (a click outside keeps it), e.g. a color picker's panel returning to the color it was opened with.

type PopupPlacer

type PopupPlacer interface {
	// PopupFlipped returns, in the form's client coordinates, the X to use
	// when the popup doesn't fit to the right and the Y to use when it
	// doesn't fit below
	PopupFlipped() (x, y int)
}

PopupPlacer is implemented by popup widgets (see Form.OpenPopup) that know a better position than being pushed back onto the screen when they don't fit on it.

type PrintJob

type PrintJob struct {
	Title string
	// Pages is the number of pages; or set Paginate when it depends on the
	// page size
	Pages int
	// Paginate returns the number of pages for the page size (e.g. how many
	// pages a text takes); called before drawing them
	Paginate func(width, height int, dpi float64) int
	// DrawPage draws one page on the white page canvas
	DrawPage func(p *PrintPage)

	// Paper and Landscape are the page for SavePDF and nui's print dialog;
	// with the Windows print dialog the printer's settings apply. A4 if not set.
	Paper     PaperSize
	Landscape bool
	// DPI is the resolution the pages are drawn at, DefaultPrintDPI if 0
	DPI float64
}

PrintJob is a document to print or to save as PDF

func NewTextPrintJob

func NewTextPrintJob(title, text string, opts *TextPrintOptions) *PrintJob

NewTextPrintJob makes a job that prints plain text: the lines are wrapped to the page width (keeping their indentation) and split into pages, with page numbers at the bottom.

form.Print(ui.NewTextPrintJob("notes.txt", text, nil), nil)
ui.NewTextPrintJob("log", logText, &ui.TextPrintOptions{FontFamily: ui.FontFamilyMono}).SavePDF("log.pdf")

func (*PrintJob) SavePDF

func (j *PrintJob) SavePDF(path string) error

SavePDF writes all the pages to a PDF file

func (*PrintJob) WritePDF

func (j *PrintJob) WritePDF(w io.Writer, pages []int) error

WritePDF writes the pages (0-based; nil for all) as a PDF document

type PrintPage

type PrintPage struct {
	Canvas *Canvas
	// Index is the page's number, from 0; Count is the number of pages
	Index, Count int
	// Width and Height are the page size in pixels at DPI: the whole paper
	// in a PDF, the printable area on a printer
	Width, Height int
	DPI           float64
}

PrintPage is the page being drawn

func (*PrintPage) FontSize

func (p *PrintPage) FontSize(points float64) float64

FontSize converts a font size in points (1/72 inch) to the pixels the canvas takes: Canvas.SetFontSize(p.FontSize(10)) for 10 pt text

func (*PrintPage) MM

func (p *PrintPage) MM(mm float64) int

MM converts millimeters to the page's pixels

type ProgressBar

type ProgressBar struct {
	Widget
	// contains filtered or unexported fields
}

func NewProgressBar

func NewProgressBar(minValue, maxValue, initValue float64) *ProgressBar

func (*ProgressBar) SetMaxValue

func (c *ProgressBar) SetMaxValue(maxValue float64)

func (*ProgressBar) SetMinValue

func (c *ProgressBar) SetMinValue(minValue float64)

func (*ProgressBar) SetText

func (c *ProgressBar) SetText(text string)

func (*ProgressBar) SetValue

func (c *ProgressBar) SetValue(value float64)

func (*ProgressBar) Text

func (c *ProgressBar) Text() string

func (*ProgressBar) Value

func (c *ProgressBar) Value() float64

type Property

type Property struct {
	// contains filtered or unexported fields
}

Property is one row of a PropertyGrid: a name and the editor of its value.

func (*Property) Category

func (p *Property) Category() string

func (*Property) Editor

func (p *Property) Editor() Widgeter

Editor returns the widget that edits the value

func (*Property) Name

func (p *Property) Name() string

func (*Property) NotifyChanged

func (p *Property) NotifyChanged()

NotifyChanged reports a change made by the user in a custom editor (see AddCustom)

func (*Property) SetDescription

func (p *Property) SetDescription(text string)

SetDescription sets the text shown when the mouse rests on the property

func (*Property) SetOnChanged

func (p *Property) SetOnChanged(f func())

SetOnChanged sets the function called when the user changes this property

func (*Property) SetReadOnly

func (p *Property) SetReadOnly(readOnly bool)

SetReadOnly shows the value without letting the user change it

func (*Property) SetValue

func (p *Property) SetValue(v any)

SetValue sets the value without calling the change functions

func (*Property) Value

func (p *Property) Value() any

Value returns the value: string, int, float64, bool, the option index (int), color.RGBA or time.Time, depending on how the property was added

type PropertyGrid

type PropertyGrid struct {
	Widget
	// contains filtered or unexported fields
}

PropertyGrid is a list of named values - properties - edited in place, grouped in collapsible categories. Each property has an editor for its type: a text box, a number box, a checkbox, a combo box, a color picker or a date picker, or any widget (AddCustom).

grid := ui.NewPropertyGrid()
grid.AddString("General", "Name", "Server 1")
grid.AddInt("Network", "Port", 8080, 1, 65535)
grid.AddBool("Network", "Use TLS", true)
grid.SetOnChanged(func(p *ui.Property) { fmt.Println(p.Name(), p.Value()) })

SetObject fills the grid from the exported fields of a struct and writes the edits back into it (see SetObject for the field tags).

func NewPropertyGrid

func NewPropertyGrid() *PropertyGrid

func (*PropertyGrid) AddBool

func (c *PropertyGrid) AddBool(category, name string, value bool) *Property

AddBool adds a yes/no property edited in a checkbox

func (*PropertyGrid) AddChoice

func (c *PropertyGrid) AddChoice(category, name string, options []string, index int) *Property

AddChoice adds a property chosen from the options in a combo box. Its value is the index of the chosen option; SetValue also takes the option's text.

func (*PropertyGrid) AddColor

func (c *PropertyGrid) AddColor(category, name string, value color.RGBA) *Property

AddColor adds a color property edited in a color picker

func (*PropertyGrid) AddCustom

func (c *PropertyGrid) AddCustom(category, name string, editor Widgeter) *Property

AddCustom adds a property edited in any widget. Its Value is nil: read the widget itself, and call the property's NotifyChanged when it changes.

func (*PropertyGrid) AddDate

func (c *PropertyGrid) AddDate(category, name string, value time.Time) *Property

AddDate adds a date property edited in a date picker

func (*PropertyGrid) AddFloat

func (c *PropertyGrid) AddFloat(category, name string, value float64, decimals int) *Property

AddFloat adds a number property edited in a number box with the decimals

func (*PropertyGrid) AddInt

func (c *PropertyGrid) AddInt(category, name string, value, min, max int) *Property

AddInt adds a whole number property edited in a number box, from min to max

func (*PropertyGrid) AddString

func (c *PropertyGrid) AddString(category, name, value string) *Property

AddString adds a property edited in a text box

func (*PropertyGrid) Category

func (c *PropertyGrid) Category(name string) *Expander

Category returns the expander of the category, nil if there is none, e.g. to collapse it

func (*PropertyGrid) Clear

func (c *PropertyGrid) Clear()

Clear removes all the properties

func (*PropertyGrid) Properties

func (c *PropertyGrid) Properties() []*Property

Properties returns the properties in the order they were added

func (*PropertyGrid) Property

func (c *PropertyGrid) Property(name string) *Property

Property returns the property with the name, nil if there is none

func (*PropertyGrid) Refresh

func (c *PropertyGrid) Refresh()

Refresh shows the current values of the struct given to SetObject, after the code changed them

func (*PropertyGrid) SetObject

func (c *PropertyGrid) SetObject(obj any) error

SetObject fills the grid with the exported fields of the struct obj points to, and writes the user's changes back into those fields. Supported field types: string, bool, the integer and float types, color.RGBA and time.Time. Field tags:

prop:"Display name"    the name shown ("-" skips the field)
category:"Network"     the category
desc:"..."             the tooltip
min:"0" max:"100"      the range of a number
decimals:"2"           the decimals of a float
options:"Low,High"     a string (or int index) chosen from the options
readonly:"true"        shown but not editable

Call Refresh after changing the struct from the code.

func (*PropertyGrid) SetOnChanged

func (c *PropertyGrid) SetOnChanged(f func(p *Property))

SetOnChanged sets the function called when the user changes a property

type RadioButton

type RadioButton struct {
	Widget
	// contains filtered or unexported fields
}

func NewRadioButton

func NewRadioButton(text string) *RadioButton

func (*RadioButton) Checked

func (c *RadioButton) Checked() bool

func (*RadioButton) SetChecked

func (c *RadioButton) SetChecked(checked bool)

func (*RadioButton) SetOnStateChanged

func (c *RadioButton) SetOnStateChanged(fn func(btn *RadioButton, checked bool))

func (*RadioButton) SetText

func (c *RadioButton) SetText(text string)

func (*RadioButton) SetTextFunc

func (c *RadioButton) SetTextFunc(f func() string)

func (*RadioButton) Text

func (c *RadioButton) Text() string

type SaveFileDialogOptions

type SaveFileDialogOptions = platforms.SaveFileDialogOptions

type ScrollArea

type ScrollArea struct {
	Widget
}

func NewScrollArea

func NewScrollArea() *ScrollArea

type SelectDirectoryDialogOptions

type SelectDirectoryDialogOptions = platforms.SelectDirectoryDialogOptions

type Shortcut

type Shortcut struct {
	Key                   Key
	Ctrl, Shift, Alt, Cmd bool
}

Shortcut is a key with modifiers, e.g. Ctrl+S. It is matched by the key's place on the keyboard, so Ctrl+S works in any keyboard layout.

func MustParseShortcut

func MustParseShortcut(s string) Shortcut

MustParseShortcut is ParseShortcut that panics on a wrong shortcut

func ParseShortcut

func ParseShortcut(s string) (Shortcut, error)

ParseShortcut parses a shortcut like "Ctrl+S", "Ctrl+Shift+Z", "Alt+F4", "F5" or "Delete". "Mod" is Cmd on macOS and Ctrl elsewhere: "Mod+S" saves with the usual key of each system.

func (Shortcut) IsZero

func (s Shortcut) IsZero() bool

func (Shortcut) Matches

func (s Shortcut) Matches(key Key, mods KeyModifiers) bool

Matches reports whether the key with exactly these modifiers is the shortcut

func (Shortcut) String

func (s Shortcut) String() string

String is the shortcut as menus show it: "Ctrl+Shift+S", "⇧⌘S" on macOS

type Slider

type Slider struct {
	Widget
	// contains filtered or unexported fields
}

Slider chooses a number in a range by dragging a thumb along a track. A click on the track moves the thumb there; the arrows move it by a step, PageUp/PageDown by a page, Home/End to the ends; so does the mouse wheel.

volume := ui.NewSlider()
volume.SetRange(0, 100)
volume.SetStep(1)
volume.SetOnValueChanged(func() { player.SetVolume(volume.Value()) })

func NewSlider

func NewSlider() *Slider

func (*Slider) IsVertical

func (c *Slider) IsVertical() bool

func (*Slider) Max

func (c *Slider) Max() float64

func (*Slider) Min

func (c *Slider) Min() float64

func (*Slider) ProcessKeyDown

func (c *Slider) ProcessKeyDown(key Key, mods KeyModifiers) bool

func (*Slider) SetMax

func (c *Slider) SetMax(max float64)

func (*Slider) SetMin

func (c *Slider) SetMin(min float64)

func (*Slider) SetOnValueChanged

func (c *Slider) SetOnValueChanged(f func())

SetOnValueChanged sets the function called when the user changes the value, also while dragging.

func (*Slider) SetPageStep

func (c *Slider) SetPageStep(step float64)

SetPageStep sets how far PageUp/PageDown move; 0 (the default) is 1/10 of the range.

func (*Slider) SetRange

func (c *Slider) SetRange(min, max float64)

SetRange sets the minimum and the maximum; the value is kept in them.

func (*Slider) SetStep

func (c *Slider) SetStep(step float64)

SetStep makes the value a multiple of step from the minimum; 0 (the default) allows any value, and the keys move by 1/100 of the range.

func (*Slider) SetTickInterval

func (c *Slider) SetTickInterval(interval float64)

SetTickInterval draws a tick every interval along the track; 0 draws none.

func (*Slider) SetValue

func (c *Slider) SetValue(value float64)

SetValue sets the value, kept in the range and on the step, without calling SetOnValueChanged's function.

func (*Slider) SetVertical

func (c *Slider) SetVertical(vertical bool)

SetVertical puts the track upright, the minimum at the bottom.

func (*Slider) Step

func (c *Slider) Step() float64

func (*Slider) Value

func (c *Slider) Value() float64

type Space

type Space struct {
	Widget
}

func NewSpace

func NewSpace() *Space

func (*Space) MaxHeight

func (c *Space) MaxHeight() int

func (*Space) MaxWidth

func (c *Space) MaxWidth() int

func (*Space) MinHeight

func (c *Space) MinHeight() int

func (*Space) MinWidth

func (c *Space) MinWidth() int

func (*Space) SetSize

func (c *Space) SetSize(width, height int)

type Splitter

type Splitter struct {
	Widget
	// contains filtered or unexported fields
}

Splitter shows two widgets side by side (or one above the other) with a handle between them that can be dragged to resize them.

One of the panes is "fixed": it keeps its size when the splitter is resized, the other one takes the rest. SetFirstSize makes the first pane fixed, SetSecondSize makes the second pane fixed. If one of the panes is hidden, the other one takes the whole area.

func NewHSplitter

func NewHSplitter() *Splitter

NewHSplitter creates a splitter with the panes on the left and on the right

func NewVSplitter

func NewVSplitter() *Splitter

NewVSplitter creates a splitter with the panes on the top and on the bottom

func (*Splitter) First

func (c *Splitter) First() Widgeter

func (*Splitter) FirstSize

func (c *Splitter) FirstSize() int

FirstSize returns the current size of the first pane

func (*Splitter) HandleSize

func (c *Splitter) HandleSize() int

func (*Splitter) IsVertical

func (c *Splitter) IsVertical() bool

func (*Splitter) MinHeight

func (c *Splitter) MinHeight() int

func (*Splitter) MinWidth

func (c *Splitter) MinWidth() int

func (*Splitter) Second

func (c *Splitter) Second() Widgeter

func (*Splitter) SecondSize

func (c *Splitter) SecondSize() int

SecondSize returns the current size of the second pane

func (*Splitter) SetFirstSize

func (c *Splitter) SetFirstSize(size int)

SetFirstSize sets the size of the first pane and keeps it when the splitter is resized

func (*Splitter) SetHandleSize

func (c *Splitter) SetHandleSize(size int)

SetHandleSize sets the thickness of the handle between the panes

func (*Splitter) SetOnSplitChanged

func (c *Splitter) SetOnSplitChanged(fn func())

SetOnSplitChanged sets the callback called when the user has dragged the handle

func (*Splitter) SetSecondSize

func (c *Splitter) SetSecondSize(size int)

SetSecondSize sets the size of the second pane and keeps it when the splitter is resized

func (*Splitter) SetSize

func (c *Splitter) SetSize(w, h int)

func (*Splitter) SetWidgets

func (c *Splitter) SetWidgets(first, second Widgeter)

SetWidgets sets the panes: left/top and right/bottom. nil leaves the pane empty.

func (*Splitter) XExpandable

func (c *Splitter) XExpandable() bool

The splitter always fills the space given to it

func (*Splitter) YExpandable

func (c *Splitter) YExpandable() bool

type TabWidget

type TabWidget struct {
	Widget
	// contains filtered or unexported fields
}

func NewTabWidget

func NewTabWidget() *TabWidget

func (*TabWidget) AddPage

func (c *TabWidget) AddPage(name string, widgeter Widgeter)

func (*TabWidget) SetLayoutXml

func (c *TabWidget) SetLayoutXml(n *uiNode, eventProcessor interface{}, widgets map[string]Widgeter)

func (*TabWidget) SetPageNameFunc

func (c *TabWidget) SetPageNameFunc(index int, f func() string)

SetPageNameFunc makes the name of the page come from f, now and on every language change.

type Table

type Table struct {
	Widget
	// contains filtered or unexported fields
}

func NewTable

func NewTable() *Table

func (*Table) AddWidgetOnTable

func (c *Table) AddWidgetOnTable(widget Widgeter, posCellRow int, posCellCol int, widthInCells int, heightInCells int)

func (*Table) CancelCellEditor

func (c *Table) CancelCellEditor()

CancelCellEditor closes the editor of EditCell, if one is open, as Esc does

func (*Table) CellBorderColor

func (c *Table) CellBorderColor() color.Color

func (*Table) CellBorderWidth

func (c *Table) CellBorderWidth() int

func (*Table) CellPadding

func (c *Table) CellPadding() int

func (*Table) ClearRows

func (c *Table) ClearRows()

ClearRows removes all the rows, as in a new table: the cells with their text, data, images and colors, the selection and the current cell. RowCount becomes 0. An open cell editor is closed without applying it.

SetRowCount only changes how many rows are shown: the cells of the rows beyond the count are kept, and come back when the count grows again. To load other data, call ClearRows first, then fill the cells and set the count.

func (*Table) ClearSelection

func (c *Table) ClearSelection()

ClearSelection removes the selection entirely: nothing is selected and CurrentRow() returns -1 until a row is clicked or navigated to again (Arrow Down / Home then start from the first row).

func (*Table) ClearSelectionOnEmptyClick

func (c *Table) ClearSelectionOnEmptyClick() bool

func (*Table) ColumnCount

func (c *Table) ColumnCount() int

func (*Table) ColumnName

func (c *Table) ColumnName(col int) string

func (*Table) ColumnWidth

func (c *Table) ColumnWidth(col int) int

func (*Table) CopySelectionToClipboard

func (c *Table) CopySelectionToClipboard()

func (*Table) CurrentColumn

func (c *Table) CurrentColumn() int

func (*Table) CurrentRow

func (c *Table) CurrentRow() int

func (*Table) EditCell

func (c *Table) EditCell(row, col, colSpan int, text string, onDone func(text string, accepted bool)) *TextBox

EditCell opens a one-line editor over the cells [col, col+colSpan) of the row, with the text in it (in-place renaming of file managers). onDone gets the text: accepted is true on Enter and when the editor loses the focus, false on Esc; the cell itself is not changed. Returns the editor (to select a part of the text, for example), nil if the cell is out of the table.

func (*Table) EditCurrentCell

func (c *Table) EditCurrentCell(enteredText string)

func (*Table) GetCellData2

func (c *Table) GetCellData2(row int, col int) interface{}

func (*Table) GetCellText2

func (c *Table) GetCellText2(row int, col int) string

func (*Table) IsCellSelected

func (c *Table) IsCellSelected(row int, col int) bool

IsCellSelected reports whether the given cell is selected. Only meaningful when SelectingRows() is false.

func (*Table) IsEditingCell

func (c *Table) IsEditingCell() bool

IsEditingCell tells whether the editor of EditCell is open

func (*Table) IsRowSelected

func (c *Table) IsRowSelected(row int) bool

IsRowSelected reports whether the given row is selected. Only meaningful when SelectingRows() is true.

func (*Table) Multiselect

func (c *Table) Multiselect() bool

func (*Table) PreviousCurrentCellX

func (c *Table) PreviousCurrentCellX() int

func (*Table) PreviousCurrentCellY

func (c *Table) PreviousCurrentCellY() int

func (*Table) ProcessKeyDown

func (c *Table) ProcessKeyDown(key Key, mods KeyModifiers) bool

func (*Table) ProcessMouseDown

func (c *Table) ProcessMouseDown(button MouseButton, x int, y int, mods KeyModifiers) bool

ProcessMouseDown selects the row (cell) under a right click before the context menu is shown, so the menu acts on what was clicked. An already selected row keeps the selection, so a menu over a multi-selection acts on all of it.

func (*Table) RowCount

func (c *Table) RowCount() int

func (*Table) RowHeight

func (c *Table) RowHeight() int

func (*Table) ScrollToCell2

func (c *Table) ScrollToCell2(row, col int)

func (*Table) SelectAll

func (c *Table) SelectAll()

SelectAll selects every row (in row-selection mode) or every cell (in cell-selection mode). No-op unless multiselect is enabled.

func (*Table) SelectedCells

func (c *Table) SelectedCells() []TableCellPos

SelectedCells returns the sorted list of currently selected cells. Meaningful when SelectingRows() is false.

func (*Table) SelectedRows

func (c *Table) SelectedRows() []int

SelectedRows returns the sorted list of currently selected row indices. Meaningful when SelectingRows() is true.

func (*Table) SelectingRows

func (c *Table) SelectingRows() bool

func (*Table) SetCellBorderColor

func (c *Table) SetCellBorderColor(col color.RGBA)

func (*Table) SetCellBorderWidth

func (c *Table) SetCellBorderWidth(width int)

func (*Table) SetCellColor

func (c *Table) SetCellColor(row int, col int, color color.Color)

func (*Table) SetCellContraction

func (c *Table) SetCellContraction(row int, col int, contraction bool)

func (*Table) SetCellData2

func (c *Table) SetCellData2(row int, col int, data interface{})

func (*Table) SetCellDisplayText

func (c *Table) SetCellDisplayText(row int, col int, text string)

func (*Table) SetCellEditTriggerDoubleClick

func (c *Table) SetCellEditTriggerDoubleClick(row int, col int, enabled bool)

func (*Table) SetCellEditTriggerEnter

func (c *Table) SetCellEditTriggerEnter(row int, col int, enabled bool)

func (*Table) SetCellEditTriggerF2

func (c *Table) SetCellEditTriggerF2(row int, col int, enabled bool)

func (*Table) SetCellEditTriggerKeyDown

func (c *Table) SetCellEditTriggerKeyDown(row int, col int, enabled bool)

func (*Table) SetCellHAlign

func (c *Table) SetCellHAlign(row int, col int, align HAlign)

func (*Table) SetCellImage

func (c *Table) SetCellImage(row int, col int, img image.Image, imgWidth int)

func (*Table) SetCellOnDraw

func (c *Table) SetCellOnDraw(row int, col int, onDraw func(cnv *Canvas))

func (*Table) SetCellPadding

func (c *Table) SetCellPadding(padding int)

SetCellPadding sets the space between the text of the cells (and of the header) and their edges

func (*Table) SetCellSelectionDisabled

func (c *Table) SetCellSelectionDisabled(row int, col int, disabled bool)

func (*Table) SetCellText2

func (c *Table) SetCellText2(row int, col int, text string)

func (*Table) SetCellVAlign

func (c *Table) SetCellVAlign(row int, col int, align VAlign)

func (*Table) SetClearSelectionOnEmptyClick

func (c *Table) SetClearSelectionOnEmptyClick(enabled bool)

SetClearSelectionOnEmptyClick controls whether a plain left click on the empty area of the table (outside any cell) clears the selection (default true).

func (*Table) SetColumnCellName2

func (c *Table) SetColumnCellName2(row int, col int, name string)

func (*Table) SetColumnCount

func (c *Table) SetColumnCount(count int)

func (*Table) SetColumnHAlign

func (c *Table) SetColumnHAlign(col int, align HAlign)

SetColumnHAlign aligns the column's header text, e.g. to the right over numbers aligned with SetCellHAlign

func (*Table) SetColumnImage

func (c *Table) SetColumnImage(col int, img image.Image, imgWidth int)

func (*Table) SetColumnName

func (c *Table) SetColumnName(col int, name string)

func (*Table) SetColumnWidth

func (c *Table) SetColumnWidth(col int, width int)

func (*Table) SetCurrentCell2

func (c *Table) SetCurrentCell2(row int, col int)

func (*Table) SetEditTriggerDoubleClick

func (c *Table) SetEditTriggerDoubleClick(enabled bool)

func (*Table) SetEditTriggerEnter

func (c *Table) SetEditTriggerEnter(enabled bool)

func (*Table) SetEditTriggerF2

func (c *Table) SetEditTriggerF2(enabled bool)

func (*Table) SetEditTriggerKeyDown

func (c *Table) SetEditTriggerKeyDown(enabled bool)

func (*Table) SetHeaderCellSpan2

func (c *Table) SetHeaderCellSpan2(row int, col int, spanRow int, spanCol int)

func (*Table) SetHeaderRowCount

func (c *Table) SetHeaderRowCount(count int)

func (*Table) SetHotTracking

func (c *Table) SetHotTracking(enabled bool)

SetHotTracking makes the current cell follow the mouse, as in a drop-down list: the cell under the mouse is lit and the mouse is a hand over it (cells with the selection disabled are skipped)

func (*Table) SetModeLoading

func (c *Table) SetModeLoading(loading bool, text string)

func (*Table) SetMultiselect

func (c *Table) SetMultiselect(enabled bool)

SetMultiselect enables or disables selecting more than one row/cell at a time (drag, Shift+click, Ctrl+click, Ctrl+A). Disabling it collapses any existing multi-selection down to the current cell/row.

func (*Table) SetOnCellChanged

func (c *Table) SetOnCellChanged(callback func(row int, col int, text string, data interface{}) bool)

func (*Table) SetOnCellMouseDblClick

func (c *Table) SetOnCellMouseDblClick(callback func())

func (*Table) SetOnCellMouseDown

func (c *Table) SetOnCellMouseDown(callback func(button MouseButton, row int, col int, x int, y int, mods KeyModifiers))

func (*Table) SetOnCellMouseUp

func (c *Table) SetOnCellMouseUp(callback func(button MouseButton, row int, col int, x int, y int, mods KeyModifiers))

SetOnCellMouseUp is called when a mouse button is released over the table; row and col are -1 outside the cells

func (*Table) SetOnColumnClick

func (c *Table) SetOnColumnClick(callback func(col int))

func (*Table) SetOnColumnResize

func (c *Table) SetOnColumnResize(callback func(col int, newWidth int))

func (*Table) SetOnSelectionChanged

func (c *Table) SetOnSelectionChanged(callback func(x int, y int))

func (*Table) SetRowCount

func (c *Table) SetRowCount(count int)

func (*Table) SetRowHeight

func (c *Table) SetRowHeight(height int)

func (*Table) SetSelectedRows

func (c *Table) SetSelectedRows(rows []int)

SetSelectedRows selects the rows (in row-selection mode), e.g. to keep a selection after the rows were reloaded; the first one becomes the current row. Rows out of range are skipped. Without multiselect only the first row is selected.

func (*Table) SetSelectingRows

func (c *Table) SetSelectingRows(selectingRows bool)

SetSelectingRows chooses the selection unit: true selects whole rows, false selects individual cells.

func (*Table) SetShowSelection

func (c *Table) SetShowSelection(show bool)

func (*Table) SetStretchLastColumn

func (c *Table) SetStretchLastColumn(stretch bool)

SetStretchLastColumn makes the last column fill the table up to its right edge, so there is no empty strip after the columns. Its width set with SetColumnWidth stays the minimum; the table doesn't scroll to show the rest.

func (*Table) ShowSelection

func (c *Table) ShowSelection() bool

func (*Table) TableSetLayoutXml

func (c *Table) TableSetLayoutXml(n *uiNode)

type TableCellPos

type TableCellPos struct {
	Row int
	Col int
}

TableCellPos identifies a single cell by row and column index.

type TextBox

type TextBox struct {
	Widget
	// contains filtered or unexported fields
}

func NewTextBox

func NewTextBox() *TextBox

func (*TextBox) AcceptsReturn

func (c *TextBox) AcceptsReturn() bool

func (*TextBox) AssemblyText

func (c *TextBox) AssemblyText(lines []string) string

func (*TextBox) CanRedo

func (c *TextBox) CanRedo() bool

func (*TextBox) CanUndo

func (c *TextBox) CanUndo() bool

func (*TextBox) ClearUndo

func (c *TextBox) ClearUndo()

ClearUndo forgets the undo history

func (*TextBox) Draw

func (c *TextBox) Draw(ctx *Canvas, width, height int)

func (*TextBox) Hint

func (c *TextBox) Hint() string

func (*TextBox) KeyChar

func (c *TextBox) KeyChar(ch rune, mods KeyModifiers)

func (*TextBox) KeyDown

func (c *TextBox) KeyDown(key Key, mods KeyModifiers) bool

func (*TextBox) KeyUp

func (c *TextBox) KeyUp(key Key, mods KeyModifiers)

func (*TextBox) Lines

func (c *TextBox) Lines() []string

func (*TextBox) MinHeight

func (c *TextBox) MinHeight() int

func (*TextBox) MouseDown

func (c *TextBox) MouseDown(button MouseButton, x int, y int, mods KeyModifiers)

func (*TextBox) MouseMove

func (c *TextBox) MouseMove(x int, y int, mods KeyModifiers)

func (*TextBox) MouseUp

func (c *TextBox) MouseUp(button MouseButton, x int, y int, mods KeyModifiers)

func (*TextBox) MoveCursorToEnd

func (c *TextBox) MoveCursorToEnd()

func (*TextBox) Multiline

func (c *TextBox) Multiline() bool

func (*TextBox) OneLineHeight

func (c *TextBox) OneLineHeight() int

func (*TextBox) ProcessPaint

func (c *TextBox) ProcessPaint(cnv *Canvas)

ProcessPaint draws the frame on the whole widget, under the text and the scroll bars: the text is drawn in the view only and the frame doesn't scroll with it

func (*TextBox) ProcessPropChange

func (c *TextBox) ProcessPropChange(key string, value interface{})

/////////////////////////////////////////////////////////////////////////////// Props

func (*TextBox) ReadOnly

func (c *TextBox) ReadOnly() bool

func (*TextBox) Redo

func (c *TextBox) Redo()

Redo makes the edit taken back by Undo again (Ctrl+Y, Ctrl+Shift+Z)

func (*TextBox) ScrollToBegin

func (c *TextBox) ScrollToBegin()

func (*TextBox) SelectAllText

func (c *TextBox) SelectAllText()

func (*TextBox) SelectRange

func (c *TextBox) SelectRange(from, to int)

SelectRange selects the runes [from, to) of the first line and puts the cursor at the end of the selection (as file managers select a name without its extension)

func (*TextBox) SelectedText

func (c *TextBox) SelectedText() string

func (*TextBox) SetHint

func (c *TextBox) SetHint(text string)

func (*TextBox) SetHintFunc

func (c *TextBox) SetHintFunc(f func() string)

SetHintFunc makes the hint come from f, now and on every language change.

func (*TextBox) SetIsPassword

func (c *TextBox) SetIsPassword(isPassword bool)

func (*TextBox) SetMultiline

func (c *TextBox) SetMultiline(multiline bool)

func (*TextBox) SetOnTextBoxKeyDown

func (c *TextBox) SetOnTextBoxKeyDown(onKeyDown func())

func (*TextBox) SetOnTextChanged

func (c *TextBox) SetOnTextChanged(onTextChanged func())

func (*TextBox) SetProp

func (c *TextBox) SetProp(key string, value any)

func (*TextBox) SetReadOnly

func (c *TextBox) SetReadOnly(readonly bool)

func (*TextBox) SetText

func (c *TextBox) SetText(text string)

func (*TextBox) Text

func (c *TextBox) Text() string

func (*TextBox) Undo

func (c *TextBox) Undo()

Undo takes back the last edit of the user (Ctrl+Z)

type TextBoxSelection

type TextBoxSelection struct {
	X1, Y1, X2, Y2 int
	Text           string
}

type TextPrintOptions

type TextPrintOptions struct {
	FontFamily string
	// FontSize in points
	FontSize float64
	// Margin on all the sides, in millimeters
	Margin float64
	// NoPageNumbers leaves out the "page / pages" line at the bottom
	NoPageNumbers bool
}

TextPrintOptions set up NewTextPrintJob; the zero values give the theme font at 10 pt, 20 mm margins and page numbers

type ThemePalette

type ThemePalette struct {
	// Window is the background of forms and panels, WindowText the text on it
	Window     color.RGBA
	WindowText color.RGBA

	// Base is the background of input fields, lists and tables, Text the
	// text in them
	Base color.RGBA
	Text color.RGBA

	// Button is the background of buttons, combo boxes and table headers
	Button     color.RGBA
	ButtonText color.RGBA

	// Border frames the controls; Divider is a softer line inside them:
	// table grid, menu separators
	Border  color.RGBA
	Divider color.RGBA

	// Highlight is the accent: focus, checked boxes, chosen items, primary
	// buttons; HighlightedText is the text on it
	Highlight       color.RGBA
	HighlightedText color.RGBA

	// Selection is the background of selected text, softer than Highlight
	// so the text keeps its own color
	Selection color.RGBA

	DisabledText    color.RGBA
	PlaceholderText color.RGBA

	// PopupBase is the background of menus and dropdowns
	PopupBase color.RGBA

	ToolTipBase color.RGBA
	ToolTipText color.RGBA

	Link    color.RGBA
	Error   color.RGBA
	Warning color.RGBA
	Success color.RGBA
}

ThemePalette is the set of colors every widget is drawn with. Each color has a role, like QPalette in Qt: widgets ask for "the background of an input field" or "the border of a control", not for a particular gray, so the light and the dark themes are just two palettes.

Hover and pressed states aren't in the palette: they are mixed from the background and the text color (see hoverColor), which works in both themes.

func CurrentPalette

func CurrentPalette() *ThemePalette

CurrentPalette returns the colors of the current theme.

type TimeChart

type TimeChart struct {
	Widget
	// contains filtered or unexported fields
}

TimeChart draws time series in one or more stacked areas.

Mouse: left drag pans horizontally, right drag to the right zooms into the dragged time range, Ctrl + right drag to the right zooms into the dragged rectangle (time and the Y range of that area). Zooms stack: each one saves the current view and right drag to the left (with or without Ctrl) goes back one level, or to the default view when there is nothing to go back to (see ZoomBack, SetDefaultTimeRange and ResetZoom). A double click also goes back one level, Esc resets the zoom and clears the stack. Shift + left drag selects a range; dragging its header moves it, dragging its edges resizes it and the close button in the header clears it. The wheel zooms time around the pointer.

func NewTimeChart

func NewTimeChart() *TimeChart

func (*TimeChart) AddArea

func (c *TimeChart) AddArea() *TimeChartArea

func (*TimeChart) Areas

func (c *TimeChart) Areas() []*TimeChartArea

func (*TimeChart) ClearSelection

func (c *TimeChart) ClearSelection()

func (*TimeChart) DefaultTimeRange

func (c *TimeChart) DefaultTimeRange() (from, to time.Time)

func (*TimeChart) IsDefaultView

func (c *TimeChart) IsDefaultView() bool

IsDefaultView reports whether the chart shows the default range and follows SetDefaultTimeRange.

func (*TimeChart) ProcessMouseUp

func (c *TimeChart) ProcessMouseUp(button MouseButton, x int, y int, mods KeyModifiers, onlyForWidgetId string) bool

ProcessMouseUp is overridden because the form routes onMouseUp only to the widget pressed with the left button; a right-button zoom must end here too. Every widget receives ProcessMouseUp, so the release is seen even when it happens outside the chart.

func (*TimeChart) RemoveAllAreas

func (c *TimeChart) RemoveAllAreas()

func (*TimeChart) ResetTimeRange

func (c *TimeChart) ResetTimeRange()

ResetTimeRange switches to the default view.

func (*TimeChart) ResetZoom

func (c *TimeChart) ResetZoom()

ResetZoom returns to the default time range, auto-scales Y in every area and clears the zoom stack.

func (*TimeChart) Selection

func (c *TimeChart) Selection() (from, to time.Time, ok bool)

func (*TimeChart) SetDefaultTimeRange

func (c *TimeChart) SetDefaultTimeRange(from, to time.Time)

SetDefaultTimeRange sets the default range. The application owns it and may call this as often as it likes (for example on every new sample of a live feed): while the chart is in the default view the new range is shown at once; after the user has panned or zoomed it is only remembered, and returning to the default view (ResetZoom, ResetTimeRange or zooming all the way back) shows the default range as it is at that moment.

func (*TimeChart) SetOnSelectionChanged

func (c *TimeChart) SetOnSelectionChanged(f func())

func (*TimeChart) SetOnTimeRangeChanged

func (c *TimeChart) SetOnTimeRangeChanged(f func())

func (*TimeChart) SetSelection

func (c *TimeChart) SetSelection(from, to time.Time)

func (*TimeChart) SetTimeRange

func (c *TimeChart) SetTimeRange(from, to time.Time)

SetTimeRange shows the given range. The chart leaves the default view until ResetTimeRange, ResetZoom or zooming back to a level that was the default view.

func (*TimeChart) TimeRange

func (c *TimeChart) TimeRange() (from, to time.Time)

func (*TimeChart) ZoomBack

func (c *TimeChart) ZoomBack()

ZoomBack restores the view saved by the last zoom-in. With an empty stack it resets to the default view.

func (*TimeChart) ZoomDepth

func (c *TimeChart) ZoomDepth() int

ZoomDepth returns how many zoom levels ZoomBack can go back.

type TimeChartAggregator

type TimeChartAggregator struct {
	// contains filtered or unexported fields
}

TimeChartAggregator merges sorted points into buckets of groupDuration one by one, the same way as TimeChartDownsample. A source with many points can feed them straight from its storage without building a slice of all of them first.

func NewTimeChartAggregator

func NewTimeChartAggregator(groupDuration time.Duration, capacity int) *TimeChartAggregator

NewTimeChartAggregator creates an aggregator; capacity is a hint for the number of result points

func (*TimeChartAggregator) Add

Add adds the next point; points must come sorted by DT

func (*TimeChartAggregator) Points

func (c *TimeChartAggregator) Points() []TimeChartPoint

Points returns the aggregated points

type TimeChartArea

type TimeChartArea struct {
	// contains filtered or unexported fields
}

TimeChartArea is one horizontal band of the chart with its own Y axis. All areas share the time axis.

func (*TimeChartArea) AddMarker

func (c *TimeChartArea) AddMarker(m TimeChartMarker)

AddMarker adds a marker to the area. Markers may be added in any order.

func (*TimeChartArea) AddSeries

func (c *TimeChartArea) AddSeries(name string, source TimeChartDataSource) *TimeChartSeries

func (*TimeChartArea) ClearMarkers

func (c *TimeChartArea) ClearMarkers()

func (*TimeChartArea) Markers

func (c *TimeChartArea) Markers() []TimeChartMarker

func (*TimeChartArea) ResetYRange

func (c *TimeChartArea) ResetYRange()

ResetYRange returns the area to auto-scaling over the visible data.

func (*TimeChartArea) Series

func (c *TimeChartArea) Series() []*TimeChartSeries

func (*TimeChartArea) SetMarkers

func (c *TimeChartArea) SetMarkers(markers []TimeChartMarker)

SetMarkers replaces all markers of the area.

func (*TimeChartArea) SetYRange

func (c *TimeChartArea) SetYRange(yMin, yMax float64)

func (*TimeChartArea) YRange

func (c *TimeChartArea) YRange() (yMin, yMax float64, ok bool)

YRange returns the manual Y range; ok is false while the area auto-scales.

type TimeChartDataSource

type TimeChartDataSource interface {
	GetData(from, to time.Time, groupDuration time.Duration) []TimeChartPoint
}

TimeChartDataSource supplies the points of a series.

GetData is called on every paint for the visible range [from, to]. groupDuration is the time covered by one screen pixel: the source should aggregate its data into buckets of that size (see TimeChartDownsample) so that no more than about one point per pixel is returned. Points must be sorted by DT. Returning the nearest point on each side outside the range lets the line continue to the edges of the plot.

A source that loads data asynchronously should return what it has now and call Form().Update() on the chart when more data arrives.

type TimeChartMarker

type TimeChartMarker struct {
	DT    time.Time
	Value float64
	Text  string
	Color color.Color
}

TimeChartMarker is a text note pinned to a point of an area: DT on the time axis and Value on the area's Y axis (for example the top of a peak). A nil Color uses the theme's marker color.

type TimeChartMemorySource

type TimeChartMemorySource struct {
	// contains filtered or unexported fields
}

TimeChartMemorySource is a TimeChartDataSource over an in-memory slice of points sorted by DT. It is safe to add points from another goroutine.

func NewTimeChartMemorySource

func NewTimeChartMemorySource() *TimeChartMemorySource

func (*TimeChartMemorySource) AddPoint

func (c *TimeChartMemorySource) AddPoint(p TimeChartPoint)

AddPoint appends a point. Its DT must not be earlier than the last one.

func (*TimeChartMemorySource) GetData

func (c *TimeChartMemorySource) GetData(from, to time.Time, groupDuration time.Duration) []TimeChartPoint

func (*TimeChartMemorySource) SetPoints

func (c *TimeChartMemorySource) SetPoints(points []TimeChartPoint)

SetPoints replaces the data. The points must be sorted by DT.

type TimeChartPoint

type TimeChartPoint struct {
	DT      time.Time
	First   float64
	Last    float64
	High    float64
	Low     float64
	HasGood bool
	HasBad  bool
}

TimeChartPoint is one sample (or one aggregated bucket) of a time series. For a raw sample all four values are equal. For a downsampled bucket First/Last are the first and last values in the bucket and High/Low are its extremes, so a signal that jitters inside a bucket is still drawn as a vertical band instead of collapsing into a flat average. The same shape is an OHLC bar, so trading charts use it directly.

HasGood and HasBad describe data quality: HasBad means the point (or some sample in the bucket) is bad - e.g. the sensor was disconnected - and HasGood means at least one sample carries a valid value. First/Last/High/ Low only describe the good samples. A point without HasGood has no value: the line breaks there. Bad spans are drawn as a light reddish hatch. A point with neither flag is a gap - no data at all, e.g. the acquisition was stopped: the line breaks without the hatch.

func NewTimeChartBad

func NewTimeChartBad(dt time.Time) TimeChartPoint

NewTimeChartBad returns a point with no value, marking bad quality at dt.

func NewTimeChartGap

func NewTimeChartGap(dt time.Time) TimeChartPoint

NewTimeChartGap returns a point that breaks the line at dt without marking bad quality - e.g. where data acquisition was stopped or started.

func NewTimeChartValue

func NewTimeChartValue(dt time.Time, value float64) TimeChartPoint

func TimeChartDownsample

func TimeChartDownsample(points []TimeChartPoint, from, to time.Time, groupDuration time.Duration) []TimeChartPoint

TimeChartDownsample returns the points of the sorted slice that fall into [from, to], plus the nearest point on each side, merged into buckets of groupDuration: First/Last of a bucket come from its first and last good point, High/Low are the extremes of the good points, HasGood is set when the bucket has any good point and HasBad when it has any bad one - so a short outage stays visible however far the chart is zoomed out. Gap points (neither flag) are never merged: each one is kept as a separate point and closes the current bucket, so a break stays visible at any zoom. Buckets are aligned to multiples of groupDuration since the Unix epoch, so panning does not change how points are grouped. It is the same aggregation a server should do before sending data to the chart.

func (TimeChartPoint) HasValue

func (p TimeChartPoint) HasValue() bool

HasValue reports whether First/Last/High/Low are meaningful.

func (TimeChartPoint) IsGap

func (p TimeChartPoint) IsGap() bool

IsGap reports whether the point marks a break in the data.

type TimeChartSeries

type TimeChartSeries struct {
	// contains filtered or unexported fields
}

func (*TimeChartSeries) Name

func (c *TimeChartSeries) Name() string

func (*TimeChartSeries) SetColor

func (c *TimeChartSeries) SetColor(col color.Color)

SetColor fixes the series color regardless of the theme.

func (*TimeChartSeries) SetPaletteColor

func (c *TimeChartSeries) SetPaletteColor(index int)

SetPaletteColor uses color number index of the chart palette, which has a dark and a light variant, so the series stays readable in both themes.

func (*TimeChartSeries) SetType

func (c *TimeChartSeries) SetType(seriesType TimeChartSeriesType)

func (*TimeChartSeries) Source

type TimeChartSeriesType

type TimeChartSeriesType int
const (
	TimeChartSeriesLine TimeChartSeriesType = iota
	TimeChartSeriesCandles
)

type TimePicker

type TimePicker struct {
	Widget
	// contains filtered or unexported fields
}

TimePicker edits a time of day, 24-hour, in segments: HH:MM or HH:MM:SS. Left/Right (or a click) choose the segment, Up/Down and the mouse wheel change it, digits type it (two digits, or one that can't start a two-digit value, move to the next segment); the arrows at the right change the segment too.

start := ui.NewTimePicker()
start.SetTime(9, 30, 0)
start.SetOnTimeChanged(func() { meeting.Start = start.Duration() })

func NewTimePicker

func NewTimePicker() *TimePicker

func (*TimePicker) Duration

func (c *TimePicker) Duration() time.Duration

Duration returns the time as the time since midnight.

func (*TimePicker) Hour

func (c *TimePicker) Hour() int

func (*TimePicker) Minute

func (c *TimePicker) Minute() int

func (*TimePicker) ProcessKeyDown

func (c *TimePicker) ProcessKeyDown(key Key, mods KeyModifiers) bool

func (*TimePicker) Second

func (c *TimePicker) Second() int

func (*TimePicker) SetDuration

func (c *TimePicker) SetDuration(d time.Duration)

SetDuration sets the time from the time since midnight.

func (*TimePicker) SetOnTimeChanged

func (c *TimePicker) SetOnTimeChanged(f func())

SetOnTimeChanged sets the function called when the user changes the time.

func (*TimePicker) SetShowSeconds

func (c *TimePicker) SetShowSeconds(show bool)

SetShowSeconds adds the seconds segment.

func (*TimePicker) SetTime

func (c *TimePicker) SetTime(hour, minute, second int)

SetTime sets the time without calling SetOnTimeChanged's function; the values are kept in their ranges.

func (*TimePicker) Text

func (c *TimePicker) Text() string

Text returns the time as shown: "09:30" or "09:30:00".

type ToastKind

type ToastKind int

ToastKind is the look of a toast: the color of its stripe

const (
	ToastInfo ToastKind = iota
	ToastSuccess
	ToastWarning
	ToastError
)

type ToggleSwitch

type ToggleSwitch struct {
	Widget
	// contains filtered or unexported fields
}

ToggleSwitch is an on/off switch with a text, for settings that apply at once: a click, Space or Enter flips it. The knob slides to its new side.

wifi := ui.NewToggleSwitch("Wi-Fi")
wifi.SetOnStateChanged(func() { network.SetWifi(wifi.Checked()) })

func NewToggleSwitch

func NewToggleSwitch(text string) *ToggleSwitch

func (*ToggleSwitch) Checked

func (c *ToggleSwitch) Checked() bool

func (*ToggleSwitch) ProcessKeyDown

func (c *ToggleSwitch) ProcessKeyDown(key Key, mods KeyModifiers) bool

func (*ToggleSwitch) SetChecked

func (c *ToggleSwitch) SetChecked(checked bool)

SetChecked sets the state without calling SetOnStateChanged's function and without the animation.

func (*ToggleSwitch) SetOnStateChanged

func (c *ToggleSwitch) SetOnStateChanged(f func())

SetOnStateChanged sets the function called when the user flips the switch.

func (*ToggleSwitch) SetText

func (c *ToggleSwitch) SetText(text string)

func (*ToggleSwitch) SetTextFunc

func (c *ToggleSwitch) SetTextFunc(f func() string)

func (*ToggleSwitch) Text

func (c *ToggleSwitch) Text() string

type ToolButton

type ToolButton struct {
	ButtonImage
	// contains filtered or unexported fields
}

ToolButton is a fixed-size image button for toolbars.

On top of ButtonImage it has:

  • a disabled state: a grayed-out copy of the image is shown and clicks are ignored;
  • a checked state for toggles: a lighter background and a bright bar along the bottom;
  • a lighter bottom edge, so the buttons stand out from the toolbar;
  • a flat look (SetFlat): just the image, without the box.

func NewToolButton

func NewToolButton(img image.Image, tooltip string, onClick func()) *ToolButton

NewToolButton creates a ToolButtonDefaultSize square button with the image (drawn centered, as is) and the tooltip. onClick may be nil.

func (*ToolButton) IsChecked

func (c *ToolButton) IsChecked() bool

func (*ToolButton) IsFlat

func (c *ToolButton) IsFlat() bool

func (*ToolButton) SetButtonSize

func (c *ToolButton) SetButtonSize(width, height int)

SetButtonSize fixes the size of the button, e.g. to make the main action wider

func (*ToolButton) SetChecked

func (c *ToolButton) SetChecked(checked bool)

SetChecked shows the button as toggled on: a lighter background and a bar along the bottom edge. The button does not toggle itself on click.

func (*ToolButton) SetEnabled

func (c *ToolButton) SetEnabled(enabled bool)

func (*ToolButton) SetFlat

func (c *ToolButton) SetFlat(flat bool)

SetFlat draws the button without its box: just the image, on a soft rounded background while the mouse is over it, it is pressed or checked. A row of flat buttons makes a light toolbar.

func (*ToolButton) SetHighlight

func (c *ToolButton) SetHighlight(col color.Color)

SetHighlight draws the bottom bar in the color to draw attention to the button, e.g. the action to start with. nil returns the usual look.

func (*ToolButton) SetImage

func (c *ToolButton) SetImage(img image.Image)

SetImage sets the image; the disabled look is derived from it

func (*ToolButton) SetOnClick

func (c *ToolButton) SetOnClick(onClick func())

SetOnClick sets the function called when the enabled button is clicked

type TrayIcon

type TrayIcon struct {
	// contains filtered or unexported fields
}

TrayIcon is an icon in the system tray: the notification area on Windows and Linux, the menu bar on macOS. It has a tooltip, a menu (a right click; on macOS any click) and a left-click action, and can show system notifications. Its callbacks run on the UI thread, like all the handlers; the application must be running a form's Exec.

tray, err := ui.NewTrayIcon()
if err == nil {
	tray.SetIcon(icon)
	tray.SetTooltip("My app")
	tray.SetOnClick(func() { form.Show() })
	tray.SetMenu(
		ui.TrayMenuItem{Text: "Open", OnClick: func() { form.Show() }},
		ui.TrayMenuItem{Separator: true},
		ui.TrayMenuItem{Text: "Quit", OnClick: func() { form.Close() }},
	)
}

To keep the application in the tray when its window is closed, hide the form instead: form.OnClose = func() bool { form.Hide(); return false }

func NewTrayIcon

func NewTrayIcon() (*TrayIcon, error)

NewTrayIcon puts an icon in the system tray. Set its image with SetIcon: until then, it shows the application icon (see SetAppIcon) if there is one.

func (*TrayIcon) Close

func (t *TrayIcon) Close()

Close removes the icon from the tray

func (*TrayIcon) SetIcon

func (t *TrayIcon) SetIcon(img image.Image)

SetIcon sets the image; a square one of 32x32 or 64x64 pixels looks best

func (*TrayIcon) SetMenu

func (t *TrayIcon) SetMenu(items ...TrayMenuItem)

SetMenu sets the menu of the icon; call it again to change the items, e.g. the state of a checkable one

func (*TrayIcon) SetOnClick

func (t *TrayIcon) SetOnClick(f func())

SetOnClick sets the function called on a left click on the icon (on macOS, only when the icon has no menu)

func (*TrayIcon) SetTooltip

func (t *TrayIcon) SetTooltip(text string)

func (*TrayIcon) ShowNotification

func (t *TrayIcon) ShowNotification(title, text string) error

ShowNotification shows a system notification (a balloon on Windows, a desktop notification on Linux)

type TrayMenuItem

type TrayMenuItem = platforms.TrayMenuItem

TrayMenuItem is an item of the tray icon's menu: a text with OnClick, a Separator, a Checkable item, or a submenu (Items).

type TreeNode

type TreeNode struct {
	// contains filtered or unexported fields
}

TreeNode is a row of a TreeView: texts per column, an icon, children.

func (*TreeNode) AddChild

func (n *TreeNode) AddChild(text string) *TreeNode

AddChild adds a child with the text in the first column.

func (*TreeNode) ChildCount

func (n *TreeNode) ChildCount() int

func (*TreeNode) Children

func (n *TreeNode) Children() []*TreeNode

func (*TreeNode) Collapse

func (n *TreeNode) Collapse()

Collapse hides the children.

func (*TreeNode) Data

func (n *TreeNode) Data() any

Data returns the value attached to the node with SetData.

func (*TreeNode) Expand

func (n *TreeNode) Expand()

Expand shows the children, calling the tree's SetOnExpand function first.

func (*TreeNode) ExpandAll

func (n *TreeNode) ExpandAll()

ExpandAll expands the node (loading its children, see TreeView.SetOnExpand) and the nodes below it that have children; nodes below whose children aren't loaded yet stay collapsed.

func (*TreeNode) HasChildren

func (n *TreeNode) HasChildren() bool

HasChildren reports whether the node has children or is marked with SetHasChildren.

func (*TreeNode) Image

func (n *TreeNode) Image() image.Image

func (*TreeNode) Index

func (n *TreeNode) Index() int

Index returns the position of the node among its siblings.

func (*TreeNode) InsertChild

func (n *TreeNode) InsertChild(index int, text string) *TreeNode

InsertChild adds a child at the index among the children.

func (*TreeNode) IsExpanded

func (n *TreeNode) IsExpanded() bool

func (*TreeNode) IsReadOnly

func (n *TreeNode) IsReadOnly(col int) bool

func (*TreeNode) Level

func (n *TreeNode) Level() int

Level is 0 for a top-level node, 1 for its children and so on.

func (*TreeNode) Parent

func (n *TreeNode) Parent() *TreeNode

func (*TreeNode) Remove

func (n *TreeNode) Remove()

Remove removes the node with its children from the tree.

func (*TreeNode) RemoveChildren

func (n *TreeNode) RemoveChildren()

RemoveChildren removes all the children.

func (*TreeNode) SetColor

func (n *TreeNode) SetColor(col color.Color)

SetColor sets the color of the node's texts; nil returns to the default.

func (*TreeNode) SetData

func (n *TreeNode) SetData(data any)

func (*TreeNode) SetExpanded

func (n *TreeNode) SetExpanded(expanded bool)

SetExpanded expands or collapses the node.

func (*TreeNode) SetHasChildren

func (n *TreeNode) SetHasChildren(hasChildren bool)

SetHasChildren shows the expand arrow before the children are added, for children loaded in TreeView.SetOnExpand.

func (*TreeNode) SetImage

func (n *TreeNode) SetImage(img image.Image) *TreeNode

SetImage sets the icon shown before the text; a larger image is scaled down to TreeViewIconSize. nil removes it. Returns the node for chaining.

func (*TreeNode) SetReadOnly

func (n *TreeNode) SetReadOnly(col int, readOnly bool)

SetReadOnly excludes the node's cell in the column from editing.

func (*TreeNode) SetText

func (n *TreeNode) SetText(col int, text string)

func (*TreeNode) SetTextFunc

func (n *TreeNode) SetTextFunc(col int, f func() string)

SetTextFunc makes the column's text come from f, now and on every language change.

func (*TreeNode) Text

func (n *TreeNode) Text(col int) string

func (*TreeNode) Toggle

func (n *TreeNode) Toggle()

Toggle expands a collapsed node and collapses an expanded one.

func (*TreeNode) Tree

func (n *TreeNode) Tree() *TreeView

Tree returns the tree view the node is in, nil after it was removed.

type TreeView

type TreeView struct {
	Widget
	// contains filtered or unexported fields
}

TreeView shows a hierarchy of nodes in rows, with columns: the first column holds the tree (indentation, expand arrow, icon, text), the other columns hold more texts of the node - like a file manager's detail view.

tree := ui.NewTreeView()
tree.SetColumnCount(2)
tree.SetColumnName(0, "Name")
tree.SetColumnName(1, "Size")
docs := tree.AddNode(nil, "Documents")
docs.AddChild("report.txt").SetText(1, "12 KB")
docs.Expand()

Selection, keyboard navigation and editing work like in Table: see SetMultiselect, SetEditTriggerF2 and SetOnCellChanged.

func NewTreeView

func NewTreeView() *TreeView

func (*TreeView) AddNode

func (c *TreeView) AddNode(parent *TreeNode, text string) *TreeNode

AddNode adds a node with the text in the first column at the end of parent's children, or of the top-level nodes when parent is nil.

func (*TreeView) CancelEdit

func (c *TreeView) CancelEdit()

CancelEdit closes the editor keeping the cell's text.

func (*TreeView) Clear

func (c *TreeView) Clear()

Clear removes all the nodes.

func (*TreeView) CollapseAll

func (c *TreeView) CollapseAll()

CollapseAll collapses every node.

func (*TreeView) ColumnCount

func (c *TreeView) ColumnCount() int

func (*TreeView) ColumnName

func (c *TreeView) ColumnName(col int) string

func (*TreeView) ColumnWidth

func (c *TreeView) ColumnWidth(col int) int

ColumnWidth returns the width set for the column; the last column may be shown wider, see SetStretchLastColumn.

func (*TreeView) CommitEdit

func (c *TreeView) CommitEdit()

CommitEdit applies the editor's text (unless SetOnCellChanged rejects it) and closes the editor.

func (*TreeView) CopySelectionToClipboard

func (c *TreeView) CopySelectionToClipboard()

CopySelectionToClipboard copies the selected nodes, one per line, their columns separated by tabs (Ctrl+C).

func (*TreeView) CurrentColumn

func (c *TreeView) CurrentColumn() int

CurrentColumn returns the column that editing starts in: the one clicked last, or moved to with Ctrl+Left/Right.

func (*TreeView) CurrentNode

func (c *TreeView) CurrentNode() *TreeNode

CurrentNode returns the node with the keyboard focus, nil if none.

func (*TreeView) EditCell

func (c *TreeView) EditCell(node *TreeNode, col int, enteredText string)

EditCell opens the editor on the cell, see EditCurrentCell. Does nothing for a cell that isn't editable (IsCellEditable).

func (*TreeView) EditCurrentCell

func (c *TreeView) EditCurrentCell(enteredText string)

EditCurrentCell opens the editor on the current node's current column. With enteredText empty the editor starts from the cell's text, all selected; otherwise it starts from enteredText.

func (*TreeView) ExpandAll

func (c *TreeView) ExpandAll()

ExpandAll expands every node that has children. Nodes whose children aren't loaded yet (SetHasChildren) stay collapsed: loading them could never end, e.g. for a tree of folders.

func (*TreeView) HeaderVisible

func (c *TreeView) HeaderVisible() bool

func (*TreeView) Indent

func (c *TreeView) Indent() int

func (*TreeView) InnerHeight

func (c *TreeView) InnerHeight() int

func (*TreeView) InsertNode

func (c *TreeView) InsertNode(parent *TreeNode, index int, text string) *TreeNode

InsertNode adds a node at the index among parent's children (the top-level nodes when parent is nil).

func (*TreeView) IsCellEditable

func (c *TreeView) IsCellEditable(node *TreeNode, col int) bool

IsCellEditable reports whether the cell can be edited: its column and node aren't read-only.

func (*TreeView) IsEditing

func (c *TreeView) IsEditing() bool

IsEditing reports whether the inline editor is open.

func (*TreeView) IsNodeSelected

func (c *TreeView) IsNodeSelected(node *TreeNode) bool

func (*TreeView) Multiselect

func (c *TreeView) Multiselect() bool

func (*TreeView) Nodes

func (c *TreeView) Nodes() []*TreeNode

Nodes returns the top-level nodes.

func (*TreeView) ProcessKeyDown

func (c *TreeView) ProcessKeyDown(key Key, mods KeyModifiers) bool

func (*TreeView) ProcessMouseDown

func (c *TreeView) ProcessMouseDown(button MouseButton, x int, y int, mods KeyModifiers) bool

ProcessMouseDown handles the right click before a context menu opens, so the menu acts on the node under the mouse.

func (*TreeView) ProcessMouseWheel

func (c *TreeView) ProcessMouseWheel(deltaX, deltaY int) bool

func (*TreeView) ProcessPaint

func (c *TreeView) ProcessPaint(cnv *Canvas)

ProcessPaint brings the rows up to date before the content and the scroll bars are drawn.

func (*TreeView) RemoveNode

func (c *TreeView) RemoveNode(node *TreeNode)

RemoveNode removes the node with all its children.

func (*TreeView) RowHeight

func (c *TreeView) RowHeight() int

func (*TreeView) ScrollToNode

func (c *TreeView) ScrollToNode(node *TreeNode)

ScrollToNode expands the node's parents and scrolls the node into view.

func (*TreeView) SelectAll

func (c *TreeView) SelectAll()

SelectAll selects all the shown nodes; only with multiselect.

func (*TreeView) SelectedNodes

func (c *TreeView) SelectedNodes() []*TreeNode

SelectedNodes returns the selected nodes, top to bottom.

func (*TreeView) SetColumnCount

func (c *TreeView) SetColumnCount(count int)

func (*TreeView) SetColumnName

func (c *TreeView) SetColumnName(col int, name string)

SetColumnName sets the header text of the column.

func (*TreeView) SetColumnNameFunc

func (c *TreeView) SetColumnNameFunc(col int, f func() string)

SetColumnNameFunc makes the header text come from f, now and on every language change.

func (*TreeView) SetColumnReadOnly

func (c *TreeView) SetColumnReadOnly(col int, readOnly bool)

SetColumnReadOnly excludes the column from editing, whatever the edit triggers are; see also TreeNode.SetReadOnly.

func (*TreeView) SetColumnWidth

func (c *TreeView) SetColumnWidth(col int, width int)

func (*TreeView) SetCurrentColumn

func (c *TreeView) SetCurrentColumn(col int)

SetCurrentColumn sets the column editing starts in.

func (*TreeView) SetCurrentNode

func (c *TreeView) SetCurrentNode(node *TreeNode)

SetCurrentNode makes the node current and the only selected one, expanding its parents and scrolling it into view. nil clears the selection.

func (*TreeView) SetEditTriggerDoubleClick

func (c *TreeView) SetEditTriggerDoubleClick(enabled bool)

func (*TreeView) SetEditTriggerEnter

func (c *TreeView) SetEditTriggerEnter(enabled bool)

func (*TreeView) SetEditTriggerF2

func (c *TreeView) SetEditTriggerF2(enabled bool)

func (*TreeView) SetEditTriggerKeyDown

func (c *TreeView) SetEditTriggerKeyDown(enabled bool)

SetEditTriggerKeyDown starts editing when a letter is typed, replacing the text; without it typing jumps to the next node starting with the typed letters.

func (*TreeView) SetGridLines

func (c *TreeView) SetGridLines(gridLines bool)

SetGridLines draws lines between the rows and columns.

func (*TreeView) SetHeaderVisible

func (c *TreeView) SetHeaderVisible(visible bool)

SetHeaderVisible shows or hides the row of column names.

func (*TreeView) SetIndent

func (c *TreeView) SetIndent(indent int)

SetIndent sets how far each level is shifted to the right; 0 (the default) follows the row height.

func (*TreeView) SetMultiselect

func (c *TreeView) SetMultiselect(enabled bool)

SetMultiselect allows selecting several nodes: Shift+click and Shift+arrows select a range, Ctrl+click and Ctrl+Space toggle a node, Ctrl+A selects all shown nodes. Turning it off keeps only the current node.

func (*TreeView) SetOnCellChanged

func (c *TreeView) SetOnCellChanged(f func(node *TreeNode, col int, text string) bool)

SetOnCellChanged sets the function called when an edit is committed, with the new text; returning false rejects it.

func (*TreeView) SetOnCollapse

func (c *TreeView) SetOnCollapse(f func(node *TreeNode))

SetOnCollapse sets the function called after a node collapses.

func (*TreeView) SetOnColumnClick

func (c *TreeView) SetOnColumnClick(callback func(col int))

func (*TreeView) SetOnColumnResize

func (c *TreeView) SetOnColumnResize(callback func(col int, newWidth int))

func (*TreeView) SetOnExpand

func (c *TreeView) SetOnExpand(f func(node *TreeNode))

SetOnExpand sets the function called before a node expands. Children can be added there, e.g. to load a folder only when it's opened; mark such nodes with SetHasChildren so they show the expand arrow.

func (*TreeView) SetOnNodeActivated

func (c *TreeView) SetOnNodeActivated(f func(node *TreeNode))

SetOnNodeActivated sets the function called on a double click on a node or Enter, when they don't start editing.

func (*TreeView) SetOnSelectionChanged

func (c *TreeView) SetOnSelectionChanged(f func(node *TreeNode))

SetOnSelectionChanged sets the function called when the current node or the set of selected nodes changes.

func (*TreeView) SetRowHeight

func (c *TreeView) SetRowHeight(height int)

func (*TreeView) SetScrollX

func (c *TreeView) SetScrollX(scrollX int)

func (*TreeView) SetScrollY

func (c *TreeView) SetScrollY(scrollY int)

func (*TreeView) SetSelectedNodes

func (c *TreeView) SetSelectedNodes(nodes []*TreeNode)

SetSelectedNodes selects the nodes (all of them with multiselect, else the first); the first one becomes current.

func (*TreeView) SetSize

func (c *TreeView) SetSize(w, h int)

SetSize also stretches the last column to the new width.

func (*TreeView) SetStretchLastColumn

func (c *TreeView) SetStretchLastColumn(stretch bool)

SetStretchLastColumn makes the last column fill the width left by the other columns (the default).

type UIStrings

type UIStrings struct {
	OK     string
	Cancel string
	Yes    string
	No     string

	// Calendar, DatePicker
	Today string
	// MonthNames in the nominative case: January...December
	MonthNames [12]string
	// WeekdaysShort are two- or three-letter names, Sunday first (as time.Weekday)
	WeekdaysShort [7]string

	// The print dialog (Form.Print on Linux and macOS)
	Print, Printer, Copies, Pages, PagesHint, Paper string
	Portrait, Landscape, SaveAsPDF                  string
}

UIStrings are the texts of the library's own widgets, e.g. the buttons of message boxes. English, Russian and Chinese are built in; an application adds other languages with RegisterUIStrings.

func UIText

func UIText() *UIStrings

UIText returns the library's texts in the language of the application.

type VAlign

type VAlign int
const VAlignBottom VAlign = 2
const VAlignCenter VAlign = 1
const VAlignTop VAlign = 0

func (*VAlign) String

func (c *VAlign) String() string

type VSpacer

type VSpacer struct {
	Widget
}

func NewVSpacer

func NewVSpacer() *VSpacer

type Widget

type Widget struct {
	PopupWidgets []Widgeter
	// contains filtered or unexported fields
}

func (*Widget) AddButton

func (c *Widget) AddButton(row int, col int, text string, onPush func()) *Button

func (*Widget) AddHSpacer

func (c *Widget) AddHSpacer(row int, col int) *HSpacer

func (*Widget) AddLabel

func (c *Widget) AddLabel(row int, col int, text string) *Label

func (*Widget) AddPanel

func (c *Widget) AddPanel(row int, col int) *Panel

func (*Widget) AddTimer

func (c *Widget) AddTimer(intervalMs int, callback func())

func (*Widget) AddVSpacer

func (c *Widget) AddVSpacer(row int, col int) *VSpacer

func (*Widget) AddWidget

func (c *Widget) AddWidget(gridRow int, gridColumn int, w Widgeter)

func (*Widget) AllChildren

func (c *Widget) AllChildren() []Widgeter

func (*Widget) AppendPopupWidget

func (c *Widget) AppendPopupWidget(w Widgeter)

func (*Widget) BackgroundColor

func (c *Widget) BackgroundColor() color.Color

func (*Widget) BackgroundColorForRole

func (c *Widget) BackgroundColorForRole(role string) color.Color

func (*Widget) BackgroundColorWithAddElevation

func (c *Widget) BackgroundColorWithAddElevation(elevation int) color.Color

func (*Widget) ClearFocus

func (c *Widget) ClearFocus()

func (*Widget) ClearLayoutCache

func (c *Widget) ClearLayoutCache()

func (*Widget) CloseAfterPopupWidget

func (c *Widget) CloseAfterPopupWidget(w Widgeter)

func (*Widget) CloseAllPopup

func (c *Widget) CloseAllPopup()

func (*Widget) CloseByClickOutside

func (c *Widget) CloseByClickOutside() bool

func (*Widget) CloseTopPopup

func (c *Widget) CloseTopPopup()

func (*Widget) ContextMenu

func (c *Widget) ContextMenu() *ContextMenu

func (*Widget) CurrentElevation

func (c *Widget) CurrentElevation() int

func (*Widget) Elevation

func (c *Widget) Elevation() int

func (*Widget) Enabled

func (c *Widget) Enabled() bool

func (*Widget) FindWidgetByName

func (c *Widget) FindWidgetByName(name string) Widgeter

func (*Widget) Focus

func (c *Widget) Focus()

func (*Widget) FontFamily

func (c *Widget) FontFamily() string

func (*Widget) FontSize

func (c *Widget) FontSize() float64

func (*Widget) ForegroundColor

func (c *Widget) ForegroundColor() color.Color

func (*Widget) ForegroundColorDisabled

func (c *Widget) ForegroundColorDisabled() color.Color

func (*Widget) Form

func (c *Widget) Form() *Form

func (*Widget) FullPath

func (c *Widget) FullPath() []string

func (*Widget) GetHAlign

func (c *Widget) GetHAlign(key string, defaultValue HAlign) HAlign

func (*Widget) GetProp

func (c *Widget) GetProp(key string) any

func (*Widget) GetPropBool

func (c *Widget) GetPropBool(key string, defaultValue bool) bool

func (*Widget) GetPropColor

func (c *Widget) GetPropColor(key string, defaultValue string) color.Color

func (*Widget) GetPropFloat64

func (c *Widget) GetPropFloat64(key string, defaultValue float64) float64

func (*Widget) GetPropFunction

func (c *Widget) GetPropFunction(key string) func()

func (*Widget) GetPropInt

func (c *Widget) GetPropInt(key string, defaultValue int) int

func (*Widget) GetPropString

func (c *Widget) GetPropString(key string, defaultValue string) string

func (*Widget) GetVAlign

func (c *Widget) GetVAlign(key string, defaultValue VAlign) VAlign

func (*Widget) GridX

func (c *Widget) GridX() int

func (*Widget) GridY

func (c *Widget) GridY() int

func (*Widget) Height

func (c *Widget) Height() int

func (*Widget) Id

func (c *Widget) Id() string

func (*Widget) InitWidget

func (c *Widget) InitWidget()

func (*Widget) InnerHeight

func (c *Widget) InnerHeight() int

func (*Widget) InnerWidth

func (c *Widget) InnerWidth() int

func (*Widget) IsCanBeFocused

func (c *Widget) IsCanBeFocused() bool

func (*Widget) IsFocused

func (c *Widget) IsFocused() bool

func (*Widget) IsHovered

func (c *Widget) IsHovered() bool

func (*Widget) IsRolePrimary

func (c *Widget) IsRolePrimary() bool

func (*Widget) IsRoleSecondary

func (c *Widget) IsRoleSecondary() bool

func (*Widget) IsRoleSurface

func (c *Widget) IsRoleSurface() bool

func (*Widget) IsVisible

func (c *Widget) IsVisible() bool

func (*Widget) MaxHeight

func (c *Widget) MaxHeight() int

func (*Widget) MaxWidth

func (c *Widget) MaxWidth() int

func (*Widget) MinHeight

func (c *Widget) MinHeight() int

func (*Widget) MinWidth

func (c *Widget) MinWidth() int

func (*Widget) MouseCursor

func (c *Widget) MouseCursor() MouseCursor

func (*Widget) Name

func (c *Widget) Name() string

func (*Widget) NextGridColumn

func (c *Widget) NextGridColumn() int

func (*Widget) NextGridRow

func (c *Widget) NextGridRow() int

func (*Widget) ParentWidget

func (c *Widget) ParentWidget() Widgeter

func (*Widget) ParentWidgetId

func (c *Widget) ParentWidgetId() string

func (*Widget) ProcessChar

func (c *Widget) ProcessChar(char rune, mods KeyModifiers) bool

func (*Widget) ProcessClosePopup

func (c *Widget) ProcessClosePopup()

func (*Widget) ProcessFocusLost

func (c *Widget) ProcessFocusLost()

func (*Widget) ProcessFocused

func (c *Widget) ProcessFocused()

func (*Widget) ProcessKeyDown

func (c *Widget) ProcessKeyDown(key Key, mods KeyModifiers) bool

func (*Widget) ProcessKeyUp

func (c *Widget) ProcessKeyUp(key Key, mods KeyModifiers) bool

func (*Widget) ProcessMouseDblClick

func (c *Widget) ProcessMouseDblClick(button MouseButton, x int, y int, mods KeyModifiers) bool

func (*Widget) ProcessMouseDown

func (c *Widget) ProcessMouseDown(button MouseButton, x int, y int, mods KeyModifiers) bool

func (*Widget) ProcessMouseEnter

func (c *Widget) ProcessMouseEnter() bool

func (*Widget) ProcessMouseLeave

func (c *Widget) ProcessMouseLeave() bool

func (*Widget) ProcessMouseMove

func (c *Widget) ProcessMouseMove(x int, y int, mods KeyModifiers) bool

func (*Widget) ProcessMouseUp

func (c *Widget) ProcessMouseUp(button MouseButton, x int, y int, mods KeyModifiers, onlyForWidgetId string) bool

func (*Widget) ProcessMouseWheel

func (c *Widget) ProcessMouseWheel(deltaX, deltaY int) bool

func (*Widget) ProcessPaint

func (c *Widget) ProcessPaint(cnv *Canvas)

func (*Widget) ProcessPropChange

func (c *Widget) ProcessPropChange(key string, value interface{})

func (*Widget) ProcessTimer

func (c *Widget) ProcessTimer()

func (*Widget) RectClientAreaOnWindow

func (c *Widget) RectClientAreaOnWindow() (x, y int)

func (*Widget) RemoveAllWidgets

func (c *Widget) RemoveAllWidgets()

func (*Widget) RemoveWidget

func (c *Widget) RemoveWidget(w Widgeter)

func (*Widget) Role

func (c *Widget) Role() string

func (*Widget) ScrollEnsureVisible

func (c *Widget) ScrollEnsureVisible(x1, y1 int)

ScrollEnsureVisible scrolls the content so the point (x1, y1) of it is in the view

func (*Widget) ScrollX

func (c *Widget) ScrollX() int

func (*Widget) ScrollY

func (c *Widget) ScrollY() int

func (*Widget) SetAbsolutePositioning

func (c *Widget) SetAbsolutePositioning(absolute bool)

func (*Widget) SetAllowScroll

func (c *Widget) SetAllowScroll(allowX bool, allowY bool)

func (*Widget) SetAnchors

func (c *Widget) SetAnchors(left, top, right, bottom bool)

func (*Widget) SetAutoFillBackground

func (c *Widget) SetAutoFillBackground(autoFill bool)

func (*Widget) SetBackgroundColor

func (c *Widget) SetBackgroundColor(col color.Color)

func (*Widget) SetCanBeFocused

func (c *Widget) SetCanBeFocused(canBeFocused bool)

func (*Widget) SetCellPadding

func (c *Widget) SetCellPadding(padding int)

func (*Widget) SetCloseByClickOutside

func (c *Widget) SetCloseByClickOutside(close bool)

func (*Widget) SetContextMenu

func (c *Widget) SetContextMenu(menu *ContextMenu)

func (*Widget) SetDragSource

func (c *Widget) SetDragSource(f func(x, y int) *DragData)

SetDragSource makes the widget a place to drag data from. When the user presses the left button on it and moves the mouse, f is called with the point the drag started at, in the widget's coordinates; it returns what is dragged, or nil for no drag there (e.g. outside the selected rows).

func (*Widget) SetDropTarget

func (c *Widget) SetDropTarget(accept func(data *DragData, x, y int) bool, drop func(data *DragData, x, y int))

SetDropTarget makes the widget a place to drop data on. While data is dragged over the widget, accept tells whether it can be dropped at (x, y), in the widget's coordinates; the widget is highlighted when it can. drop is called when the data is dropped there. A nil accept accepts everything. Files dragged from the system come to drop targets too (DragData.Files).

func (*Widget) SetElevation

func (c *Widget) SetElevation(elevation int)

func (*Widget) SetEnabled

func (c *Widget) SetEnabled(enabled bool)

func (*Widget) SetFontFamily

func (c *Widget) SetFontFamily(family string)

SetFontFamily sets the font of the widget, e.g. FontFamilyMono; an empty family returns the theme font.

func (*Widget) SetFontSize

func (c *Widget) SetFontSize(fontSize float64)

func (*Widget) SetForegroundColor

func (c *Widget) SetForegroundColor(col color.Color)

func (*Widget) SetGridPosition

func (c *Widget) SetGridPosition(row, column int)

func (*Widget) SetInnerSize

func (c *Widget) SetInnerSize(width, height int)

func (*Widget) SetLayout

func (c *Widget) SetLayout(layoutAsXml string, eventProcessor interface{}, widgets map[string]Widgeter) error

func (*Widget) SetMaxHeight

func (c *Widget) SetMaxHeight(maxHeight int)

func (*Widget) SetMaxSize

func (c *Widget) SetMaxSize(maxWidth, maxHeight int)

func (*Widget) SetMaxWidth

func (c *Widget) SetMaxWidth(maxWidth int)

func (*Widget) SetMinHeight

func (c *Widget) SetMinHeight(minHeight int)

func (*Widget) SetMinSize

func (c *Widget) SetMinSize(minWidth, minHeight int)

func (*Widget) SetMinWidth

func (c *Widget) SetMinWidth(minWidth int)

func (*Widget) SetMouseCursor

func (c *Widget) SetMouseCursor(cursor MouseCursor)

func (*Widget) SetName

func (c *Widget) SetName(name string)

func (*Widget) SetOnChar

func (c *Widget) SetOnChar(f func(char rune, mods KeyModifiers) bool)

func (*Widget) SetOnClick

func (c *Widget) SetOnClick(f func())

func (*Widget) SetOnFocusLost

func (c *Widget) SetOnFocusLost(onFocusLost func())

func (*Widget) SetOnFocused

func (c *Widget) SetOnFocused(onFocused func())

func (*Widget) SetOnKeyDown

func (c *Widget) SetOnKeyDown(f func(key Key, mods KeyModifiers) bool)

func (*Widget) SetOnKeyUp

func (c *Widget) SetOnKeyUp(f func(key Key, mods KeyModifiers) bool)

func (*Widget) SetOnMouseDblClick

func (c *Widget) SetOnMouseDblClick(f func(button MouseButton, x int, y int, mods KeyModifiers) bool)

func (*Widget) SetOnMouseDown

func (c *Widget) SetOnMouseDown(f func(button MouseButton, x int, y int, mods KeyModifiers) bool)

func (*Widget) SetOnMouseEnter

func (c *Widget) SetOnMouseEnter(f func())

func (*Widget) SetOnMouseLeave

func (c *Widget) SetOnMouseLeave(f func())

func (*Widget) SetOnMouseMove

func (c *Widget) SetOnMouseMove(f func(x int, y int, mods KeyModifiers) bool)

func (*Widget) SetOnMouseUp

func (c *Widget) SetOnMouseUp(f func(button MouseButton, x int, y int, mods KeyModifiers) bool)

func (*Widget) SetOnMouseWheel

func (c *Widget) SetOnMouseWheel(f func(deltaX, deltaY int) bool)

func (*Widget) SetOnPaint

func (c *Widget) SetOnPaint(f func(cnv *Canvas))

func (*Widget) SetOnPostPaint

func (c *Widget) SetOnPostPaint(f func(cnv *Canvas))

func (*Widget) SetOnScrollChanged

func (c *Widget) SetOnScrollChanged(f func(scrollX, scrollY int))

func (*Widget) SetPanelPadding

func (c *Widget) SetPanelPadding(padding int)

func (*Widget) SetParentWidgetId

func (c *Widget) SetParentWidgetId(id string)

func (*Widget) SetPosition

func (c *Widget) SetPosition(x, y int)

func (*Widget) SetProp

func (c *Widget) SetProp(key string, value any)

func (*Widget) SetPropFunction

func (c *Widget) SetPropFunction(key string, f func())

func (*Widget) SetRole

func (c *Widget) SetRole(role string)

func (*Widget) SetScrollX

func (c *Widget) SetScrollX(scrollX int)

SetScrollX scrolls the content horizontally to scrollX, kept within the content

func (*Widget) SetScrollY

func (c *Widget) SetScrollY(scrollY int)

SetScrollY scrolls the content vertically to scrollY, kept within the content

func (*Widget) SetSize

func (c *Widget) SetSize(w, h int)

func (*Widget) SetTooltip

func (c *Widget) SetTooltip(text string)

SetTooltip sets the text shown when the mouse rests on the widget. An empty string disables the tooltip.

func (*Widget) SetTooltipFunc

func (c *Widget) SetTooltipFunc(f func() string)

SetTooltipFunc makes the tooltip come from f, now and on every language change.

func (*Widget) SetTypeName

func (c *Widget) SetTypeName(typeName string)

func (*Widget) SetVisible

func (c *Widget) SetVisible(visible bool)

func (*Widget) SetXExpandable

func (c *Widget) SetXExpandable(expandable bool)

func (*Widget) SetYExpandable

func (c *Widget) SetYExpandable(expandable bool)

func (*Widget) ShowDialog

func (c *Widget) ShowDialog(centralWidget Widgeter)

func (*Widget) Tooltip

func (c *Widget) Tooltip() string

func (*Widget) TypeName

func (c *Widget) TypeName() string

func (*Widget) ViewportHeight

func (c *Widget) ViewportHeight() int

ViewportHeight is the height of the visible content area: the widget's height without the horizontal scroll bar

func (*Widget) ViewportWidth

func (c *Widget) ViewportWidth() int

ViewportWidth is the width of the visible content area: the widget's width without the vertical scroll bar

func (*Widget) Widgets

func (c *Widget) Widgets() []Widgeter

func (*Widget) Width

func (c *Widget) Width() int

func (*Widget) X

func (c *Widget) X() int

func (*Widget) XExpandable

func (c *Widget) XExpandable() bool

func (*Widget) Y

func (c *Widget) Y() int

func (*Widget) YExpandable

func (c *Widget) YExpandable() bool

type Widgeter

type Widgeter interface {
	Id() string
	ParentWidgetId() string
	SetParentWidgetId(id string)

	FullPath() []string
	TypeName() string
	Name() string
	X() int
	Y() int
	Width() int
	Height() int
	InnerWidth() int
	InnerHeight() int
	Form() *Form

	SetProp(key string, value interface{})
	SetPropFunction(key string, f func())
	GetProp(key string) interface{}
	GetPropString(key string, defaultValue string) string
	GetPropInt(key string, defaultValue int) int
	GetPropBool(key string, defaultValue bool) bool
	GetPropFloat64(key string, defaultValue float64) float64

	SetCloseByClickOutside(close bool)
	CloseByClickOutside() bool

	Widgets() []Widgeter

	Elevation() int

	SetRole(role string)
	Role() string

	FindWidgetByName(name string) Widgeter

	Enabled() bool
	SetEnabled(enabled bool)

	AddTimer(duration int, callback func())

	SetName(name string)
	SetPosition(x, y int)
	SetSize(width, height int)

	Focus()
	ClearFocus()

	ProcessPaint(cnv *Canvas)
	ProcessMouseDown(button MouseButton, x int, y int, mods KeyModifiers) bool
	ProcessMouseUp(button MouseButton, x int, y int, mods KeyModifiers, onlyForWidgetId string) bool
	ProcessMouseMove(x int, y int, mods KeyModifiers) bool
	ProcessMouseLeave() bool
	ProcessMouseEnter() bool
	ProcessKeyDown(keyCode Key, mods KeyModifiers) bool
	ProcessKeyUp(keyCode Key, mods KeyModifiers) bool
	ProcessMouseDblClick(button MouseButton, x int, y int, mods KeyModifiers) bool
	ProcessChar(char rune, mods KeyModifiers) bool
	ProcessMouseWheel(deltaX int, deltaY int) bool
	ProcessTimer()
	ProcessFocused()
	ProcessFocusLost()
	ProcessPropChange(key string, value interface{})

	ProcessClosePopup()

	RectClientAreaOnWindow() (x, y int)

	ScrollX() int
	ScrollY() int

	SetMouseCursor(cursor MouseCursor)
	MouseCursor() MouseCursor

	AddWidget(gridX, gridY int, widget Widgeter)
	RemoveWidget(widget Widgeter)

	AllChildren() []Widgeter
	IsCanBeFocused() bool

	IsVisible() bool

	GridX() int
	GridY() int
	SetGridPosition(row, column int)

	XExpandable() bool
	YExpandable() bool

	MinWidth() int
	MinHeight() int

	MaxWidth() int
	MaxHeight() int

	SetAbsolutePositioning(absolute bool)
	SetXExpandable(expandable bool)
	SetYExpandable(expandable bool)

	ClearLayoutCache()
	// contains filtered or unexported methods
}

Directories

Path Synopsis
Package i18n holds the translations of an application as Go code: the strings are the fields of a struct, and each language is a value of it.
Package i18n holds the translations of an application as Go code: the strings are the fields of a struct, and each language is a value of it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址