Common library for Go GUI apps on Windows

winc

Common library for Go GUI apps on Windows. It is for Windows OS only. This makes library smaller than some other UI libraries for Go.

Design goals: minimalism and simplicity.

Dependencies

No other dependencies except Go standard library.

Building

If you want to package icon files and other resources into binary rsrc tool is recommended:

rsrc -manifest app.manifest -ico=app.ico,application_edit.ico,application_error.ico -o rsrc.syso

Here app.manifest is XML file in format:



    
    
        
            
        
    

Most Windows applications do not display command prompt. Build your Go project with flag to indicate that it is Windows GUI binary:

go build -ldflags="-H windowsgui"

Samples

Best way to learn how to use the library is to look at the included examples projects.

Setup

  1. Make sure you have a working Go installation and build environment, see more for details on page below. http://golang.org/doc/install

  2. go get github.com/tadvi/winc

Icons

When rsrc is used to pack icons into binary it displays IDs of the packed icons.

rsrc -manifest app.manifest -ico=app.ico,lightning.ico,edit.ico,application_error.ico -o rsrc.syso
Manifest ID:  1
Icon  app.ico  ID:  10
Icon  lightning.ico  ID:  13
Icon  edit.ico  ID:  16
Icon  application_error.ico  ID:  19

Use IDs to reference packed icons.

const myIcon = 13

btn.SetResIcon(myIcon) // Set icon on the button.

Included source examples use basic building via release.bat files. Note that icon IDs are order dependent. So if you change they order in -ico flag then icon IDs will be different. If you want to keep order the same, just add new icons to the end of -ico comma separated list.

Layout Manager

SimpleDock is default layout manager.

Current design of docking and split views allows building simple apps but if you need to have multiple split views in few different directions you might need to create your own layout manager.

Important point is to have one control inside SimpleDock set to dock as Fill. Controls that are not set to any docking get placed using SetPos() function. So you can have Panel set to dock at the Top and then have another dock to arrange controls inside that Panel or have controls placed using SetPos() at fixed positions.

Example layout with two toolbars and status bar

This is basic layout. Instead of toolbars and status bar you can have Panel or any other control that can resize. Panel can have its own internal Dock that will arrange other controls inside of it.

Example layout with two toolbars and navigation on the left

This is layout with extra control(s) on the left. Left side is usually treeview or listview.

The rule is simple: you either dock controls using SimpleDock OR use SetPos() to set them at fixed positions. That's it.

At some point winc may get more sophisticated layout manager.

Dialog Screens

Dialog screens are not based on Windows resource files (.rc). They are just windows with controls placed at fixed coordinates. This works fine for dialog screens up to 10-14 controls.

Minimal Demo

package main

import (
	"github.com/tadvi/winc"
)

func main() {
	mainWindow := winc.NewForm(nil)
	mainWindow.SetSize(400, 300)  // (width, height)
	mainWindow.SetText("Hello World Demo")

	edt := winc.NewEdit(mainWindow)
	edt.SetPos(10, 20)
	// Most Controls have default size unless SetSize is called.
	edt.SetText("edit text")

	btn := winc.NewPushButton(mainWindow)
	btn.SetText("Show or Hide")
	btn.SetPos(40, 50)	// (x, y)
	btn.SetSize(100, 40) // (width, height)
	btn.OnClick().Bind(func(e *winc.Event) {
		if edt.Visible() {
			edt.Hide()
		} else {
			edt.Show()
		}
	})

	mainWindow.Center()
	mainWindow.Show()
	mainWindow.OnClose().Bind(wndOnClose)

	winc.RunMainLoop() // Must call to start event loop.
}

func wndOnClose(arg *winc.Event) {
	winc.Exit()
}

Hello World

Result of running sample_minimal.

Create Your Own

It is good practice to create your own controls based on existing structures and event model. Library contains some of the controls built that way: IconButton (button.go), ErrorPanel (panel.go), MultiEdit (edit.go), etc. Please look at existing controls as examples before building your own.

When designing your own controls keep in mind that types have to be converted from Go into Win32 API and back. This is usually due to string UTF8 and UTF16 conversions. But there are other types of conversions too.

