Getting started - Horizon-NTH/HorizonGUI GitHub Wiki
Getting Started with HGUI
Table of Contents
- Including the HGUI Header
- Link the library
- Initializing HGUI
- Terminating HGUI
- Creating a Window
- Creating Widgets
- Processing Binds
- Example
Including the HGUI Header
In your application's source files where you intend to use HGUI, make sure to include HGUI's header file:
#include <hgui/HorizonGUI.h>
This header provides access to all the constants, types, functions and classes of the HGUI API.
Link the library
In you application project you must link all the libraries located in the lib
folder.
# An example of the minimum CMakeLists.txt you must create in order to use the HorizonGUI library:
cmake_minimum_required(VERSION 3.12)
project(YourProject VERSION 1.0)
add_subdirectory(path/to/HorizonGUI)
# Set your files
set(HEADER_FILES
# List your header files here
)
set(SOURCE_FILES
# List your source files here
)
add_executable(${PROJECT_NAME} ${HEADER_FILES} ${SOURCE_FILES})
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20) #Be sure to use at least c++20
target_include_directories(${PROJECT_NAME} PRIVATE path/to/HorizonGUI/include)
target_link_libraries(${PROJECT_NAME} PRIVATE horizongui glfw freetype OpenAL sndfile)
Initializing HGUI
Before using HGUI functions and classes, you must initialize the library by calling the init
function:
hgui::init();
HGUI's initialization sets up various resources and prepares for window and widget creation.
Terminating HGUI
When you're done using HGUI, typically just before your application exits, you should terminate HGUI by calling the end
function:
hgui::end();
This will clean up resources, destroy any windows, leave render loop and release other resources allocated by HGUI. After this call, you must initialize HGUI again before using any HGUI functions that require it.
Creating a Window
Before using any function or classes related to any widgets in your application you
must have an active window that you can create by using the WindowManager
:
auto myIcon = hgui::image_loader(path/to/your/icon.png)
auto window = hgui::WindowManager("myWindow", hgui::size(1920, 1080), hgui::point(0), myIcon);
Creating Widgets
Widgets are the building blocks of your user interface. HGUI provides a variety of widgets, including buttons, labels, canvas, and more. Use the following functions to create and manipulate widgets:
auto button = hgui::ButtonManager::create(myFunction, hgui::size(200, 100), hgui::point(640, 256));
Processing Binds
Widgets can be bound to specific actions, such as button clicks or mouse movement. Use the following functions to bind actions:
// Keyboard bind
hgui::KeyBoardManager::bind(hgui::KeyBoardAction(hgui::keys::A, hgui::PRESS), myFunction); // myFunction will be called when the key A is pressed
// Mouse bind
myWidget->bind(hgui::inputs::OVER, myFunction) // myFunction will be called when the mouse is over myWIdget
hgui::MouseManager::bind(hgui::MouseAction(hgui::buttons::LEFT, hgui::RELEASE), myFunction); // myFunction will be called when the left button of the
// mouse is released
Example
Now that you have read this, it's possible to create a simple program:
#include <hgui/HorizonGUI.h>
int main()
{
hgui::init(); // Library initialization
auto monitor = hgui::MonitorManager::get_primary_monitor(); // Get the primary monitor
auto window = hgui::WindowManager("FirstHGUIApp",, monitor->get_size(), hgui::point(0)); // Create a window with the size of the monitor
auto button = hgui::ButtonManager::create(hgui::end, hgui::size(200, 100), hgui::point(0)); // Create a button to close the application
button->set_position(hgui::point(50_em) - button->get_size() / 2.0f); // Place the button exactly at the center of the window
hgui::kernel::Widget::active(); // Active all widgets (here only our button)
hgui::Renderer::draw(); // Draw all widgets (here only our button)
hgui::Renderer::loop(); // Begin the render loop
return 0;
]