wui

package module
v2.4.2 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2021 License: MIT Imports: 9 Imported by: 0

README

Windows GUI Library

This is a pure Go library to create native Windows GUIs. See the online documentation for details. Note that you need to set GOOS=windows to display all of the documentation as most files are tagged with //+build windows.

Minimal Example

This is all the code you need to create a window (which does not do much).

package main

import "github.com/gonutz/wui/v2"

func main() {
	wui.NewWindow().Show()
}

The Designer

I am currently working on a graphical designer. It is located under github.com/gonutz/wui/v2/cmd/designer.

At the moment it lets you place widgets graphically and generate a Go main file from it (using the Save menu). You can also run a preview with Ctrl+R.

There is no way to read the generated code back in at the moment. Right now it is a tool to place things and generate code from it.

Documentation

Index

Constants

View Source
const (
	KeyLeftMouseButton   = w32.VK_LBUTTON
	KeyRightMouseButton  = w32.VK_RBUTTON
	KeyCancel            = w32.VK_CANCEL
	KeyMiddleMouseButton = w32.VK_MBUTTON
	KeyXMouseButton1     = w32.VK_XBUTTON1
	KeyXMouseButton2     = w32.VK_XBUTTON2
	KeyBack              = w32.VK_BACK
	KeyTab               = w32.VK_TAB
	KeyClear             = w32.VK_CLEAR
	KeyReturn            = w32.VK_RETURN
	KeyShift             = w32.VK_SHIFT
	KeyControl           = w32.VK_CONTROL
	KeyAlt               = w32.VK_MENU
	KeyPause             = w32.VK_PAUSE
	KeyCapital           = w32.VK_CAPITAL
	KeyKana              = w32.VK_KANA
	KeyHangul            = w32.VK_HANGUL
	KeyIMEOn             = w32.VK_IME_ON
	KeyJunja             = w32.VK_JUNJA
	KeyFinal             = w32.VK_FINAL
	KeyHanja             = w32.VK_HANJA
	KeyKanji             = w32.VK_KANJI
	KeyIMEOff            = w32.VK_IME_OFF
	KeyEscape            = w32.VK_ESCAPE
	KeyConvert           = w32.VK_CONVERT
	KeyNonConvert        = w32.VK_NONCONVERT
	KeyAccept            = w32.VK_ACCEPT
	KeyModeChange        = w32.VK_MODECHANGE
	KeySpace             = w32.VK_SPACE
	KeyPrior             = w32.VK_PRIOR
	KeyNext              = w32.VK_NEXT
	KeyEnd               = w32.VK_END
	KeyHome              = w32.VK_HOME
	KeyLeft              = w32.VK_LEFT
	KeyUp                = w32.VK_UP
	KeyRight             = w32.VK_RIGHT
	KeyDown              = w32.VK_DOWN
	KeySelect            = w32.VK_SELECT
	KeyPrint             = w32.VK_PRINT
	KeyExecute           = w32.VK_EXECUTE
	KeySnapshot          = w32.VK_SNAPSHOT
	KeyInsert            = w32.VK_INSERT
	KeyDelete            = w32.VK_DELETE
	KeyHelp              = w32.VK_HELP
	Key0                 = '0'
	Key1                 = '1'
	Key2                 = '2'
	Key3                 = '3'
	Key4                 = '4'
	Key5                 = '5'
	Key6                 = '6'
	Key7                 = '7'
	Key8                 = '8'
	Key9                 = '9'
	KeyA                 = 'A'
	KeyB                 = 'B'
	KeyC                 = 'C'
	KeyD                 = 'D'
	KeyE                 = 'E'
	KeyF                 = 'F'
	KeyG                 = 'G'
	KeyH                 = 'H'
	KeyI                 = 'I'
	KeyJ                 = 'J'
	KeyK                 = 'K'
	KeyL                 = 'L'
	KeyM                 = 'M'
	KeyN                 = 'N'
	KeyO                 = 'O'
	KeyP                 = 'P'
	KeyQ                 = 'Q'
	KeyR                 = 'R'
	KeyS                 = 'S'
	KeyT                 = 'T'
	KeyU                 = 'U'
	KeyV                 = 'V'
	KeyW                 = 'W'
	KeyX                 = 'X'
	KeyY                 = 'Y'
	KeyZ                 = 'Z'
	KeyLeftWindows       = w32.VK_LWIN
	KeyRightWindows      = w32.VK_RWIN
	KeyApps              = w32.VK_APPS
	KeySleep             = w32.VK_SLEEP
	KeyNum0              = w32.VK_NUMPAD0
	KeyNum1              = w32.VK_NUMPAD1
	KeyNum2              = w32.VK_NUMPAD2
	KeyNum3              = w32.VK_NUMPAD3
	KeyNum4              = w32.VK_NUMPAD4
	KeyNum5              = w32.VK_NUMPAD5
	KeyNum6              = w32.VK_NUMPAD6
	KeyNum7              = w32.VK_NUMPAD7
	KeyNum8              = w32.VK_NUMPAD8
	KeyNum9              = w32.VK_NUMPAD9
	KeyMultiply          = w32.VK_MULTIPLY
	KeyAdd               = w32.VK_ADD
	KeySeparator         = w32.VK_SEPARATOR
	KeySubtract          = w32.VK_SUBTRACT
	KeyDecimal           = w32.VK_DECIMAL
	KeyDivide            = w32.VK_DIVIDE
	KeyF1                = w32.VK_F1
	KeyF2                = w32.VK_F2
	KeyF3                = w32.VK_F3
	KeyF4                = w32.VK_F4
	KeyF5                = w32.VK_F5
	KeyF6                = w32.VK_F6
	KeyF7                = w32.VK_F7
	KeyF8                = w32.VK_F8
	KeyF9                = w32.VK_F9
	KeyF10               = w32.VK_F10
	KeyF11               = w32.VK_F11
	KeyF12               = w32.VK_F12
	KeyF13               = w32.VK_F13
	KeyF14               = w32.VK_F14
	KeyF15               = w32.VK_F15
	KeyF16               = w32.VK_F16
	KeyF17               = w32.VK_F17
	KeyF18               = w32.VK_F18
	KeyF19               = w32.VK_F19
	KeyF20               = w32.VK_F20
	KeyF21               = w32.VK_F21
	KeyF22               = w32.VK_F22
	KeyF23               = w32.VK_F23
	KeyF24               = w32.VK_F24
	KeyNumLock           = w32.VK_NUMLOCK
	KeyScroll            = w32.VK_SCROLL
	KeyOEMNecEqual       = w32.VK_OEM_NEC_EQUAL
	KeyOEMFjJisho        = w32.VK_OEM_FJ_JISHO
	KeyOEMFjMasshou      = w32.VK_OEM_FJ_MASSHOU
	KeyOEMFjTouroku      = w32.VK_OEM_FJ_TOUROKU
	KeyOEMFjLoya         = w32.VK_OEM_FJ_LOYA
	KeyOEMFjRoya         = w32.VK_OEM_FJ_ROYA
	KeyLeftShift         = w32.VK_LSHIFT
	KeyRightShift        = w32.VK_RSHIFT
	KeyLeftControl       = w32.VK_LCONTROL
	KeyRightControl      = w32.VK_RCONTROL
	KeyLeftAlt           = w32.VK_LMENU
	KeyRightAlt          = w32.VK_RMENU
	KeyBrowserBack       = w32.VK_BROWSER_BACK
	KeyBrowserForward    = w32.VK_BROWSER_FORWARD
	KeyBrowserRefresh    = w32.VK_BROWSER_REFRESH
	KeyBrowserStop       = w32.VK_BROWSER_STOP
	KeyBrowserSearch     = w32.VK_BROWSER_SEARCH
	KeyBrowserFavorites  = w32.VK_BROWSER_FAVORITES
	KeyBrowserHome       = w32.VK_BROWSER_HOME
	KeyVolumeMute        = w32.VK_VOLUME_MUTE
	KeyVolumeDown        = w32.VK_VOLUME_DOWN
	KeyVolumeUp          = w32.VK_VOLUME_UP
	KeyMediaNextTrack    = w32.VK_MEDIA_NEXT_TRACK
	KeyMediaPrevTrack    = w32.VK_MEDIA_PREV_TRACK
	KeyMediaStop         = w32.VK_MEDIA_STOP
	KeyMediaPlayPause    = w32.VK_MEDIA_PLAY_PAUSE
	KeyLaunchMail        = w32.VK_LAUNCH_MAIL
	KeyLaunchMediaSelect = w32.VK_LAUNCH_MEDIA_SELECT
	KeyLaunchApp1        = w32.VK_LAUNCH_APP1
	KeyLaunchApp2        = w32.VK_LAUNCH_APP2
	KeyOEM1              = w32.VK_OEM_1
	KeyOEMPlus           = w32.VK_OEM_PLUS
	KeyOEMComma          = w32.VK_OEM_COMMA
	KeyOEMMinus          = w32.VK_OEM_MINUS
	KeyOEMPeriod         = w32.VK_OEM_PERIOD
	KeyOEM2              = w32.VK_OEM_2
	KeyOEM3              = w32.VK_OEM_3
	KeyOEM4              = w32.VK_OEM_4
	KeyOEM5              = w32.VK_OEM_5
	KeyOEM6              = w32.VK_OEM_6
	KeyOEM7              = w32.VK_OEM_7
	KeyOEM8              = w32.VK_OEM_8
	KeyOEMAx             = w32.VK_OEM_AX
	KeyOEM102            = w32.VK_OEM_102
	KeyIcoHelp           = w32.VK_ICO_HELP
	KeyIco00             = w32.VK_ICO_00
	KeyProcesskey        = w32.VK_PROCESSKEY
	KeyIcoClear          = w32.VK_ICO_CLEAR
	KeyPacket            = w32.VK_PACKET
	KeyOEMReset          = w32.VK_OEM_RESET
	KeyOEMJump           = w32.VK_OEM_JUMP
	KeyOEMPA1            = w32.VK_OEM_PA1
	KeyOEMPA2            = w32.VK_OEM_PA2
	KeyOEMPA3            = w32.VK_OEM_PA3
	KeyOEMWSControl      = w32.VK_OEM_WSCTRL
	KeyOEMCuSel          = w32.VK_OEM_CUSEL
	KeyOEMAttention      = w32.VK_OEM_ATTN
	KeyOEMFinish         = w32.VK_OEM_FINISH
	KeyOEMCopy           = w32.VK_OEM_COPY
	KeyOEMAuto           = w32.VK_OEM_AUTO
	KeyOEMEnlw           = w32.VK_OEM_ENLW
	KeyOEMBacktab        = w32.VK_OEM_BACKTAB
	KeyAttention         = w32.VK_ATTN
	KeyCrSel             = w32.VK_CRSEL
	KeyExSel             = w32.VK_EXSEL
	KeyErEOF             = w32.VK_EREOF
	KeyPlay              = w32.VK_PLAY
	KeyZoom              = w32.VK_ZOOM
	KeyNoName            = w32.VK_NONAME
	KeyPa1               = w32.VK_PA1
	KeyOEMClear          = w32.VK_OEM_CLEAR
)

