The InitInfo
struct in the Instance.hpp
header is responsible for data needed to initialize the framework. The members of the struct can be seen below:
struct InitInfo
{
std::vector<InlineComponent*> inlineComponents;
std::vector<TitlebarComponent*> titlebarComponents;
std::vector<WindowComponent*> windowComponents;
// Provide a global data struct to be shared with all components
void* globalData = nullptr;
bool bGlobalAllocatedOnHeap = true; // Set this to false if the global is a stack pointer
};
The 3 arrays contain generic pointers to the different components that should be rendered.
The globalData
void pointer contains data that you can fetch on demand in any component by calling UImGui::Instance::getGlobal()
.
When cleaning up the globalData
, we will automatically default to calling free
on it. If the pointer is stack allocated, however, this will result in a segmentation fault. For that reason, you need to set bGlobalAllocatedOnHeap
to false
.
2 entries ago, we started a hello world application, but we still haven’t initialized it yet. Let’s render that text! Enter your Instance.hpp
file under Source
. It should look like this:
#pragma once
#include <Framework.hpp>
namespace UntitledTextEditor
{
class UIMGUI_PUBLIC_API Instance : public UImGui::Instance
{
public:
Instance();
virtual void begin() override;
virtual void tick(float deltaTime) override;
virtual void end() override;
virtual ~Instance() override;
virtual void onEventConfigureStyle(ImGuiStyle& style, ImGuiIO& io) override;
private:
};
}
First, include the hello.hpp
file above and create an instance of the hello
class as a member variable.
In your Instance.cpp
file, all you need to do is modify the InitInfo
. Simply put this line into your constructor so that it looks like this:
UntitledTextEditor::Instance::Instance()
{
initInfo.inlineComponents = { &hello };
}
And run your application. We have a hello world message!
The entire module is flagged as event safe at Any time
.