When developing your own controls you might also need to:

import "github.com/tadvi/winc/w32"

w32 has Win32 API low level constants and functions.

Look at sample_control for example of custom built window.

Companion Package

Go package for Windows Systray icon, menu and notifications

Credits

This library is built on

AllenDang/gform Windows GUI framework for Go

winc takes most design decisions from gform and adds many more controls and code samples to it.

Owner
Comments
  • Support for new features

    Support for new features

    Hi there!

    I've been busy building out some support for new features specific to my use case. I'm sure that not all will be useful to the main project, but here's a PR anyway that you can cherry pick from.

    Cheers.

  • OnDropFiles how to get filenames?

    OnDropFiles how to get filenames?

    I enabled parameter for mainWindow to mainWindow.EnableDragAcceptFiles(true) and was listening event

        mainWindow.OnDropFiles().Bind(func(e *winc.Event) {
            fmt.Println(mainWindow)
        })
    

    how can I get filenames droped to form ( get DropFilesEventData )?

  • Play/Pause button

    Play/Pause button

    If someone else uses this library, please help implement the play-pause buttons to pause the program. I tried this implementation - https://stackoverflow.com/questions/38798863/golang-pause-a-loop-in-a-goroutine-with-channels but either it doesn't work as it should, or it freezes.

  • Context menu button, auto scrolling

    Context menu button, auto scrolling

    This is a cool library, but I can't figure out how to do it:

    • context menu in the form of a button anywhere in the window. (In the examples, there is only if you right-click on a certain area, or only at the top of the window - File, Edit, etc.)
    • add scrolling for the context menu, for long lists;
    • automatically scroll down when adding a new line in NewMultiEdit (or other).
  • gui not responding for long time job

    gui not responding for long time job

    Hi 3 questions,in case others meet the same question,open an issue

    • for a long time job,such as network diagnose,gui will be not responding,I know there must exist a method to resolve it,maybe another thread or gorourine
    • I wanna something like static text to display output from some job,maybe a Rect or Canvas?
    • I wanna fix the window size,it cannot be scaled or maximum
  • Printing

    Printing

    Awesome library !

    I want to add the ability to Output to a PDF for all your Windows Controls. This would require making a Window which is alot like the Chrome Print Preview Page, where you have the Printer options on the left and a PDF view of the output like a a4 landscape or portrait, Colour or Black and white.

    Like this: https://techdows.com/wp-content/uploads/2011/04/enable-print-preview-in-google-chrome.png

    The first bit is to be able to query for all printers and their options. The 2nd bit it to just make your controls be able to output as a PDF. I think i can do that myself. The 3rd bit is to then just display the PDF in the right side of the pane as a raster. that is easy as its easy to convert a PDF to raster image using golang.

    SO the main bit of to get all printer and their options. I think maybe we can use the google Printer lib ?

    https://github.com/google/cloud-print-connector/blob/master/winspool/win32.go

Golang bindings for XCGUI, Windows GUI library, DirectUI design idea.
Golang bindings for XCGUI, Windows GUI library, DirectUI design idea.

XCGUI 项目文档 帮助文档 程序示例 介绍 English | 简体中文 DirectUI设计思想: 在窗口内没有子窗口,界面元素都是逻辑上的区域(无HWND句柄,安全,灵活), 所有UI元素都是自主开发(不受系统限制), 更加灵活的实现各种程序界面,满足不同用户的需求.

Dec 22, 2022
Build cross platform GUI apps with GO and HTML/JS/CSS (powered by Electron)

Thanks to go-astilectron build cross platform GUI apps with GO and HTML/JS/CSS. It is the official GO bindings of astilectron and is powered by Electr

Jan 9, 2023
Build cross platform GUI apps with GO and HTML/JS/CSS (powered by nwjs)
Build cross platform GUI apps with GO and HTML/JS/CSS (powered by nwjs)

gowd Build cross platform GUI apps with GO and HTML/JS/CSS (powered by nwjs) How to use this library: Download and install nwjs Install this library g

