Giter Site home page Giter Site logo

gform's Introduction

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(nil)
mainWindow.SetPos(300, 100)
mainWindow.SetSize(500, 300)
mainWindow.SetCaption("Controls Demo")

btn := gform.NewPushButton(mainWindow)
btn.SetPos(10, 10)
btn.OnLBUp().Bind(btn_onclick)

mainWindow.Show()

gform.RunMainLoop()

2. Create dialog in resource file and attach to it.

gform.Init()

dialog := gform.NewDialogFromResId(nil, 101) //101 is the resource Id.
dialog.Center()
dialog.Show()

edt = gform.AttachEdit(dialog, 1000)
edt.SetCaption("Hello")

btn := gform.AttachPushButton(dialog, 2)
btn.OnLBDown().Attach(onclick)

gform.RunMainLoop()

Event handling

gform provides two approaches to handle event. For most commonly used events, convenient event handler is introduced. To handle windows message directly, "Bind" mechanism is introduce.

1. Convenient event handler.

These kind of event handler follows the same naming convention, "OnSomething".

btn.OnLBUp().Bind(btn_onclick) //LB means Left Button.
btn.OnMBUp //MB means middle button
btn.OnKillFocus
btn.OnDropFiles
...

If you bind two methods for one event, the first bind will be overwritten by later bind. E.g.

btn.OnLBUp().Bind(btn_onclick1)
btn.OnLBUp().Bind(btn_onclick2)

Only "btn_onclick2" will be triggered.

You can also bind "nil" to a event handler, that simply means nothing will be triggered.

2. Raw windows message handler.

It's a common case that we need to handler various windows messages in GUI, and to wrap them all is basically "mission impossible" (and I don't think a GUI framework should do that frankly), so gform leaves the freedom to user. The "Bind" method could bind an event handler directly to a raw windows message. E.g.

btn.Bind(w32.WM_CLIPBOARDUPDATE, btn_onClipboardUpdate)

func btn_onClipboardUpdate(arg *EventArg) {
    sender := arg.Sender()
    if data, ok := arg.Data().(*gform.RawMsg); ok {
        println(data.Hwnd, data.Msg, data.WParam, data.LParam)
    }
}

The event handler uses the same method signature "func(arg *EventArg)", but a new struct named "RawMsg" will be filled to the "data" field of EventArg.

type RawMsg struct {
    Hwnd           w32.HWND
    Msg            uint
    WParam, LParam uintptr
} 

The same with convenient event handler, if you bind two methods for one event, the first bind will be overwritten by later bind. And bind "nil" to a message is allowed.

Setup

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

  2. go get github.com/AllenDang/gform

  3. go install github.com/AllenDang/gform

Have fun now!

Recommand Tools

  1. ResEdit - very good tool to edit resource file, strongly recommand! http://www.resedit.net/

  2. windres - tools to compile *.rc file to *.o which makes it is possible to embed resource file into *.exe.

Contribute

Contributions in form of design, code, documentation, bug reporting or other ways you see fit are very welcome.

Thank You!

gform's People

Contributors

allendang avatar hfinucane avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.