Create a Haxe Native GUI GTK App

John Gabriele

2020-05

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

We’ll install the required packages from the bottom up.

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 (preferred)

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

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

apt install libgtk-3-dev freeglut3-dev

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

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

# Then, in that same directory, as root:
make install
ldconfig

Confirm your version of wx:

$ wx-config --version
3.1.3

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

make uninstall

2. Older version

You can instead install the slightly older 3.0.5 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.5

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

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,1,3/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:

haxelib install haxeui-hxwidgets

That will automatically install, as a dependency, haxeui-core as well.

Set up an alias

HaxeUI comes with a command to help you manage your HaxeUI projects, and you execute it like so: haxelib run haxeui-core {command}. This is a handful to type, so create a handy alias in your ~/.bashrc:

alias haxeui='haxelib run haxeui-core'

Hello World!

Use haxeui create to create a new starter hello-world app:

cd ~/dev
mkdir my-gui-proj
cd my-gui-proj
haxeui 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

Well, I’ve started a HaxeUI tutorial, but it’s still rough and incomplete.