Dec 11, 2022
Kita is a declarative, reactive GUI toolkit for build cross platform apps with web technology with single codebase
Kita is a declarative, reactive GUI toolkit for build cross platform apps with web technology with single codebase

Kita is a declarative, reactive GUI toolkit for build cross platform apps with web technology with single codebase. Inspired by Flutter, React. S

Apr 18, 2022
UIKit - A declarative, reactive GUI toolkit for build cross platform apps with web technology with single codebase
 UIKit - A declarative, reactive GUI toolkit for build cross platform apps with web technology with single codebase

UIKit - A declarative, reactive GUI toolkit for build cross platform apps with web technology with single codebase

Apr 18, 2022
A Windows GUI toolkit for the Go Programming Language
A Windows GUI toolkit for the Go Programming Language

About Walk Walk is a "Windows Application Library Kit" for the Go Programming Language. Its primarily useful for Desktop GUI development, but there is

Dec 30, 2022
Windows GUI framework for Go.

gform is an easy to use Windows GUI toolkit for Go It provides two approaches to create UI. 1. Pure code. gform.Init() mainWindow := gform.NewForm(ni

Jan 1, 2023
Windows API and GUI in idiomatic Go.
Windows API and GUI in idiomatic Go.

Windigo Win32 API and GUI in idiomatic Go. Overview The UI library is divided in the following packages: Package Description ui High-level UI wrappers

Dec 27, 2022
An example desktop system tray application that can launch HTML5 windows. Go source with a build process for Windows, Mac and Linux.

ExampleTrayGUI An example cross-platform (Mac, Windows, Linux) system tray application that can launch HTML5 windows, developed in Go including functi

Dec 3, 2022
An example desktop system tray application that can launch HTML5 windows. Go source with a build process for Windows, Mac and Linux.

ExampleTrayGUI An example cross-platform (Mac, Windows, Linux) system tray application that can launch HTML5 windows, developed in Go including functi

Dec 3, 2022
An example desktop system tray application that can launch HTML5 windows. Go source with a build process for Windows, Mac and Linux.

An example cross-platform (Mac, Windows, Linux) system tray application that can launch HTML5 windows, developed in Go including functional build process. This repository is intended as a quick reference to help others start similar projects using the referenced libraries and will not be actively maintained.

Dec 3, 2022
An example desktop system tray application that can launch HTML5 windows. Go source with a build process for Windows, Mac and Linux.

ExampleTrayGUI An example cross-platform (Mac, Windows, Linux) system tray application that can launch HTML5 windows, developed in Go including functi

Dec 3, 2022
W32find - Find parent windows and their children windows using win32api.

w32find Package w32find provides a set of interface to win32 APIs that can be used to find windows and their controls. Install go get -v github.com/mo

Jan 5, 2022
Platform-native GUI library for Go.

ui: platform-native GUI library for Go This is a library that aims to provide simple GUI software development in Go. It is based on my libui, a simple

Jan 9, 2023
This project provides Go bindings for nuklear.h — a small ANSI C GUI library.
This project provides Go bindings for nuklear.h — a small ANSI C GUI library.

Nuklear Package nk provides Go bindings for nuklear.h — a small ANSI C gui library. See github.com/vurtun/nuklear. All the binding code has automatica

Jan 1, 2023
Cross-platform Go/Golang GUI library.

中文 | English GoVCL Cross-platform Golang GUI library, The core binding is liblcl, a common cross-platform GUI library created by Lazarus. GoVCL is a n

Dec 30, 2022
Cross platform GUI in Go based on Material Design
Cross platform GUI in Go based on Material Design

About Fyne is an easy to use UI toolkit and app API written in Go. It is designed to build applications that run on desktop and mobile devices with a

Jan 3, 2023
Go wrapper around the Iup GUI toolset

Iup Go Wrapper iup is a Go wrapper around the Iup GUI toolkit. The project was started on April 27, 2011. Fork https://github.com/grd/iup is a fork of

Nov 28, 2020
Go Wrapper for the wxWidgets GUI

This is the source code for wxGo a Go wrapper of the wxWidgets library. The actuall wxWidgets source code is not included and will need to be downloa

Nov 30, 2022