Skip to content

Container

Otavio edited this page Oct 16, 2021 · 6 revisions

Container

Introduction:

In FGUI we don't have Forms or GroupBoxes. Instead we have Containers. It will behave just like a normal Form (Window) or a GroupBox.

How it works:

Every widget on FGUI is usually attached to a Container. Even if we are going to add a new Container into the menu, we need to attach it into another Container, so if the Container has a parent widget (is attached to another Container), it will behave as a GroupBox and if it doesn't have any parent widget (doesn't have anything attached to it) it will behave like a window. (Logically it doesn't have anything above him, so it will become the parent of every widget added on the menu.)

First things first:

Here I will show how to setup your first Container with and without the Builder Pattern and then proceeding to render it.

Example:

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

std::shared_ptr<FGUI::CContainer> Container;
std::shared_ptr<FGUI::CContainer> GroupBox;

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

FGUI::CBuilder buildrPattern;

// Window
Container = std::make_shared<FGUI::CContainer>();
buildrPattern.Widget(Container).Title("Container").Position(200, 200).Size(750, 450).Key(KEY_HOME).Font("Tahoma", 12);

// GroupBox
GroupBox = std::make_shared<FGUI::CContainer>();
buildrPattern.Widget(GroupBox).Title("GroupBox").Position(15, 35).Size(280, 300).Font("Tahoma", 12, true).SpawnIn(Container);

NOTE: On the second example I've added a new function to the pattern: SpawnIn you will use this function to tell FGUI where do you want your widget to be spawned. In this case our GroupBox needs to be Spawned inside the Container (Window) so it can have a parent and then behave like a GroupBox.

(There's other functions of the builder pattern that you can use when setting up a GroupBox Container or a Window Container.)

Rendering:

Now that we've created our Window and GroupBox, we need to render it. You just need to call one function. Assuming that your Window pointer is declared and initialized correctly, you just need to call this function inside your drawing thread (EndScene, PaintTraverse/Paint (Source Engine), etc.):

// inside paint traverse or w/e function you use to draw stuff on screen.
Container->Render() // NOTE: This is the Window pointer (aka. the Container that is behaving like a Window)

What's next?

Next you will learn how to create a ItemSelector.