Simple SFML GUI  0.2a
SimpleTemplate.cpp
#include "SSG/SSG.hpp"
int main() {
//Application is more usable with loaded font.
//Last bool says that this font should be also setted as default
//When font can not be loaded, please check path and your working directory
FontManager::set("assets/Inconsolata.otf","mono",true);
//Load configuration from config.txt, first call will save this path as default for app configuration
//Is better to have load call after all addConfVar but variable can be too loaded from cache with relConfVar(myVar)
Configurator::load("config.txt");
//Create window via GUIManager::createWindow which save window title and context settings
std::shared_ptr<sf::RenderWindow> rw = GUIManager::createWindow("SSG Simple template");
Panel mainPanel;
//Set panel model for proper arrangement of elements
mainPanel.setModel(std::make_shared<PanelModelLine>(Orientation::Vertical, Align::Center, VAlign::Middle));
//Create button with click lambda action
ButtonPtr button = std::make_shared<Button>("Hello!",[]() {
GUIManager::addDialog(std::make_shared<DialogInfo>("Hello SSG!"));
});
button->getLabel().setColor(ColorId::FontFill, StateId::Focus, sf::Color::Red);
//Optionally set hot key
button->setHotKey(sf::Keyboard::Key::H);
//Add your element to panel
mainPanel.add(button);
while(rw->isOpen()) {
//Clear window with your color
rw->clear(sf::Color(64,64,64));
//Use defaultEventsHandle for properly scrolling and text input
//This event loop can be easly extended for other reactions
sf::Event e;
while(rw->pollEvent(e)) {
defaultEventsHandle(e, *rw);
}
//Fit panel size to window dimensions
mainPanel.fitToWindow(*rw);
//Use mainUpdate and mainDraw methods only once in app loop, for properly handling GUIManager and GUIInspector
mainPanel.mainUpdate(*rw);
mainPanel.mainDraw(*rw);
//Standard SFML display call
rw->display();
}
return 0;
}