Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <SFGUI/SFGUI.hpp>
#include <SFGUI/Widgets.hpp>
#include <SFML/Graphics.hpp>
int main()
{
enum class Option {none, rectangle, circle};
Option option = Option::none;
sf::RenderWindow win{sf::VideoMode{400, 400}, "sfgui test"};
sfg::SFGUI sfgui;
auto window = sfg::Window::Create();
window->SetTitle("select option");
auto box = sfg::Box::Create(sfg::Box::Orientation::VERTICAL);
auto option1 = sfg::RadioButton::Create("rectangle");
auto option2 = sfg::RadioButton::Create("circle", option1->GetGroup());
auto button_select = [&option1, &option2, &option] {
if (option1->IsActive())
{
option = Option::rectangle;
}
else if (option2->IsActive())
{
option = Option::circle;
}
};
option1->GetSignal(sfg::ToggleButton::OnToggle).Connect(button_select);
option2->GetSignal(sfg::ToggleButton::OnToggle).Connect(button_select);
box->Pack(option1);
box->Pack(option2);
window->Add(box);
sf::RectangleShape rect{sf::Vector2f{20, 20}};
rect.setOrigin(10, 10);
rect.setPosition(200, 200);
rect.setFillColor(sf::Color::White);
while (win.isOpen())
{
sf::Event event;
while (win.pollEvent(event))
{
window->HandleEvent(event);
if (event.type == sf::Event::Closed) win.close();
}
window->Update( 0.f );
win.clear();
win.resetGLStates();
sfgui.Display(win);
win.resetGLStates();
if (option == Option::rectangle)
{
win.draw(rect);
}
win.display();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.