These are the keyboard key constants.

Variables

View Source
var (
	// Scroll bar gray area.
	ColorScrollBar = sysColor(w32.COLOR_SCROLLBAR)

	// Desktop.
	ColorBackground = sysColor(w32.COLOR_BACKGROUND)

	// Desktop.
	ColorDesktop = sysColor(w32.COLOR_DESKTOP)

	// Active window title bar. The associated foreground color is
	// COLOR_CAPTIONTEXT. Specifies the left side color in the color gradient of
	// an active window's title bar if the gradient effect is enabled.
	ColorActiveCaption = sysColor(w32.COLOR_ACTIVECAPTION)

	// Inactive window caption. The associated foreground color is
	// COLOR_INACTIVECAPTIONTEXT. Specifies the left side color in the color
	// gradient of an inactive window's title bar if the gradient effect is
	// enabled.
	ColorInactiveCaption = sysColor(w32.COLOR_INACTIVECAPTION)

	// Menu background. The associated foreground color is COLOR_MENUTEXT.
	ColorMenu = sysColor(w32.COLOR_MENU)

	// Window background. The associated foreground colors are COLOR_WINDOWTEXT
	// and COLOR_HOTLITE.
	ColorWindow = sysColor(w32.COLOR_WINDOW)

	// Window frame.
	ColorWindowFrame = sysColor(w32.COLOR_WINDOWFRAME)

	// Text in menus. The associated background color is COLOR_MENU.
	ColorMenuText = sysColor(w32.COLOR_MENUTEXT)

	// Text in windows. The associated background color is COLOR_WINDOW.
	ColorWindowText = sysColor(w32.COLOR_WINDOWTEXT)

	// Text in caption, size box, and scroll bar arrow box. The associated
	// background color is COLOR_ACTIVECAPTION.
	ColorCaptionText = sysColor(w32.COLOR_CAPTIONTEXT)

	// Active window border.
	ColorActiveBorder = sysColor(w32.COLOR_ACTIVEBORDER)

	// Inactive window border.
	ColorInactiveBorder = sysColor(w32.COLOR_INACTIVEBORDER)

	// Background color of multiple document interface (MDI) applications.
	ColorAppWorkspace = sysColor(w32.COLOR_APPWORKSPACE)

	// Item(s) selected in a control. The associated foreground color is
	// COLOR_HIGHLIGHTTEXT.
	ColorHighlight = sysColor(w32.COLOR_HIGHLIGHT)

	// Text of item(s) selected in a control. The associated background color is
	// COLOR_HIGHLIGHT.
	ColorHighlightText = sysColor(w32.COLOR_HIGHLIGHTTEXT)

	// Face color for three-dimensional display elements and for dialog box
	// backgrounds.
	Color3DFace = sysColor(w32.COLOR_3DFACE)

	// Face color for three-dimensional display elements and for dialog box
	// backgrounds. The associated foreground color is COLOR_BTNTEXT.
	ColorButtonFace = sysColor(w32.COLOR_BTNFACE)

	// Shadow color for three-dimensional display elements (for edges facing
	// away from the light source).
	Color3DShadow = sysColor(w32.COLOR_3DSHADOW)

	// Shadow color for three-dimensional display elements (for edges facing
	// away from the light source).
	ColorButtonShadow = sysColor(w32.COLOR_BTNSHADOW)

	// Grayed (disabled) text. This color is set to 0 if the current display
	// driver does not support a solid gray color.
	ColorGrayText = sysColor(w32.COLOR_GRAYTEXT)

	// Text on push buttons. The associated background color is COLOR_BTNFACE.
	ColorButtonText = sysColor(w32.COLOR_BTNTEXT)

	// Color of text in an inactive caption. The associated background color is
	// COLOR_INACTIVECAPTION.
	ColorInactiveCaptionText = sysColor(w32.COLOR_INACTIVECAPTIONTEXT)

	// Highlight color for three-dimensional display elements (for edges facing
	// the light source.)
	Color3DHighlight = sysColor(w32.COLOR_3DHIGHLIGHT)

	// Highlight color for three-dimensional display elements (for edges facing
	// the light source.)
	ColorButtonHighlight = sysColor(w32.COLOR_BTNHIGHLIGHT)

	// Dark shadow for three-dimensional display elements.
	Color3DDarkShadow = sysColor(w32.COLOR_3DDKSHADOW)

	// Light color for three-dimensional display elements (for edges facing the
	// light source.)
	Color3DLight = sysColor(w32.COLOR_3DLIGHT)

	// Text color for tooltip controls. The associated background color is
	// COLOR_INFOBK.
	ColorInfoText = sysColor(w32.COLOR_INFOTEXT)

	// Background color for tooltip controls. The associated foreground color is
	// COLOR_INFOTEXT.
	ColorInfoBackground = sysColor(w32.COLOR_INFOBK)

	// Color for a hyperlink or hot-tracked item. The associated background
	// color is COLOR_WINDOW.
	ColorHotlight = sysColor(w32.COLOR_HOTLIGHT)

	// Right side color in the color gradient of an active window's title bar.
	// COLOR_ACTIVECAPTION specifies the left side color. Use
	// SPI_GETGRADIENTCAPTIONS with the SystemParametersInfo function to
	// determine whether the gradient effect is enabled.
	ColorGradientActiveCaption = sysColor(w32.COLOR_GRADIENTACTIVECAPTION)

	// Right side color in the color gradient of an inactive window's title bar.
	// COLOR_INACTIVECAPTION specifies the left side color.
	ColorGradientInactiveCaption = sysColor(w32.COLOR_GRADIENTINACTIVECAPTION)

	// The color used to highlight menu items when the menu appears as a flat
	// menu (see SystemParametersInfo). The highlighted menu item is outlined
	// with COLOR_HIGHLIGHT. Windows 2000: This value is not supported.
	ColorMenuHighlight = sysColor(w32.COLOR_MENUHILIGHT)

	// The background color for the menu bar when menus appear as flat menus
	// (see SystemParametersInfo). However, COLOR_MENU continues to specify the
	// background color of the menu popup. Windows 2000: This value is not
	// supported.
	ColorMenuBar = sysColor(w32.COLOR_MENUBAR)
)

