Create a Haxe Native GUI GTK App

John Gabriele

2019-07

This is a quick guide to creating native GUI apps on GNU/Linux using Haxe.

We’ll be using the popular HaxeUI framework, with its wxWidgets back-end for native GTK3 widgets.

Note that Haxe (and thus HaxeUI) and wxWidgets are cross-platform, and so you’ll be able to build and run your GUI app most anywhere, but the specific focus of this doc is doing so on Debian GNU/Linux.

Prerequisites

Haxe

If you don’t already have Haxe installed, see my Haxe setup doc.

Build Tools

Make sure you have the usual build tools present (gcc, g++, make, etc.). One way to get them is via apt install build-essential.

wxWidgets

To install wxWidgets, you have two choices.

1. Most recent release

Use the latest (v3.1.2) release of wx available, as it will likely work more smoothly with HaxeUI. We’ll build from source, and the wx folks make it easy.

First, if you don’t have these prereqs, install them:

apt install libgtk-3-dev freeglut3-dev

To install, download the tar.bz2 and proceed as follows:

mv wxWidgets-3.1.2.tar.bz2 ~/opt
cd ~/opt
tar xjf wxWidgets-3.1.2.tar.bz2
cd wxWidgets-3.1.2/
mkdir gtk-build
cd gtk-build/
../configure --with-opengl
make  # this will take a little while...

# Then, as root:
make install
ldconfig

Confirm your version of wx:

$ wx-config --version
3.1.2

Keep that ~/opt/wxWidgets-3.1.2/gtk-build directory around. If you ever want to uninstall, as root, do:

make uninstall

2. Older version

You can instead install the slightly older 3.0.4 release via apt:

apt install libwxgtk3.0-gtk3-dev

Note: the libwxgtk3.0-gtk3-dev package makes use of GTK3, whereas the libwxgtk3.0-dev package uses GTK2.

Check your version with the wx-config tool:

$ wx-config --version
3.0.4

Note, though, that this version of wx may not work as smoothly with HaxeUI as wx 3.1.2.

hxcpp and hscript

Since we’ll be generating C++ code (wxWidgets being a C++ GUI toolkit), install the runtime support for the c++ backend of the haxe compiler:

haxelib install hxcpp

and we’ll need this as well:

haxelib install hscript

Install HaxeUI

HaxeUI for wxWidgets comes in three separate parts: haxeui-core → haxeui-hxwidgets → hxWidgets:

Install hxWidgets

Since we already have wxWidgets installed, install the next layer up, hxWidgets:

haxelib install hxWidgets

At this point, even though we haven’t yet installed the higher-level parts of HaxeUI, we can still build and run the hxWidgets “Showcase” demo app to make sure everything is set up correctly thus far. Do so:

# Make a ~/temp directory if you don't already have one.
cd ~/haxelib
cp -r hxWidgets ~/temp
cd ~/temp/hxWidgets/1,0,8/samples/00-Showcase
haxe build.hxml
# compiling ... compiling ... compiling ...
./bin/Main

and you should see:

hxWidgets Showcase
hxWidgets Showcase

Woo!

Install the rest of HaxeUI

Install haxeui-hxwidgets and haxeui-core libraries. At this time, since the 1.0 release has not yet landed, we’ll need to install a particular branch of these libs straight from github. Thankfully, haxelib can handle this:

haxelib git haxeui-hxwidgets https://github.com/haxeui/haxeui-hxwidgets new-component-method
haxelib remove haxeui-core
haxelib git haxeui-core https://github.com/haxeui/haxeui-core new-component-method

Hello World!

A handy way to start a hello-world app is to do:

cd ~/dev
mkdir my-gui-proj
cd my-gui-proj
haxelib run haxeui-core create hxwidgets

which will get you:

.
├── assets
│   └── main.xml
├── hxwidgets.hxml
└── src
    ├── haxeui-hxwidgets.properties
    └── Main.hx

Check out the contents of those files, and when you’re ready, build your project:

haxe hxwidgets.hxml

This first time through, it will take a few minutes to build everything (including HaxeUI).

Run your gui app:

./build/hxwidgets/Main

and, after resizing, you should see something like:

HaxeUI Hello World
HaxeUI Hello World

Next Steps

todo: HaxeUI tutorial