SFML with TUI example

This commit is contained in:
Alexander Popov 2024-02-24 18:33:19 +03:00
parent 362bbed6bd
commit 6d50aa349a
Signed by: iiiypuk
GPG Key ID: E47FE0AB36CD5ED6
3 changed files with 86 additions and 0 deletions

3
sfml-tgui/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
themes/
fonts/
libtgui.so*

13
sfml-tgui/build.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/sh
rm ./a.out
g++ \
-Wl,-rpath=. \
-I/home/user/Downloads/TGUI-1.1.0/include/ \
-L./ \
main.cpp \
-ltgui \
-lsfml-graphics -lsfml-window -lsfml-system
./a.out

70
sfml-tgui/main.cpp Normal file
View File

@ -0,0 +1,70 @@
#include <TGUI/TGUI.hpp>
#include <TGUI/Backend/SFML-Graphics.hpp>
#include <TGUI/Widgets/Group.hpp>
#include <TGUI/Widgets/Panel.hpp>
#include <TGUI/Widgets/MenuBar.hpp>
int main() {
sf::RenderWindow window{{800, 600}, "TGUI example w/ SFML_GRAPHICS backend"};
sf::Event event;
tgui::Gui gui{window};
tgui::Font m_tguiFont("fonts/Cuprum/Cuprum-Regular.ttf");
tgui::Font::setGlobalFont(m_tguiFont);
tgui::Theme::setDefault("themes/Black.txt");
auto top_panel = tgui::Panel::create();
auto main_panel = tgui::Panel::create();
auto footer_panel = tgui::Panel::create();
auto menu_bar = tgui::MenuBar::create();
menu_bar->addMenu("File");
menu_bar->addMenuItem("Load");
menu_bar->addMenuItem("Save");
top_panel->setHeight("50px");
footer_panel->setHeight("30px");
top_panel->setAutoLayout(tgui::AutoLayout::Top);
main_panel->setAutoLayout(tgui::AutoLayout::Fill);
footer_panel->setAutoLayout(tgui::AutoLayout::Bottom);
tgui::Button::Ptr button = tgui::Button::create("Привет");
button->onPress([&] { printf("ololo\n"); });
button->setHeight("30px");
tgui::Button::Ptr button2 = tgui::Button::create("Закрыть");
button2->setAutoLayout(tgui::AutoLayout::Fill);
button2->onPress([&] { window.close(); });
auto picture = tgui::Picture::create("CLI_Logo_small.png");
auto editBox = tgui::EditBox::create();
top_panel->add(button);
main_panel->add(picture);
footer_panel->add(button2);
gui.add(menu_bar);
gui.add(top_panel);
gui.add(main_panel);
gui.add(footer_panel);
// gui.mainLoop();
while (window.isOpen()) {
while (window.pollEvent(event)) {
// while (window.waitEvent(event)) {
gui.handleEvent(event);
if (event.type == sf::Event::Closed)
window.close();
}
window.clear({240, 240, 240});
gui.draw();
window.display();
}
printf("Пока\n");
}