phoenix::Tutorial - Example Application

Here is a small, "Hello, World!" example in phoenix.

#include <phoenix/phoenix.hpp>
using namespace nall;
using namespace phoenix;

struct Application : Window {
  VerticalLayout layout;
  Label helloLabel;
  HorizontalLayout controlLayout;
  Button okButton;
  Button quitButton;

  void create() {
    setTitle("Test Application");
    setGeometry({ 128, 128, 640, 480 });

    helloLabel.setText("Hello, world!");
    okButton.setText("Ok");
    quitButton.setText("Quit");

    layout.setMargin(5);                         //layout border in pixels
    layout.append(helloLabel, {~0, 0}, 5);       //width, height, optional spacing
    controlLayout.append(okButton, {~0, 0}, 5);  //width, height of  0 = use least amount of space possible to display all text
    controlLayout.append(quitButton, {~0, 0});   //width, height of ~0 = use all available width (divides when multiple controls use ~0)
    layout.append(controlLayout, {~0, 0});       //nested layouts inside of other layouts (can accept optional spacing parameter)
    append(layout);                              //both buttons will take 50% of available window client width

    onClose = quitButton.onActivate = &OS::quit;
    okButton.onActivate = [&] { MessageWindow::information(*this, "Hello, world!"); };

    setVisible();
  }
} application;

int main() {
  application.create();
  OS::main();
  return 0;
}