-
Notifications
You must be signed in to change notification settings - Fork 0
Getting started
- You can simply install LibGui by using this in terminal.
git clone https://github.com/TechnologicalTurtle/LibGui.git- After that use CMake to build it for your IDE.
cmake -B [build directory]Note
If you want to also build hello world program, with everything set up, use:
cmake -B [build directory] -DLIBGUI_BUILD_CLIENT- Open the project from [build directory] in your IDE.
- And that's all! Enjoy!
Note
This part assumes you have set up main.cpp, or used LIBGUI_BUILD_CLIENT option.
First you need to include LibGui.h header,
#include "include/LibGui.h"then in your main function initialize library using the LibGui::Init() function, this function returns pointer to app window, to get handle for this window plug it into LibGui::Window constructor with other properties like window name, and size. That should look like this:
LibGui::Window MyMainWindow(LibGui(), "window name", {600, 400});Now, you have to create the square, becouse square is an basic object without any special properties, the class that handles it is called LibGui::Object, then actually tell the object it's square, to do this use MyObject.InitAsRectangle({position}, {size in pixels}, Color);
Your code should look like this:
LibGui::Object MyObject;
MyObject.InitAsRectangle({100, 100}, {200, 200}, Color::Blue);Now is time to render something, create an while loop using !MyWindow.ShouldClose(), once user clicks on [X] button, the function will return true, which will break the loop. In the loop, you should tell program where to render using function MyWindow.Draw(). Then render MyObject using MyObject.Render(). At end tell library to push changes by calling MyWindow.PushDraw();. The code will look like this:
while (!MyWindow.ShouldClose())
{
MyWindow.Draw();
MyObject.Render();
MyWindow.PushDraw();
}Now, after user closed our window, we'll tell LibGui to Terminate by calling LibGui::Terminate();
LibGui::Terminate();Our final code should look similar to this:
// include library header
#include "include/LibGui.h"
int main()
{
// initialize library and create main window
LibGui::Window MyWindow(LibGui::Init(), "My LibGui window", {600, 400});
// create our square
LibGui::Object MyObject;
MyObject.InitAsRectangle({100, 100}, {200, 200}, Color::Blue);
while (!MyWindow.ShouldClose())
{
// start drawing on our main window
MyWindow.Draw();
// render our square
MyObject.Render();
// push our changes
MyWindow.PushDraw();
}
// terminate libgui
LibGui::Terminate();
return 0;
}Features