O'Reilly logo

SFML Game Development By Example by Raimondas Pupius

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The core of all elements

The GUI_Element class is the core of every single element and interface. It provides key functionality that higher level objects rely on, as well as enforcing the implementation of necessary methods, which leads to several distinctive element types.

A definition of the different element types is a good place to start:

enum class GUI_ElementType{ Window, Label, Button, Scrollbar,
  Textfield };

Each element has to hold different styles it can switch to, based on its state. The unordered_map data structure suits our purposes pretty well:

using ElementStyles = std::unordered_map<
  GUI_ElementState, GUI_Style>;

A forward declaration of the owner class is also necessary to prevent cross-inclusion:

class GUI_Interface;

Next, we can begin ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required