Skip to content

george012/fltk_go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Document


1. fltk_go source

  • Forked from pwiecz/go-fltk with commit hash 5313f8a5a643c8b4f71dabd084cefb9437daa8a7 rebased
  • A simple wrapper around the FLTK 1.4 library, a lightweight GUI library that allows creating small, standalone and fast GUI applications.

2. Usage

2.1. Dependencies

  • To build fltk_go, in addition to the Golang compiler, you also need a C++11 compiler,

  • GCC or Clang on Linux

  • MinGW64 on Windows

  • XCode on MacOS.

  • fltk_go comes with prebuilt FLTK libraries for some architectures (linux/amd64, windows/amd64), but you can easily rebuild them yourself, or build them for other architectures. To build the FLTK library for your platform, just run go generate from the root of the fltk_go source tree.

  • To run programs built with fltk_go, you will need some system libraries that are typically available on operating systems with a graphical user interface:

  • Windows: no external dependencies except mingw64 (msys2's mingw64 is recommended)

  • MacOS: no external dependencies

  • Linux (and other untested Unix systems): you will need:

  • X11

  • Xrender

  • Xcursor

  • Xfixes

  • Xext

  • Xft

  • Xinerama

  • OpenGL

2.2. Usage

  • You can use the fltk_go.New<WidgetType> function to create widgets and make modifications to the widget you are instantiating. Function and method names are similar to the original C++ names, but follow the Go language's PascalCase naming convention.

Setter methods are prefixed with Set.

package main

import "github.com/george012/fltk_go"

func main() {
win := fltk_go.NewWindow(400, 300)
win.SetLabel("Main Window")
btn := fltk_go.NewButton(160, 200, 80, 30, "Click")
btn.SetCallback(func() {
btn.SetLabel("Clicked")
})
win.End()
win.Show()
fltk_go.Run()
}

2.3. Styles

FLTK provides 4 built-in styles:

  • base (default)
  • gtk+
  • gleam
  • plastic For example, you can use fltk_go.SetScheme("gtk+") to set these styles.

FLTK Also allows customizing the style of the widget:

package main
import (
"strconv"

"github.com/george012/fltk_go"
)
// FLTK uses RGBI color representation, where I is an index into the FLTK color table
// Passing 00 as I will use RGB values
const GRAY = 0x75757500
const LIGHT_GRAY = 0xeeeeee00
const BLUE = 0x42A5F500
const SEL_BLUE = 0x2196F300
const WIDTH = 600
const HEIGHT = 400

func main() {
curr := 0
fltk_go.InitStyles()
win := fltk_go.NewWindow(WIDTH, HEIGHT)
win.SetLabel("Flutter-like")
win.SetColor(fltk_go.WHITE)
bar := fltk_go.NewBox(fltk_go.FLAT_BOX, 0, 0, WIDTH, 60, " FLTK App!")
bar.SetDrawHandler(func() { // Shadow under the bar
fltk_go.DrawBox(fltk_go.FLAT_BOX, 0, 0, WIDTH, 63, LIGHT_GRAY)
})
bar.SetAlign(fltk_go.ALIGN_INSIDE | fltk_go.ALIGN_LEFT)
bar.SetLabelColor(255) // this uses the index into the color map, here it's white
bar.SetColor(BLUE)
bar.SetLabelSize(22)
text := fltk_go.NewBox(fltk_go.NO_BOX, 250, 180, 100, 40, "You have pushed the button this many times:")
text.SetLabelSize(18)
text.SetLabelFont(fltk_go.TIMES)
count := fltk_go.NewBox(fltk_go.NO_BOX, 250, 180+40, 100, 40, "0")
count.SetLabelSize(36)
count.SetLabelColor(GRAY)
btn := fltk_go.NewButton(WIDTH-100, HEIGHT-100, 60, 60, "@+6plus") // This translates to a plus sign
btn.SetColor(BLUE)
btn.SetSelectionColor(SEL_BLUE)
btn.SetLabelColor(255)
btn.SetBox(fltk_go.OFLAT_BOX)
btn.ClearVisibleFocus()
btn.SetCallback(func() {
curr += 1
count.SetLabel(strconv.Itoa(curr))
})
win.End()
win.Show()
fltk_go.Run()
}

image

Label properties can be viewed here

2.4. Image support

FLTK supports both vector and raster graphics, through several image types:

  • SvgImage
  • RgbImage
  • JpegImage
  • PngImage
  • BmpImage
  • SharedImage

Some of these can be instantiated from image files or data:

package main

import (
"fmt"

"github.com/george012/fltk_go"

func main() {
win := fltk_go.NewWindow(400, 300)
box := fltk_go.NewBox(fltk_go.FLAT_BOX, 0, 0, 400, 300, "")
image, err := fltk_go.NewJpegImageLoad("image.jpg")
if err != nil {
fmt.Printf("An error occurred: %s\n", err)
} else {
box.SetImage(image)
}
win.End()
win.Show()
fltk_go.Run()
}

3. Resources