Basic Go bindings for FLTK



This is a simple go wrapper for FLTK2, which I did to support my Go version of Ober (based on Acme), Gober. It's very small and should be fairly easy to extend to support whatever other widgets and functionality you need. Please contribute changes you make. The code is licensed under the very permissive ZLIB license. FLTK2 is only somewhat supported, but I like its mouse-text behavior better than FLTK 1.3's.


  • Good integration with Go -- the way this binding processes events lends itself well to Go programs (I think). since there is not call-in from C to Go, only call-out from Go to C, this runs FLTK in a separate thread in order to allow Go to intercept every event. Go FLTK operations are protected so that they are safe to use in goroutines.
  • Simplicity -- I'm trying to keep the code small, mostly in Go, generic (multipurpose, but not fat), easy to modify, and easy to extend
  • Small and relatively stand-alone -- I wanted a toolkit that only depended on basic X functionality and was relatively small so I could statially link it into the Go package. At this point, fltk.a is 121K and is 312K. Yes, I'm sitting here with a straight face and claiming that this is "small." Widget kits are usually several megabytes, so this is small. Maybe someday this will even be a service instead of a library.


This wrapper is far from complete, and I'm only planning on supporting what I need to do Gober, but I welcome additions to it. In fact, at this point it hardly does anything. I'll flesh things out as I need them for Gober.


  • fltk.Run(while func() bool) runs FLTK until while() returns false. Run() is defined like this: for (while()) {ContinueEvent(Handle(ReadEvent()))}
  • fltk.ReadEvent() returns the next *Event structure read
  • fltk.Handle(event *Event) runs the widget's event handler (if there is one) and returns what the handler returned (1 means the widget used the event, 0 means it did not)
  • fltk.ContinueEvent(status int) allows FLTK to continue processing. If you do not call this, the GUI will hang.

By default, widgets have empty handlers, so you can treat fltk as an event stream if you like, instead of using event handlers (wait for an event, process the event yourself), which may lend itself well to using Go channels, since Go FLTK operations are safe to use in goroutines. That boils down to four ways you can deal with events:

case 1, process an event after the widget handles it:

	user event --> widget --> go event handler

case 2, process an event before the widget handles it (event stealing):

	user event --> go event handler [optionally: --> widget]

case 3, roll your own, with default widget behavior (without an event handler):

	user event --> widget --> roll your own with the current event

case 4, roll your own, with no default widget behavior (stealing without an event handler):

	user event --> roll your own with the current event [optionally: --> widget]

You can install an event handler with widget.SetEventHandler() like this:

