Documentation
¶
Index ¶
- Constants
- Variables
- func GetNativeWindowByHandle(hwnd uintptr) *nativeWindow
- func HasPrintDialog() bool
- func IsUIThread() bool
- func OpenFileDialog(parent Window, opts OpenFileDialogOptions) ([]string, error)
- func Post(f func())
- func PrintFile(printer, path string, copies int, title string, options map[string]string) error
- func PrintWithDialog(owner Window, req PrintRequest) error
- func Printers() (names []string, defaultName string, err error)
- func Run(windows ...Window)
- func RunOnUIThread(f func())
- func SaveFileDialog(parent Window, opts SaveFileDialogOptions) (string, error)
- func SelectDirectoryDialog(parent Window, opts SelectDirectoryDialogOptions) (string, error)
- func SystemFontFile(name string) (path, family string, err error)
- func SystemLanguage() string
- func SystemUIFontName() string
- type FileDialogFilter
- type FontData
- type Key
- type KeyModifiers
- type MouseButton
- type MouseCursor
- type OpenFileDialogOptions
- type PopupWindow
- type PrintRequest
- type SaveFileDialogOptions
- type SelectDirectoryDialogOptions
- type SystemFont
- type TrayIcon
- type TrayMenuItem
- type Window
Constants ¶
const ( KeyEsc = 0x1B KeyF1 = 0x70 KeyF2 = 0x71 KeyF3 = 0x72 KeyF4 = 0x73 KeyF5 = 0x74 KeyF6 = 0x75 KeyF7 = 0x76 KeyF8 = 0x77 KeyF9 = 0x78 KeyF10 = 0x79 KeyF11 = 0x7A KeyF12 = 0x7B KeyF13 = 0x7C KeyF14 = 0x7D KeyF15 = 0x7E KeyF16 = 0x7F KeyF17 = 0x80 KeyF18 = 0x81 KeyF19 = 0x82 KeyF20 = 0x83 KeyF21 = 0x84 KeyF22 = 0x85 KeyF23 = 0x86 KeyF24 = 0x87 KeyGrave = 0xC0 Key1 = 0x31 Key2 = 0x32 Key3 = 0x33 Key4 = 0x34 Key5 = 0x35 Key6 = 0x36 Key7 = 0x37 Key8 = 0x38 Key9 = 0x39 Key0 = 0x30 KeyMinus = 0xBD KeyEqual = 0xBB KeyBackspace = 0x08 KeyTab = 0x09 KeyQ = 0x51 KeyW = 0x57 KeyE = 0x45 KeyR = 0x52 KeyT = 0x54 KeyY = 0x59 KeyU = 0x55 KeyI = 0x49 KeyO = 0x4F KeyP = 0x50 KeyLeftBracket = 0xDB KeyRightBracket = 0xDD KeyBackslash = 0xDC KeyCapsLock = 0x14 KeyA = 0x41 KeyS = 0x53 KeyD = 0x44 KeyF = 0x46 KeyG = 0x47 KeyH = 0x48 KeyJ = 0x4A KeyK = 0x4B KeyL = 0x4C KeySemicolon = 0xBA KeyApostrophe = 0xDE KeyEnter = 0x0D KeyShift = 0x10 KeyZ = 0x5A KeyX = 0x58 KeyC = 0x43 KeyV = 0x56 KeyB = 0x42 KeyN = 0x4E KeyM = 0x4D KeyComma = 0xBC KeyDot = 0xBE KeySlash = 0xBF KeyCtrl = 0x11 KeyWin = 0x5B KeyAlt = 0x12 KeySpace = 0x20 KeyContextMenu = 0x5D KeyPrintScreen = 0x2C KeyScrollLock = 0x91 KeyPauseBreak = 0x13 KeyInsert = 0x2D KeyHome = 0x24 KeyPageUp = 0x21 KeyDelete = 0x2E KeyEnd = 0x23 KeyPageDown = 0x22 KeyArrowUp = 0x26 KeyArrowLeft = 0x25 KeyArrowDown = 0x28 KeyArrowRight = 0x27 KeyNumLock = 0x90 KeyNumpadSlash = 0x6F KeyNumpadAsterisk = 0x6A KeyNumpadMinus = 0x6D KeyNumpadPlus = 0x6B KeyNumpad1 = 0x61 KeyNumpad2 = 0x62 KeyNumpad3 = 0x63 KeyNumpad4 = 0x64 KeyNumpad5 = 0x65 KeyNumpad6 = 0x66 KeyNumpad7 = 0x67 KeyNumpad8 = 0x68 KeyNumpad9 = 0x69 KeyNumpad0 = 0x60 KeyNumpadDot = 0x6E // Mac OS KeyCommand = 0xCC01 KeyFunction = 0xCC03 )
Variables ¶
var ErrNoFileDialog = errors.New("nui: no file dialog helper found (install zenity or kdialog)")
ErrNoFileDialog is returned when the system has no file dialog to show, e.g. Linux without zenity or kdialog
var ErrNoPrinting = errors.New("nui: printing is not available")
ErrNoPrinting is returned where there is no way to print: no print dialog (Windows) and no CUPS (lp) elsewhere
var ErrNotificationsNotSupported = errors.New("nui: system notifications are not available")
ErrNotificationsNotSupported is returned by ShowNotification where the platform can't show system notifications
var ErrPrintCanceled = errors.New("nui: printing canceled")
ErrPrintCanceled is returned when the user cancels printing
var ErrSystemFontNotFound = errors.New("nui: the system has no such font")
ErrSystemFontNotFound is returned when the system has no font of the name
var ErrSystemTextNotSupported = errors.New("nui: system text rendering is not available")
ErrSystemTextNotSupported is returned where the platform's text engine isn't used (macOS: see SystemFontFile)
var ErrTrayNotSupported = errors.New("nui: the system tray is not available")
ErrTrayNotSupported is returned when the system has no tray (notification area) to put an icon in
Functions ¶
func GetNativeWindowByHandle ¶
func GetNativeWindowByHandle(hwnd uintptr) *nativeWindow
func HasPrintDialog ¶
func HasPrintDialog() bool
HasPrintDialog reports whether the system has a print dialog of its own
func IsUIThread ¶
func IsUIThread() bool
IsUIThread reports whether the caller runs on the UI thread - the main OS thread, where all the window callbacks are called.
func OpenFileDialog ¶
func OpenFileDialog(parent Window, opts OpenFileDialogOptions) ([]string, error)
OpenFileDialog shows the operating system's standard "Open File" dialog, owned by parent if given (parent may be nil), and blocks until the user picks a file or cancels. On cancel it returns (nil, nil).
func Post ¶
func Post(f func())
Post schedules f to run on the UI thread and returns at once. It is safe to call from any goroutine, including the UI thread itself (f then runs after the current callback returns). Functions run in the order they were posted.
f runs only while the UI thread is in an event loop (Run, Exec), so the program's main goroutine must eventually call one of them.
func PrintFile ¶
PrintFile sends the file to the CUPS printer with lp; options are lp's -o options, e.g. "media": "A4"
func PrintWithDialog ¶
func PrintWithDialog(owner Window, req PrintRequest) error
PrintWithDialog is Windows only: elsewhere nui shows its own dialog
func Run ¶
func Run(windows ...Window)
Run shows the windows and runs the event loop until all of them are closed. Call it from the main goroutine: the event loop of every window - these ones and the ones opened later, e.g. from a callback - runs on the UI thread (the main OS thread), and so does every window callback.
Windows opened later need no Run of their own: Show() is enough, the running event loop serves them too.
func RunOnUIThread ¶
func RunOnUIThread(f func())
RunOnUIThread runs f on the UI thread and waits for it to return. Called on the UI thread, it runs f at once. Called from another goroutine, it blocks until the UI thread picks f up, so it must not be used while the UI thread itself waits for the calling goroutine.
func SaveFileDialog ¶
func SaveFileDialog(parent Window, opts SaveFileDialogOptions) (string, error)
SaveFileDialog shows the operating system's standard "Save File" dialog, owned by parent if given (parent may be nil), and blocks until the user picks a destination path or cancels. On cancel it returns ("", nil).
func SelectDirectoryDialog ¶
func SelectDirectoryDialog(parent Window, opts SelectDirectoryDialogOptions) (string, error)
SelectDirectoryDialog shows the operating system's standard "Select Folder" dialog, owned by parent if given (parent may be nil), and blocks until the user picks a directory or cancels. On cancel it returns ("", nil).
func SystemFontFile ¶
SystemFontFile is used on macOS only, where the system fonts are drawn by nui's rasterizer: elsewhere OpenSystemFont draws them
func SystemLanguage ¶
func SystemLanguage() string
SystemLanguage returns the language of the user interface of the system as the system reports it, e.g. "ru-RU", "zh-Hans-CN" or "en_US.UTF-8"; "" if unknown.
func SystemUIFontName ¶
func SystemUIFontName() string
SystemUIFontName returns the name of the font the system uses for its interface, e.g. "Segoe UI" on Windows
Types ¶
type FileDialogFilter ¶
FileDialogFilter restricts an open-file dialog to a named group of file patterns, e.g. {DisplayName: "Text files", Patterns: []string{"*.txt", "*.md"}}.
type FontData ¶
FontData is a font file the application handed to the system's text engine (see RegisterFontData): the family name, the weight and the style the system knows it by
func RegisterFontData ¶
RegisterFontData hands a TrueType or OpenType file to the system's text engine, for this process only, so OpenFontData draws it like a system font (GDI with ClearType on Windows). ErrSystemTextNotSupported elsewhere.
type KeyModifiers ¶
func (KeyModifiers) String ¶
func (c KeyModifiers) String() string
type MouseButton ¶
type MouseButton int
const ( MouseButtonLeft MouseButton = 0 MouseButtonMiddle MouseButton = 1 MouseButtonRight MouseButton = 2 )
func (MouseButton) String ¶
func (m MouseButton) String() string
type MouseCursor ¶
type MouseCursor int
const ( MouseCursorNotDefined MouseCursor = 0 MouseCursorArrow MouseCursor = 1 MouseCursorPointer MouseCursor = 2 MouseCursorResizeHor MouseCursor = 3 MouseCursorResizeVer MouseCursor = 4 MouseCursorIBeam MouseCursor = 5 )
type OpenFileDialogOptions ¶
type OpenFileDialogOptions struct {
Title string
DefaultDirectory string
Filters []FileDialogFilter
AllowMultiple bool
}
OpenFileDialogOptions configures OpenFileDialog.
type PopupWindow ¶
type PopupWindow interface {
OnPaint(func(rgba *image.RGBA))
// Scale returns how many pixels of the image given to OnPaint a logical
// pixel takes, as Window.Scale
Scale() float64
// Mouse events of an interactive popup, in popup coordinates
OnMouseMove(func(x, y int))
OnMouseButtonDown(func(btn MouseButton, x, y int))
OnMouseButtonUp(func(btn MouseButton, x, y int))
OnMouseLeave(func())
OnMouseWheel(func(deltaX, deltaY int))
// SetMouseCursor sets the cursor shown over an interactive popup
SetMouseCursor(cursor MouseCursor)
// ShowAt moves the popup to (x, y) in screen coordinates, resizes it and
// shows it without activating it
ShowAt(x, y, width, height int)
Hide()
Update()
Close()
}
PopupWindow is a borderless window for tooltips, menus and similar popups that may extend beyond the owner window. It never takes activation or keyboard focus, has no taskbar button and stays above its owner.
A non-interactive popup (a tooltip) lets the mouse pass through to the window below it. An interactive one (a menu) gets mouse events itself; keyboard input stays with the owner.
func CreatePopupWindow ¶
func CreatePopupWindow(owner Window, interactive bool) PopupWindow
CreatePopupWindow creates a hidden popup owned by owner. Returns nil when the platform doesn't support popups - callers should fall back to drawing inside the owner window.
type PrintRequest ¶
type PrintRequest struct {
Title string
// PageCount returns the number of pages for the page size
PageCount func(width, height int, dpi float64) int
// Render draws the page (0-based)
Render func(page, width, height int, dpi float64) *image.RGBA
// MaxDPI caps the resolution the pages are drawn at; the printer scales
// them up to its own
MaxDPI float64
}
PrintRequest is a document to print with the system print dialog. The page size is the printable area of the printer the user chose, in pixels at dpi.
type SaveFileDialogOptions ¶
type SaveFileDialogOptions struct {
Title string
DefaultDirectory string
DefaultFileName string
Filters []FileDialogFilter
}
SaveFileDialogOptions configures SaveFileDialog.
type SelectDirectoryDialogOptions ¶
SelectDirectoryDialogOptions configures SelectDirectoryDialog.
type SystemFont ¶
type SystemFont interface {
// Metrics returns the ascent and the descent of a line, in pixels
Metrics() (ascent, descent int)
// Positions returns the x of each character boundary of text: the start
// of every character and, last, the width of the whole text
Positions(text string) []int
// Draw draws text in the color with the top-left corner of its line box
// at (x, y), within clip. The pixels under the text must be opaque:
// subpixel antialiasing blends each color channel on its own.
// col is premultiplied, as color.RGBA is.
Draw(dst *image.RGBA, text string, col color.RGBA, x, y int, clip image.Rectangle)
}
SystemFont is a font drawn by the system's own text engine - GDI with ClearType on Windows, FreeType with the fontconfig settings (subpixel order, hinting, LCD filter) on Linux - so the text looks like in the other applications. Safe for concurrent use.
func OpenFontData ¶
func OpenFontData(fd FontData, pixelSize float64) (SystemFont, error)
OpenFontData opens a font of RegisterFontData with the em size in pixels
func OpenSystemFont ¶
func OpenSystemFont(name string, pixelSize float64) (SystemFont, error)
OpenSystemFont opens the system font of the family name with the em size in pixels. ErrSystemFontNotFound if the system has no such font.
type TrayIcon ¶
type TrayIcon interface {
SetIcon(icon *image.RGBA)
SetTooltip(text string)
// SetMenu sets the menu shown on a right click (on macOS, on any click)
SetMenu(items []TrayMenuItem)
// OnClick sets the function called on a left click
OnClick(f func())
// ShowNotification shows a system notification from the application
ShowNotification(title, text string) error
// Close removes the icon
Close()
}
TrayIcon is an icon in the system tray (the notification area of the taskbar, or the menu bar on macOS) with a tooltip and a menu. Its callbacks are called on the UI thread; call its methods there too.
func CreateTrayIcon ¶
CreateTrayIcon puts an icon in the system tray
type TrayMenuItem ¶
type TrayMenuItem struct {
Text string
OnClick func()
Disabled bool
Separator bool
// Checkable items show a check box, checked when Checked is set
Checkable bool
Checked bool
// Items makes the item a submenu
Items []TrayMenuItem
}
TrayMenuItem is an item of the tray icon's menu
type Window ¶
type Window interface {
// Change window
Show() // Shows the window, non-modal; returns immediately. Brings a hidden window back.
Hide() // Hides the window until the next Show; it stays open
ShowModal(parent Window) // Shows the window as a modal dialog owned by parent; returns immediately (blocks on macOS)
Update() // Updates the window content
Close() bool // Closes the window
Exec() // Waits for the window to close, running the event loop on the UI thread
SystemHandle() any
// Keyboard events
OnKeyDown(func(keyCode Key, mods KeyModifiers) bool)
OnKeyUp(func(keyCode Key, mods KeyModifiers))
OnChar(func(char rune))
// Mouse events
OnMouseEnter(func())
OnMouseLeave(func())
OnMouseMove(func(x, y int))
OnMouseButtonDown(func(btn MouseButton, x int, y int))
OnMouseButtonUp(func(btn MouseButton, x int, y int))
OnMouseButtonDblClick(func(btn MouseButton, x int, y int))
OnMouseWheel(func(deltaX int, deltaY int))
// Window events
OnCreated(func())
OnPaint(func(rgba *image.RGBA))
OnMove(func(x, y int))
OnResize(func(width, height int))
OnCloseRequest(func() bool)
OnTimer(func())
// OnDeactivate is called when the window loses activation (keyboard
// focus): the user switched to another window or application
OnDeactivate(func())
// OnActivate is called when the window gets activation (keyboard focus);
// it may come more than once in a row
OnActivate(func())
// OnFilesDropped is called when files dragged from the system (e.g. from
// the file manager) are dropped on the window, at (x, y) in client
// coordinates
OnFilesDropped(func(files []string, x, y int))
// Window appearance
SetTitle(title string)
SetAppIcon(icon *image.RGBA)
SetBackgroundColor(color color.RGBA)
SetMouseCursor(cursor MouseCursor)
// SetDarkMode switches the window frame (title bar) to its dark or light
// look, to match the application's theme
SetDarkMode(dark bool)
Move(width int, height int)
MoveToCenterOfScreen()
Resize(width int, height int)
// SetMinSize keeps the user from making the client area smaller than
// width x height (logical pixels)
SetMinSize(width int, height int)
MinimizeWindow()
MaximizeWindow()
// RestoreWindow returns a maximized window to its normal size
RestoreWindow()
IsMaximized() bool
// SetAlwaysOnTop keeps the window above the other windows
SetAlwaysOnTop(onTop bool)
// RequestAttention marks the window in the taskbar/dock until the user looks at it
RequestAttention()
// Beep plays the system alert sound
Beep()
SetAllowMinimize(allow bool)
SetAllowMaximize(allow bool)
// Get window information
Size() (width, height int)
Pos() (x, y int)
PosX() int
PosY() int
Width() int
Height() int
KeyModifiers() KeyModifiers
DrawTimeUs() int64
// Scale returns how many pixels of the image given to OnPaint a logical
// pixel takes: 1, or e.g. 2 on a Retina screen. The sizes, positions and
// mouse coordinates are all logical.
Scale() float64
// ClientToScreen converts a point in the window's client area to screen coordinates
ClientToScreen(x, y int) (screenX, screenY int)
// ScreenWorkArea returns the usable area (without taskbar/dock) of the
// monitor containing the screen point (x, y)
ScreenWorkArea(x, y int) (areaX, areaY, areaWidth, areaHeight int)
}
Window is a native window. All the windows live on the UI thread (the main OS thread): its event loop serves them all and calls every callback there, so callbacks of different windows never run concurrently. Call the methods on the UI thread too - from the callbacks, or via Post/RunOnUIThread from other goroutines. Update, Close and Exec may be called from any goroutine.
func CreateDefaultWindow ¶
func CreateDefaultWindow() Window
Source Files
¶
- app.go
- dnd_linux.go
- filedialog.go
- filedialog_linux.go
- ime_linux.go
- keys.go
- language.go
- language_linux.go
- mouse.go
- native_window.go
- native_window_linux.go
- nui.go
- popup.go
- popup_linux.go
- print.go
- print_cups.go
- systemfontdata_other.go
- systemfontfile.go
- systemtext.go
- systemtext_linux.go
- tray.go
- tray_linux.go
- uiqueue.go
- utils_linux.go
- window.go
- xlib_linux.go