These are predefined colors defined by the current Windows theme.

View Source
var (
	// CursorArrow is the standard, default arrow cursor.
	CursorArrow = loadCursor(w32.IDC_ARROW)

	// CursorIBeam is the text cursor, it looks like the letter I.
	CursorIBeam = loadCursor(w32.IDC_IBEAM)

	// CursorWait is the hour glass or rotating circle cursor that indicates
	// that an action will take some more time.
	CursorWait = loadCursor(w32.IDC_WAIT)

	// CursorCross looks like a black + (plus) symbol.
	CursorCross = loadCursor(w32.IDC_CROSS)

	// CursorUpArrow is a vertical arrow pointing upwards.
	CursorUpArrow = loadCursor(w32.IDC_UPARROW)

	// CursorSizeNWSE is a diagonal line from top-left to bottom-right with
	// arrows at both ends.
	CursorSizeNWSE = loadCursor(w32.IDC_SIZENWSE)

	// CursorSizeNESW is a diagonal line from top-right to bottom-left with
	// arrows at both ends.
	CursorSizeNESW = loadCursor(w32.IDC_SIZENESW)

	// CursorSizeWE is a horizontal line from left to right with arrows at both
	// ends.
	CursorSizeWE = loadCursor(w32.IDC_SIZEWE)

	// CursorSizeNS is a vertical line from top to bottom with arrows at both
	// ends.
	CursorSizeNS = loadCursor(w32.IDC_SIZENS)

	// CursorSizeAll is a white + (plus) symbol with arrows at all four ends.
	CursorSizeAll = loadCursor(w32.IDC_SIZEALL)

	// CursorNo indicates that an action is not possible. It is a crossed-out
	// red circle, like a stop sign.
	CursorNo = loadCursor(w32.IDC_NO)

	// CursorHand is a hand pointing its index finger upwards.
	CursorHand = loadCursor(w32.IDC_HAND)

	// CursorAppStarting is a combination of CursorArrow and CursorWait, it has
	// the arrow cursor but with an hour glass or rotating circle next to it.
	CursorAppStarting = loadCursor(w32.IDC_APPSTARTING)

	// CursorHelp is the default arrow cursor with a little question mark icon
	// next to it.
	CursorHelp = loadCursor(w32.IDC_HELP)
)
View Source
var (
	// IconApplication is the default application icon.
	IconApplication = loadIcon(w32.IDI_APPLICATION)
	// IconQuestion is a question mark icon.
	IconQuestion = loadIcon(w32.IDI_QUESTION)
	// versions (like Windows 2000) this was a Windows icon.
	IconWinLogo = loadIcon(w32.IDI_WINLOGO)
	// IconShield is the icon that comes up when Windows asks admin permission.
	// It looks like a knight's shield.
	IconShield = loadIcon(w32.IDI_SHIELD)
	// IconWarning is an exclamation mark icon.
	IconWarning = loadIcon(w32.IDI_WARNING)
	// IconError is a red cross icon.
	IconError = loadIcon(w32.IDI_ERROR)
	// IconInformation is a blue 'i' for information.
	IconInformation = loadIcon(w32.IDI_INFORMATION)
)

