Skip to content
Otavio edited this page Jul 23, 2021 · 9 revisions

Button

Introduction:

Buttons is a widget used to trigger a specific callback (Function).

How it works:

When a callback is set, whenever you click the Button widget it will trigger that callback, in other words it will call the function that you set for your button.

Example:

You will need to declare a pointer for your widget and to initialize it:

std::shared_ptr<FGUI::CButton> Button;

You'll also need a callback to trigger.

void MyCustomCallback() {

  ICVar->ConsoleColorPrintf(255, 255, 0, 255, "callback called!\n");

}

Now you can start setting up your widget usign the Builder Pattern.

FGUI::CBuilder buildrPattern;

// Button
Button = std::make_shared<FGUI::CButton>();
buildrPattern.Widget(Button).Title("Click Me!").Font("Tahoma", 12, true).Callback(MyCustomCallback).SpawnIn(Container);

("MyCustomCallback") is the function that you want to trigger when clicking the Button.

Result:

callback called!


What's next?

Next you will learn about the CheckBox Widget.