gui

package module
v0.0.0-...-e0ede49 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2020 License: MIT Imports: 9 Imported by: 0

README

Webview-GUI

Webview GUI allows you to easily create a GUI for your Golang project using HTML and Javascript. The resulting GUI will work on Linux (WebKitGTK+2) or Windows (Edge). Functions you register in your Go code will be available to use in JavaScript.

Webview Gui is based on the C/C++ files from Boscop/web-view a fork of zserge/webview. These projects use the MIT License. The code can be found in the webview-sys directory.

Download Prebuilt Example

Linux (requires libwebkit2gtk-4.0, built on Ubuntu) Windows (Built on Windows 10 64bit)

Example Code

This example shows how to call a Golang function from Javascript. This Go code creates a window and registers Calculator.Evaluate().

func main() {

	g := gui.NewGui("Calculator", string(asset), 400, 460, false, false)

	g.Register(new(Calculator))
	g.Run()

}

type Reply struct {
	Result string
}

type Calculator struct{}

func (t *Calculator) Evaluate(input string, reply *Reply) (err error) {

	res, err := compute.Evaluate(input)
	if err != nil {
		return err
	}
	reply.Result = strconv.FormatFloat(res, 'G', 15, 64)

	return nil
}

The Javascript to call this function is as follows. Calculator.Evaluate() returns a promise.

Calculator.Evaluate(calc).then((reply) => {

    // success, answer in reply.Result

}).catch((err) => {

    // error 

})

Windows DLL Build Instructions

Windows requires the webview_edge.dll to be in the same directory as the executable. You can build this using the instructions in webview-gui/webview-sys or use the precompiled version also found in that directory.

If you wish to build the Windows DDL it requires that Visual Studio is installed on your system with the MSVC component selected. Run the following command in the 'webview-sys' directory using 'x64 Native Tools Command Prompt for VS 2019'.

cl /LD /EHsc /DLL /std:c++17 -DUNICODE -D_UNICODE webview_edge.cpp

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlertArgs

type AlertArgs struct {
	Title   string
	Message string
}

type CallbackFunc

type CallbackFunc func(data string)

type ColorRGBArgs

type ColorRGBArgs struct {
	R, G, B uint8
}

type Gui

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

func NewGui

func NewGui(title string, html string, width, height int, resizeable bool, debug bool) (g *Gui)

New Gui

func (*Gui) DialogAlertError

func (g *Gui) DialogAlertError(title string, message string)

func (*Gui) DialogAlertInfo

func (g *Gui) DialogAlertInfo(title string, message string)

func (*Gui) DialogAlertWarning

func (g *Gui) DialogAlertWarning(title string, message string)

func (*Gui) DialogOpenDirectory

func (g *Gui) DialogOpenDirectory(title string) (path string)

func (*Gui) DialogOpenFile

func (g *Gui) DialogOpenFile(title string) (path string)

func (*Gui) DialogSaveFile

func (g *Gui) DialogSaveFile(title string) (path string)

func (*Gui) Dispatch

func (g *Gui) Dispatch(function func())

send func() to the dispatch channel and call dispatch() dispatch() is an exported Go function called by C on the main thread

func (*Gui) Eval

func (g *Gui) Eval(js string)

runs JS in the browser

func (*Gui) Register

func (g *Gui) Register(rcvr interface{}) error

Registerexports the the receiver's methods to JS

func (*Gui) RegisterName

func (g *Gui) RegisterName(name string, rcvr interface{}) error

RegisterName is like register but uses the provided name

func (*Gui) Run

func (g *Gui) Run()

Run Gui

func (*Gui) SetColorRGB

func (g *Gui) SetColorRGB(red, green, blue uint8)

func (*Gui) SetFullScreen

func (g *Gui) SetFullScreen(fullscreen bool)

func (*Gui) SetTitle

func (g *Gui) SetTitle(title string)

func (*Gui) Terminate

func (g *Gui) Terminate()

type GuiExport

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

func (*GuiExport) DialogAlertError

func (g *GuiExport) DialogAlertError(args *AlertArgs, reply *struct{}) error

func (*GuiExport) DialogAlertInfo

func (g *GuiExport) DialogAlertInfo(args *AlertArgs, reply *struct{}) error

func (*GuiExport) DialogAlertWarning

func (g *GuiExport) DialogAlertWarning(args *AlertArgs, reply *struct{}) error

func (*GuiExport) DialogOpenDirectory

func (g *GuiExport) DialogOpenDirectory(title string, reply *PathReply) error

func (*GuiExport) DialogOpenFile

func (g *GuiExport) DialogOpenFile(title string, reply *PathReply) error

func (*GuiExport) DialogSaveFile

func (g *GuiExport) DialogSaveFile(title string, reply *PathReply) error

func (*GuiExport) SetColorRGB

func (g *GuiExport) SetColorRGB(args ColorRGBArgs, reply *struct{}) error

func (*GuiExport) SetFullScreen

func (g *GuiExport) SetFullScreen(fullScreen bool, reply *struct{}) error

func (*GuiExport) SetTitle

func (g *GuiExport) SetTitle(title string, reply *struct{}) error

func (*GuiExport) Terminate

func (g *GuiExport) Terminate(args struct{}, reply *struct{}) error

type PathReply

type PathReply struct {
	Path string
}

Directories

Path Synopsis
examples
rpc
Package rpc provides access to the exported methods of an object across a network or other I/O connection.
Package rpc provides access to the exported methods of an object across a network or other I/O connection.

Jump to

Keyboard shortcuts

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