A pure Go library to create native Windows GUIs. This project is a modified and enhanced version of the original gonutz/wui library.
See the online documentation for API details.
This project is based on the excellent work by gonutz who created the original wui library. We've extended it with additional features and improvements while maintaining compatibility with the original API.
Original library: github.com/gonutz/wui
The former third-party packages are now part of this module, so there are no external dependencies and no network access is needed to build:
github.com/2dprototype/wui/w32(Win32 bindings, from gonutz/w32 v2, extended)github.com/2dprototype/wui/check(test helper, from gonutz/check)
GroupBox- captioned frame for visually grouping controlsTabControl- tab headers withSetOnChange; show/hidePanels per tab (useContentBounds()to place them)StatusBar- bottom status bar, optional multiple parts viaSetParts/SetPartTextWindow.AddTimer(ms, f)- periodicTimerrunning on the GUI thread (Start,Stop,SetInterval)DatePicker- date / long date / time chooser withValue,SetValue,SetOnChangeColorDialog- system color chooser (SetColor,Execute(parent),Color)ClipboardText()/SetClipboardText(text)- read and write unicode text on the clipboard
window.SetCenterOnShow(true)- centers on the screen when shown withShow, and over the parent window when shown withShowModalwindow.Center(),window.CenterOnScreen(),window.CenterOnParent()- center at any time
The examples folder has one small program for each new feature: group_box, tab_control, status_bar, timer, center_window, clipboard, color_dialog, date_picker, canvas_drawing, canvas_mouse, tree_view, context_menu, tooltip and toolbar. Run one with go run ./examples/timer.
New Canvas functions, all work inside PaintBox.SetOnPaint:
- Strokes:
SetStroke(wui.Stroke{Width, Style, Cap, Join}),SetLineWidth,SetLineStyle- width, dash styles (LineDash,LineDot, ...), round/square/flat caps, round/bevel/miter joins. They apply to every outline function (Line,DrawRect,DrawEllipse,Polyline,Arc,DrawPie, ...) - Shapes:
DrawRoundRect,FillRoundRect,FillRoundRectOutline,FillRectOutline,FillEllipseOutline,DrawPolygon,FillPolygonOutline,Bezier,Curve(smooth curve through points),SetPixel,Pixel,DrawFocusRect - Helpers:
RegularPolygonPoints(triangle, hexagon, ...),StarPoints,Clear - Fills:
FillGradientH,FillGradientV,FillRectAlpha(transparent fill) - Images:
DrawImageScaled(stretch),DrawImageAlpha(transparency) - Clipping:
PushDrawEllipse,PushDrawRoundRect,PushDrawPolygon(undo withPopDrawRegion) - State:
Save()/Restore()for stroke, font and clip region - Text:
TextRectEllipsis(cuts long text with "...") - Mouse:
PaintBox.SetOnMouseDown,SetOnMouseUp,SetOnDoubleClick(withMouseButton); dragging keeps reportingSetOnMouseMoveoutside the box
TreeView/TreeNode- hierarchical list (Add,Selected,SetOnSelect,SetOnDoubleClick,Expand,Collapse,ExpandAll,Remove,Tag)PopupMenu- context menus;Window.SetContextMenu(menu)andcontrol.SetContextMenu(menu)open on right click, or callmenu.Show(window, x, y)SetToolTip(text)- hover hint, available on every controlToolBar-NewToolBar(parent, x, y, height)withAddButtonandAddSeparator
New examples: canvas_drawing, canvas_mouse, tree_view, context_menu, tooltip, toolbar.
- Drag and drop files:
window.SetOnDropFiles(func(files []string, x, y int) {...}), and the sameSetOnDropFileson any control (the innermost control under the mouse gets the files) - Colored text:
SetTextColor(color)/SetBackgroundColor(color)(andResetTextColor,ResetBackgroundColor) onLabel,CheckBox,RadioButton,GroupBox,EditLine,TextEdit,ComboBoxand the fill of aPanel. Check boxes, radio buttons and group boxes drop visual styles when a text color is set because themed controls ignore it - System tray:
NewTrayIcon()withSetToolTip,SetIcon,SetMenu(*PopupMenu),SetOnClick,SetOnDoubleClick,ShowBalloon(title, text, kind); attach it withwindow.SetTrayIcon(tray).window.SetMinimizeToTray(true),window.SetCloseToTray(true),HideToTray,RestoreFromTray,Quit. The icon comes back by itself when Explorer restarts - Transparent window:
SetAlpha(0..255)for opacity,SetTransparentColor(color)/SetTransparent(true)for a color key (pixels in that color are see-through and click-through) - Headless window:
SetHeadless(true)(no title bar and border) withSetDragByBackground(true)to move it,SetCornerRadius(px)for rounded corners - More window options:
SetTopMost,SetShowInTaskbar,SetMinSize,SetMaxSize
New examples: drag_drop, tray, colored_text, overlay_window.
This is all the code you need to create a window (which does not do much):
package main
import "github.com/2dprototype/wui"
func main() {
wui.NewWindow().Show()
}A graphical designer tool is included for visually creating GUIs. It is located at github.com/2dprototype/wui/cmd/designer.
- Visual Layout: Drag and drop controls onto a window
- Property Editor: Modify control properties in real-time
- Live Preview: See your GUI as you build it
- Code Generation: Export designs as Go source code
- Project Management: Save and load designs as JSON project files
- Font Customization: Configure fonts for individual controls
- Event Handling: Define event handlers (OnPaint, etc.)
- Multiple Controls: Button, Label, CheckBox, RadioButton, Slider, ProgressBar, EditLine, TextEdit, ComboBox, Panel, PaintBox, IntUpDown, FloatUpDown, GroupBox, TabControl, DatePicker, StatusBar
- Full support for the new features: color pickers for text/background/key color, window options (transparency, headless via Has Border, corner radius, top most, taskbar, drag move, tray, drop files),
OnClickandOnDropFilesevent editors, copy / cut / paste / duplicate - Responsive: works on small screens. The toolbox and the property panel hide automatically when the window is narrow (
F2/F3toggle them,F4goes back to automatic), both scroll with the mouse wheel, the preview pans with the wheel (Shift for sideways) and project files can be dropped onto the designer to open them
| Shortcut | Action |
|---|---|
Ctrl+N |
New Project |
Ctrl+O |
Open Project (JSON) |
Ctrl+S |
Save Project (JSON) |
Ctrl+Shift+S |
Save Project As (JSON) |
Ctrl+E |
Export as Go Code |
Ctrl+J |
Export as JSON |
F5 |
Run Preview |
Del |
Delete Selected Control |
Ctrl+D |
Duplicate selected control |
Ctrl+C / Ctrl+X / Ctrl+V |
Copy / cut / paste control |
F2 / F3 / F4 |
Toggle toolbox / toggle properties / automatic layout |
F1 |
About |
Ctrl+F1 |
Keyboard Shortcuts Reference |
Projects are saved as JSON files with the following structure:
{
"windows": [
{
"name": "window",
"type": "Window",
"props": [
{"name": "Title", "value": "My Window"},
{"name": "InnerWidth", "value": 400},
{"name": "InnerHeight", "value": 300}
],
"font": {
"name": "Tahoma",
"height": -11,
"bold": false,
"italic": false,
"underlined": false,
"striked_out": false
},
"children": [
{
"name": "button1",
"type": "Button",
"props": [
{"name": "Text", "value": "Click Me"},
{"name": "X", "value": 10},
{"name": "Y", "value": 10},
{"name": "Width", "value": 100},
{"name": "Height", "value": 25}
]
}
]
}
],
"events": [
{
"control_name": "paintBox1",
"event_name": "OnPaint",
"code": "func(canvas *wui.Canvas) {\n\tcanvas.FillRect(0, 0, 100, 100, wui.RGB(255, 0, 0))\n}"
}
]
}github.com/2dprototype/wui/wml loads window layouts from XML files at run
time, similar to QML or XAML. The layout contains data only; events refer to
Go functions by name.
<wml version="1">
<Window Name="main" Title="Login" InnerSize="400,300">
<EditLine Name="user" Bounds="80,10,300,22"/>
<Button Text="Login" Bounds="300,260,90,26" OnClick="doLogin"/>
</Window>
</wml>type form struct {
Window *wui.Window `wml:"main"`
User *wui.EditLine `wml:"user"`
}
doc, err := wml.ParseFile("login.xml") // validated, with line and column in errors
var f form
_, err = doc.Build(&f, wml.Handlers{"doLogin": func() { println(f.User.Text()) }})
f.Window.Show()See wml/README.md for the format reference. go run ./cmd/wmlcheck file.xml validates a layout without opening a window, and
examples/wml_login is a complete program.
go get github.com/2dprototype/wui- Go 1.16 or later
- Windows operating system (uses native Windows API)
This version includes several enhancements over the original gonutz/wui:
- JSON Project Files: Save and load complete GUI designs
This project maintains the same license as the original work. See the LICENSE file for details.
Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.
Special thanks to gonutz for creating the original wui library that made this project possible.
Many controls and features were added (ListView, RichEdit, NativeToolBar, layouts,
DPI awareness, Window.Invoke, ...). See docs/NEW_FEATURES.md
and examples/showcase. That code has not been compiled yet, read the note there.