What I personally like about this library is the way GUI objects are grouped.
There is the GUI window ( such as "[Main]"). Inside the GUI window, there are GUI objects. They organize them self like a tree. When you call gui->draw("[Main]","[Button]"), the window chosen is [Main] and the GUI object in location "[Button]" and everyone below it is drawn.
Again when you call gui->draw("[Main]","[Button]:
One"), the window chosen is [Main] and the GUI object in location "[Button]:
One" and everyone below it is drawn. The colon (":") act as a slash ("/") to denote a virtual folder. The same applies to poll(). There are also callbacks for several scenarios (see below).
Here what's the (messy) sample code look like:
#include <SFML/Graphics.hpp>
#include "sfui/sfui.h"
#include <iostream>
void printPressedCallback(void* n)
{
bool *bScreen = (bool*)n;
if(*bScreen)
*bScreen = false;
else
*bScreen = true;
std::cout << "printPressedCallback" << std::endl;
}
void printHeldCallback(void* n)
{
std::cout << "printHeldCallback" << std::endl;
}
void printReleasedCallback(void* n)
{
std::cout << "printReleasedCallback" << std::endl;
}
void printUntouchedCallback(void* n)
{
std::cout << "printUntouchedCallback" << std::endl;
}
void printHoverEnterCallback(void* n)
{
std::cout << "printHoverEnterCallback" << std::endl;
}
void printHoveringCallback(void* n)
{
std::cout << "printHoveringCallback" << std::endl;
}
void printHoverLeaveCallback(void* n)
{
std::cout << "printHoverLeaveCallback" << std::endl;
}
void printNoHoverCallback(void* n)
{
std::cout << "printNoHoverCallback" << std::endl;
}
int main()
{
bool bScreen = false;
sf::ui::Gui *gui = new sf::ui::Gui(sf::Color(255,255,0), sf::Color(0,0,0),sf::Color(255,255,255), 13.);
sf::ui::UIButton *button = new sf::ui::UIButton("Switch!",13.);
sf::ui::UIButton *button2 = new sf::ui::UIButton("Switch!",13.);
sf::ui::UIButton *button3 = new sf::ui::UIButton("Button 3",13.);
sf::ui::UIButton *button4 = new sf::ui::UIButton("Button 4",13.);
sf::ui::UILabel *label = new sf::ui::UILabel("Label:",13.);
sf::ui::UICheckbox *checkbox = new sf::ui::UICheckbox(true);
sf::ui::UITextField *textbox = new sf::ui::UITextField("TextField ",18., false, 300);
button2->setX(10);
button2->setY(60);
button->setX(10);
button->setY(120);
button3->setX(10);
button3->setY(150);
button4->setX(10);
button4->setY(300);
button4->setWidth(50);
button4->setHeight(50);
textbox->setX(10);
textbox->setY(5);
label->setX(10);
label->setY(250);
checkbox->setX(10);
checkbox->setY(180);
button->setPressedCallBack (new sf::ui::UICallBackStruct(&printPressedCallback,&bScreen));
button2->setPressedCallBack (new sf::ui::UICallBackStruct(&printPressedCallback,&bScreen));
button->setHeldCallBack (new sf::ui::UICallBackStruct(&printHeldCallback));
button->setReleasedCallBack (new sf::ui::UICallBackStruct(&printReleasedCallback));
button->setUnTouchedCallBack (new sf::ui::UICallBackStruct(&printUntouchedCallback));
button->setHoverEnterCallBack (new sf::ui::UICallBackStruct(&printHoverEnterCallback));
button->setHoveringCallBack (new sf::ui::UICallBackStruct(&printHoveringCallback));
button->setHoverLeaveCallBack (new sf::ui::UICallBackStruct(&printHoverLeaveCallback));
button->setNoHoverCallBack (new sf::ui::UICallBackStruct(&printNoHoverCallback));
// Create main window
sf::RenderWindow App(sf::VideoMode(500, 300), "SFUI");
App.EnableKeyRepeat(true);
gui->addWindow("[Main]",&App);
gui->addObject("[Main]","[Button]:One:Two",button);
gui->addObject("[Main]","[Button]:One:Two:Three",button3);
gui->addObject("[Main]","[Button]:One:Two:Four",button4);
gui->addObject("[Main]","[Button]:One:Three",button2);
gui->addObject("[Main]","[Button]:One:Two:Label",label);
gui->addObject("[Main]","[Button]:One:Three:Checkbox",checkbox);
gui->addObject("[Main]","[Button]:One:Three:textbox",textbox);
button->setColor(sf::Color(100,200,100));
button->setTextColor(sf::Color(255,255,0));
sf::ui::UICheckbox* ch = (sf::ui::UICheckbox*)gui->getObject("[Main]","[Button]:One:Two:Checkbox");
while (App.IsOpened())
{
sf::Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
}
App.Clear(sf::Color(170,175,180));
gui->poll("[Main]");
if(bScreen)
{
gui->process("[Main]","[Button]:One:Three");
gui->draw("[Main]","[Button]:One:Three");
}else {
gui->process("[Main]","[Button]:One:Two");
gui->draw("[Main]","[Button]:One:Two");
}
App.Display();
}
delete gui;
return EXIT_SUCCESS;
}
Download HereThere is a video there too.