DMarlon Studio

Chapter 8

C++ with FLTK

Native desktop apps in C++: the same designer, compiled with FLTK.

Creating a C++ app

When you create the app, choose C++ (FLTK). The code goes in Form1.cpp: the Form1 class inherits from FormDesign and every event is a method with override. Every component is a pointer to an FLTK class with simple methods (text, checked, items…), without losing the FLTK API.

class Form1 : public FormDesign {
public:
  void Button1_click() override {
    Label1->text("Hello, " + Entry1->text());
    Status->text("Greeted");
  }

  void Scale1_change(double value) override {
    Bar1->value(value);
  }
};
ComponentMethods
Label, Button, Status bartext(), text(s), enabled(bool), visible(bool), bg(color), fg(color)
Entry, Password, Texttext(), text(s)
Check box, Radio buttonchecked(), checked(bool)
List, Combo boxitems({...}), add(s), index(), index(i), selected()
Scale, Progress barvalue(), value(v)
Page controlpage(), page(i)
TimerTimer1.start(), Timer1.stop()
Open and Save dialogsOpenFile.execute() (the path, or "" if cancelled)
The windowtitle(s), message(text), ask(question), close(); and str(number), readText(path), writeText(path, text)

Build, run and export

  • Run (F9) compiles with the computer's C++ compiler and FLTK, and opens the app. Errors go to the Output tab with their Form1.cpp line.
  • If FLTK or the compiler is missing, the studio says so and offers Install (on macOS, with Homebrew: brew install fltk).
  • Debug compiles with debug information (-g) so you can open build/cpp/app with lldb or gdb.
  • Export the C++ project creates a folder with the sources and a Makefile: make run.