Skip to content
TechnologicalTurtle edited this page Jul 25, 2026 · 15 revisions

LibGui::Window

LibGui::Window is a wrapper for GLFWwindow*, there are two ways to initialize it:

Initialization

Initialization window

This is the first window you create using the Init() method, it's also default window for all Objects (and other classes).

//                                 initialize library| name of window   | size of window
LibGui::Window MyInitializationWindow(LibGui::Init(), "My Initialization window",{600, 400});

but why?!

Normal window

All windows after creation of Initialization window should be made this way.

//                              name of window  |  size of window
LibGui::Window MyNormalWindow("My normal window", {600, 400});

Properties

Type Property Description
MouseCursor cursor handles mouse input for this window
KeyTracker key_tracker tracks key states for some keys; more here/KeyTracker
Color background_color specifies background color of this window
float transparency transparency of whole window (including rendered content)
bool CanAutoClose can window automatically close once user pressed [X]?
Vec2i size [READ-ONLY] ...current size of this window

Methods

bool GetKeyPressed(...)

Quick way to know is given key is pressed. (for more click and release properties see KeyTracker)
Examples

MyWindow.GetKeyPressed('w'); // is key W pressed?
MyWindow.GetKeyPressed(LibGui::FunctionalKey_RightShift); // is right shift pressed?

string GetClipboard()

Returns content in user's clipboard.

void SetClipboard(string text)

Sets user's clipboard to text.

void Draw()

Tells program to now render on this window, it also updates the window (input handling, window movement).
Example

while (true)
{
   // start rendering here
   MyWindow.Draw();

   // render our beloved square [reference to Getting started]
   MySquare.Render();

   // now he has friend
   MyAnotherSquare.Render(); 

   // push render to screen (for another rendering you have to call MyWindow.Draw(); again)
   MyWindow.PushDraw(); 
}

void PushDraw()

Tells program to send our since-last-Draw() rendered stuff to screen.
For example see Draw() example. (I don't want to just copy the code)

bool ShouldClose()

If user pressed [X] button (or on other events such as Close() call), returns true, else it returns false.
Example

while (!MyWindow.ShouldClose())
{
   std::cout << "I'm alive!\n";
}
std::cout << "I... was sadly closed :(  \n";
std::cin.get();

void Close()

Closes the window, next ShouldClose() call will return true. Example

MyWindow.Close(int flags);

void Reflag()

Updates init flags to new flags. See more here

void SetIcon(LibGui::Image img, bool clamp = true)

Set window icon to LibGui::Image 'img'; 'clamp' the icon must be square, so should cut or squeeze 'img' to fit.

LibGui::Image MyTurtleImage("square_turtle_logo.png");
MyWindow.SetIcon(MyTurtleImage);

void SetWindowName(string name)

Sets window's name to name.

LibGui::Image Screenshot(bool transparent = false)

Returns literal screenshot of last render. transparent means if transparent parts of that render will remain transparent (this includes final image not having window background).
Example

LibGui::Image MyScreenshot = MyWindow.Screenshot();

void Notification(string title, string text, NotificationLevel_ level)

Shows user notification called title with text text and level NotificationLevel_ level.

void DialogInput(string title, string text, string default_input)

Shows user text input box titled title with question text, at the start the input field has value default_input.

image

void MessageBox(string title, string message, DialogType_ dialog_type, NotificationLevel_ icon)

Shows user popup tiitled title, with message message. dialog_type determines button layout of the popup and icon determines icon (info/warning/error).

string SaveFileDialog(string title, string start_path, string filter_name, vector<string> allowed_file_types)

Shows a Save file window with title, it starts at start_path. If you want only some type of files set allowed_file_types to {"*.type", "*.type2"}, for example {"*.txt", "*.cpp", "*.h"} and set filter_name to how you want to call this group.

string OpenFileDialog(string title, string start_path, string filter_name, vector<string> allowed_file_types)

Is same as SaveFileDialog(), but it opens Open file window.

vector<string> OpenMultiFileDialog(...)

Is same as OpenFileDialog(), but allows user to select more files. Returns vector with paths to user selected files.

Note

Just leave the multi_select on true.

string SelectDirectory(string title, string start_path)

Opens "Select Directory/Folder" window titled title, on location start_path.

void Bind()

Binds current window. You probably won't need this. It's wrapper for glfwMakeContextCurrent()

GLFWwindow* GetID()

Returns glfw window pointer.

Init flags

At window creation, you can tell it how to behave by setting WIF (window init flags). To create them you just or together stuff from WindowInitFlag_ enum.

LibGui::MyUnresizableWindow("window", {200, 100}, LibGui::WindowInitFlag_CantBeResized);

Why has first window to be initialized so weirdly?

The Init() function must (along other stuff), initialize two OpenGL libraries, one of them is called glad. But to initialize glad you have to already have created a window, I solve this by making this window, initializing glad and then passing this GLFWwindow* to user, who has to, to have access to this window, create it with this dumb syntax:

LibGui::Window MyInitializationWindow(LibGui::Init(), "My Initialization window", {600, 400});

Clone this wiki locally