Window - Horizon-NTH/HorizonGUI GitHub Wiki

Window

Overview

The Window class in the hgui::kernel namespace provides functionality for creating and managing graphical windows. It allows you to specify window properties such as name, size, position, icon, monitor, and options. The class is defined in the header file Window.h and uses GLFW.

Constructors

  • Window(const std::string& name, const size& size, point position, const std::shared_ptr<Image>& icon, const std::shared_ptr<Monitor>& monitor, const std::map<options, bool>& options): Constructs a Window object by specifying the window's name, size, position, icon, monitor, and optional options. This constructor creates a GLFW window with the specified properties.

Note: Passing a monitor to the constructor will directly make the window in full screen on the specified monitor.

Note: If you want to see more about the window destruction read this.

Member Functions

  • const size& get_size() const: Retrieves the size of the window.

  • void set_size(const size& newSize): Sets the size of the window.

  • const point& get_position() const: Retrieves the position of the window.

  • void set_position(const point& newPosition): Sets the position of the window.

  • GLFWwindow* get_window_ptr() const: Retrieves the pointer to the GLFW window.

  • void set_size_callback(const std::variant<std::function<void()>, SizeCallback>& function): Binds a size callback function that will be called each time the window size changes. The function you pass can either take no argument or the GLFW window pointer and the new size as two int.

using SizeCallback = std::function<void(GLFWwindow*, int, int)>

  • void set_position_callback(const std::variant<std::function<void()>, PositionCallback>& function): Binds a position callback function that will be called each time the window moves. The function you pass can either take no argument or the GLFW window pointer and the new position as two int.

using PositionCallback = std::function<void(GLFWwindow*, int, int)>

Example Usage

#include <hgui/header/Window.h>

// Example Usage of Window class
std::string windowName = "My Window";
hgui::kernel::size windowSize(800, 600);
hgui::kernel::point windowPosition(100, 100);
std::shared_ptr<hgui::kernel::Image> windowIcon = hgui::image_loader("icon.png");
std::shared_ptr<hgui::kernel::Monitor> windowMonitor = std::make_shared<hgui::kernel::Monitor>(monitorPtr);

hgui::kernel::Window window(windowName, windowSize, windowPosition, windowIcon, windowMonitor, {
    {hgui::kernel::options::RESIZABLE, true},
    {hgui::kernel::options::VISIBLE, true},
    {hgui::kernel::options::DECORATED, true}
});

// Retrieve window properties
const hgui::kernel::size& currentSize = window.get_size();
const hgui::kernel::point& currentPosition = window.get_position();
GLFWwindow* glfwWindowPtr = window.get_windowPTR();

// Set window size and position
window.set_size(hgui::kernel::size(1024, 768));
window.set_position(hgui::kernel::point(200, 200));

Note: In the "Example Usage" section, replace the example values for windowName, windowSize, windowPosition, and the actual image file path for windowIcon and if you want to read more about the image_loader function, see this. Modify the options initializer list as needed to suit your application's requirements and if you want see all the possible option read this.

⚠️ **GitHub.com Fallback** ⚠️