Functions

This section is empty.

Types

type Color

type Color uint32

Color is a 24 bit color in BGR form. The alpha channel is always 0 and has no relevance.

func RGB

func RGB(r, g, b uint8) Color

RBG creates a new Color with the given intensities. r,g,b means red, green, blue. Value 0 is dark, 255 is full intensity.

func (Color) B

func (c Color) B() uint8

B returns the blue intensity in the Color, 0 means no blue, 255 means full blue.

func (Color) G

func (c Color) G() uint8

G returns the green intensity in the Color, 0 means no green, 255 means full green.

func (Color) R

func (c Color) R() uint8

R returns the red intensity in the Color, 0 means no red, 255 means full red.

type Cursor

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

Cursor describes the mouse cursor image. You can use a pre-defined Cursor... variable (see below) or create a custom cursor with NewCursorFromImage.

func NewCursorFromImage

func NewCursorFromImage(img image.Image, x, y int) (*Cursor, error)

NewCursorFromImage creates a cursor with 4 possible colors: black, white, transparent and inverse screen color. Inverse screen color depends on what is under the cursor at any time. The cursor will be white minus the screen color to give maximum contrast for such pixels.

Fully opaque black and white pixels in the image are interpreted as black and white.

Fully transparent pixels in the image are interpreted as screen color.