input.SetEventHandler(func(e fltk.Event){println(e.Event)}

Normally, the widget processes the event before Wait returns but you can "steal" events so that your event handler will get the event before the widget has a chance to process it. If you want to steal events, call widget.StealEvents() with a bit mask for the FLTK event types. There are constants for the event types and masks for them by appending _MASK to the name, like PUSH_MASK, which is just 1 << PUSH. You call StealEvents() like this:

input.StealEvents((1 << PUSH_MASK) | (1 << DRAG_MASK))

There is a bool field in Event, called "Stolen" to tell you whether the event was stolen. If you want the widget to process the stolen event, just call widget.ContinueEvent(). Here is an example of an event handler that prints a message for stolen push and drag events and then continues them:

i.StealEvents(fltk.PUSH_MASK | fltk.DRAG_MASK)
i.SetEventHandler(func(e fltk.Event) {
	if (e.Stolen) {
		println("CONTINUING EVENT: " + strconv.Itoa(e.Event))

There is an example program, test.go, in the "examples" directory, that steals events from a text field, like this.


The make file SHOULD auto-download and unpack FLTK2 for you. When it builds the Go library, it statically links FLTK into the library so that the only dependencies are -lXext -lXinerama -lXft -lX11 -lXi -lm.

This only runs under X, because of the way I build it, but FLTK purports to run on windows and macs, so if you can test that and help with the Makefile, I'd appreciate it.


To build, run "make" in the top-level directory. This assumes you have g++ installed, because FLTK is written in C++ and you need to use g++ to link the library so it can resolve mangled names.

To install the library, run "make install".

To build the examples, run "make examples".

If you want to eliminate the fltk-library from your directory, you can run "make clean-fltk".


There are two examples: hello and text. Hello is the Hello World program from the FLTK docs and text is a window with a text field in it that steals the PUSH and DRAG events, printing a message and continuing the events.

  • build failure FC12 AMD64

    build failure FC12 AMD64

    cloned the repository (a few minutes ago, 22Nov2010 13:20ish), did a make install. Make downloads fltk and starts compiling. All is well until:

    g++ -Ifltk-2.0.x-r7725 -c fltk.cxx g++ -m64 -o fltk.cgo2.o widget.cgo2.o group.cgo2.o input.cgo2.o texteditor.cgo2.o window.cgo2.o fltk.o fltk-2.0.x-r7725/lib/libfltk2.a -lXext -lXinerama -lXft -lX11 -lXi -lm -shared -lpthread -lm /usr/bin/ld: fltk.o: relocation R_X86_64_32 against `typeinfo for EventStealer' can not be used when making a shared object; recompile with -fPIC fltk.o: could not read symbols: Bad value collect2: ld returned 1 exit status

    Happy to try recompiling with -fPIC if someone can tell me where/how to add it.

    Running Fedora Core 12, system update as of this morning, on an AMD64-style system.

    uname -a output:

    Linux #1 SMP Mon Sep 27 17:23:59 UTC 2010 x86_64 x86_64 x86_64 GNU/Linux


    opened by ehedgehog 2
  • Doesn't build undir Windows using mingw32

    Doesn't build undir Windows using mingw32

    Hi, I succeeded building go-fltk and examples on windows box by slightly tweaking the makefile, but when I try to run examle I get the following panic error.

    throw: cgocall unavailable
    panic PC=0x83a07c
    runtime.throw+0x47 /go/src/pkg/runtime/runtime.c:76
            runtime.throw(0x4de170, 0x0)
    runtime.cgocall+0x32 /go/src/pkg/runtime/cgocall.c:19
            runtime.cgocall(0x0, 0x83a0b4, 0x0)
    fltk._Cfunc_go_fltk_get_UP_BOX+0x32 /development/cvstree/go-fltk/_cgo_defun.c:127
            fltk._Cfunc_go_fltk_get_UP_BOX(0x0, 0x0)
    fltk.init┬╖1+0x1e c:/development/cvstree/go-fltk/fltk.cgo1.go:-58
    fltk.Init┬╖+0x50 c:/development/cvstree/go-fltk/fltk.cgo1.go:169
    main.init+0x46 c:/development/cvstree/go-fltk/examples/hello.go:16
    runtime.mainstart+0x5 386/asm.s:82
    runtime.goexit /go/src/pkg/runtime/proc.c:146

    I suppose the problem is that something is not compiled or linked as it should?

    Here are my modifications to makefiles:

    diff --git a/Makefile b/Makefile index 6b4f159..c1d2753 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ CGOFILES=
    window.go CGO_DEPS=fltk.o

    -CGO_LDFLAGS=fltk.o $(FLTK_LIB) -lXext -lXinerama -lXft -lX11 -lXi -lm
    +CGO_LDFLAGS=fltk.o $(FLTK_LIB) -lm -lpthread -lmsimg32 -lole32 -luuid -lcomctl32 -lwsock32 -lgdi32
     include $(GOROOT)/src/Make.pkg
    @@ -44,7 +44,7 @@ $(FLTK)/stamp: $(FLTK_DIST)
        touch $(FLTK)/stamp
    -   (cd /tmp; wget $(FLTK_URL))
    +   (cd /tmp; curl -C - -O $(FLTK_URL))
        rm -rf $(FLTK)
    diff --git a/examples/Makefile b/examples/Makefile
    index b70a4f1..7ef6e8b 100644
    --- a/examples/Makefile
    +++ b/examples/Makefile
    @@ -4,7 +4,7 @@ pkgdir=$(GOROOT)/pkg/$(GOOS)_$(GOARCH)
     all: $(BINS)
     text hello : % : %.go $(pkgdir)/ $(pkgdir)/fltk.a
    -   8g [email protected] && 8l -o [email protected] [email protected]
    +   8g [email protected] && 8l -o [email protected] [email protected]
        rm -f $(BINS) *.8
    opened by markokocic 5
Bill Burdick
I've been programming since 1978 and I love learning and teaching new things.
Bill Burdick
Tcl/Tk Go bindings

Tcl/Tk Go bindings. VERSION NOTICE Recently Tcl/Tk 8.6 were released. I use them as a default, if you still have Tcl/Tk 8.5 use `go get -tags tcl85

null 140 Jun 20, 2022
Go bindings for GTK3

gotk3 The gotk3 project provides Go bindings for GTK 3 and dependent projects. Each component is given its own subdirectory, which is used as the impo

gotk3 1.8k Jun 28, 2022
Golang bindings of Sciter: the Embeddable HTML/CSS/script engine for modern UI development

Go bindings for Sciter Check this page for other language bindings (Delphi / D / Go / .NET / Python / Rust). Attention The ownership of project is tra

Terra Informatica Software, Inc 2.4k Jun 29, 2022
:traffic_light: Go bindings for libappindicator3 C library

go-appindicator Go bindings for libappindicator3 C library. Libappindicator is a library to allow applications to export a menu into the Unity Menu ba

Dawid Dziurla 20 Jun 19, 2022
Go bindings for GLFW 3

GLFW 3.3 for Go Installation GLFW C library source is included and built automatically as part of the Go package. But you need to make sure you have d

OpenGL with Golang 1.3k Jun 28, 2022
gobbi is a set of generated Go bindings for gtk et al.

gobbi gobject bindings gobbi is a set of generated Go bindings for gobject based libraries. There are bindings, with varying degrees of completeness,

Mike D Pilsbury 29 May 6, 2022
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 All the binding code has automatica

null 1.5k Jun 25, 2022
A GTK4 bindings generator for Go.

gotk4 A GTK4 bindings generator for Go. Progress tracker: All generated packages are in pkg/. The gene

null 189 Jun 28, 2022
Golang bindings for XCGUI, Windows GUI library, DirectUI design idea.

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

twgh 117 Jun 22, 2022
Go bindings for divideon/xvc

go-xvc [WIP] Go bindings for divideon/xvc Requirements requires xvc install on your system $ git clone $ cd xvc $

Yusuke Hata 0 Feb 7, 2022
Basic-api-with-go - A basic api with golang

I am creating my first API with GO. Install go get -u

Yefhem 1 Jan 3, 2022
Go-basic-graphql - Basic implementation of GraphQL using Go

Go-basic-graphql - Basic implementation of GraphQL using Go

Luis Felipe Ribeiro 0 Jan 29, 2022
🔥 Golang Rest Api with basic JWT Authentication and Basic Crud Operations.

?? Golang Rest Api with basic JWT Authentication and Basic Crud Operations.

Junaid Javed 13 Jun 15, 2022
Go-basic-skeleton - Simple and basic skeleton for go projects

Go Bootstrap (base/skeleton) Introduction This is a repository intended to serve

Kenrique Ortega 2 Mar 16, 2022
libsox bindings for go

gosox "SoX − Sound eXchange, the Swiss Army knife of audio manipulation" Go bindings for the libsox sound library For more information and documentati

Kristoffer Grönlund 123 Apr 9, 2022
Go bindings for the PortAudio audio I/O library

portaudio This package provides an interface to the PortAudio audio I/O library. See the package documentation for details. To build this package you

Gordon Klaus 507 Jun 20, 2022
Go bindings for libportmidi

portmidi Want to output to an MIDI device or listen your MIDI device as an input? This package contains Go bindings for PortMidi. libportmidi (v. 217)

Jaana Dogan 267 Jun 28, 2022
Golang bindings for the Telegram Bot API

Golang bindings for the Telegram Bot API All methods are fairly self explanatory, and reading the godoc page should explain everything. If something i

null 3.8k Jun 29, 2022
OpenSSL bindings for Go

OpenSSL bindings for Go Please see for more info License Copyright (C) 2017. See AUTHORS. Licensed u

Space Monkey Go 436 Jun 1, 2022
Golang bindings for libxlsxwriter for writing XLSX files

goxlsxwriter provides Go bindings for the libxlsxwriter C library. Install goxlsxwriter requires the libxslxwriter library to be installe

Frank Terragna 18 Jun 27, 2022
Go bindings for ForestDB

goforestdb Go bindings for ForestDB Building Obtain and build forestdb: (run make install to install the lib

null 32 Apr 5, 2022
Go bindings for GLib type system.

Go bindings for GLib type system. This package is designed for building bindings to C libraries based on GLib type system (like GTK, GStreamer, and ot

Michał Derkacz 24 Aug 13, 2019
Source code editor written in Go using go-gtk bindings. It aims to handle navigation effectively among large number of files.

tabby Source code editor written in Go using go-gtk bindings. It aims to handle navigation effectively among large number of files. screenshot: depend

Mikhail Trushnikov 49 Dec 30, 2021
Duktape JavaScript engine bindings for Go

Duktape bindings for Go(Golang) Duktape is a thin, embeddable javascript engine. Most of the api is implemented. The exceptions are listed here. Usage

Oleg Lebedev 780 Jun 27, 2022
PHP bindings for the Go programming language (Golang)

PHP bindings for Go This package implements support for executing PHP scripts, exporting Go variables for use in PHP contexts, attaching Go method rec

Alex Palaistras 862 Jun 26, 2022
naive go bindings to the CPython C-API

go-python Naive go bindings towards the C-API of CPython-2. this package provides a go package named "python" under which most of the PyXYZ functions

Sebastien Binet 1.4k Jun 24, 2022
Go bindings for Lua C API - in progress

Go Bindings for the lua C API Simplest way to install: # go get You can then try to run the examples: $ cd golua/_examp

Alessandro Arzilli 588 Jun 13, 2022
Go bindings for libmagic to detect MIME types

magicmime magicmime is a Go package which allows you to discover a file's mimetype by looking for magic numbers in its content. It could be used as a

Jaana Dogan 208 Jun 4, 2022
Go bindings for raylib, a simple and easy-to-use library to enjoy videogames programming.

raylib-go Golang bindings for raylib, a simple and easy-to-use library to enjoy videogames programming. Requirements Ubuntu X11 apt-get install libgl1

Milan Nikolic 810 Jun 22, 2022