All other pixels are interpreted as inverse screen color. This means even "almost" black/white/transparent, say with intensity 0xFFFE instead of 0xFFFF, will be interpreted as inverse screen color.

type Icon

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

Icon holds a window icon. You can use a pre-defined Icon... variable (see below) or create a custom icon with NewIconFromImage, NewIconFromExeResource, NewIconFromFile or NewIconFromReader.

func NewIconFromExeResource

func NewIconFromExeResource(resourceID int) (*Icon, error)

NewIconFromExeResource loads an icon that was compiled into the executable. In Go you can create .syso files that contain resources. Each resource will get a unique ID. See for example the rsrc tool which can create .syso files: https://github.com/gonutz/rsrc

func NewIconFromFile

func NewIconFromFile(path string) (*Icon, error)

NewIconFromFile loads an icon from disk. The format must be .ico, not an image.

func NewIconFromImage

func NewIconFromImage(img image.Image) (*Icon, error)

IconInformation creates an icon from an image. The image should have a standard icon size, typically square and a power of 2, see https://docs.microsoft.com/en-us/windows/win32/uxguide/vis-icons

func NewIconFromReader

func NewIconFromReader(r io.Reader) (*Icon, error)

NewIconFromReader loads an icon from the given reader. The format must be .ico, not an image.

type Key

type Key int

Key represents a button on a keyboard. See the constants below.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL