
I'll give it a go.auto gui = world.get_mut<Tag::GuiRoot>();
auto hudRoot = tgui::HorizontalLayout::create();
auto leftPanel = tgui::VerticalLayout::create();
auto topLeft = tgui::Panel::create();
topLeft->getRenderer()->setBackgroundColor(sf::Color::Green);
leftPanel->add(topLeft);
// auto canvas = GameCanvas::create(world);
// leftPanel->add(canvas, "GameCanvas");
// world.set( Tag::GameCanvas{canvas} );
// leftPanel->setRatio(canvas, 15.0f);
auto bottomLeft = tgui::Panel::create();
bottomLeft->getRenderer()->setBackgroundColor(sf::Color::Blue);
leftPanel->add(bottomLeft);
leftPanel->insertSpace(1, 80.0f);
hudRoot->add(leftPanel, "LeftPanel");
auto rightPanel = tgui::VerticalLayout::create();
auto topRight = tgui::Panel::create();
topRight->getRenderer()->setBackgroundColor(sf::Color::Green);
rightPanel->add(topRight);
auto button = tgui::Button::create("Steal Focus");
button->onMousePress(
[button](){
button->setFocused(true);
}
);
topRight->add(button);
button = tgui::Button::create("Quit");
button->onMousePress(
[world](){
world.add<Tag::ActiveScene, Tag::MenuScene>();
}
);
topRight->add(button);
auto txtArea = tgui::EditBox::create();
txtArea->setPosition(0, 50);
topRight->add(txtArea);
auto bottomRight = tgui::Panel::create();
bottomRight->getRenderer()->setBackgroundColor(sf::Color::Blue);
rightPanel->add(bottomRight);
hudRoot->add(rightPanel, "RightPanel");
hudRoot->setRatio(rightPanel, 0.3f);
hudRoot->setVisible(false);
gui->gui->add(hudRoot, "HudRoot");
sf::Event event;
while(window.window->pollEvent(event)){
if(event.type == sf::Event::Closed){
e.world().set( Tag::Status{ Tag::Status::QUIT });
}
if(gui.gui->handleEvent(event)){
continue;
}
ctrl.ctrl->checkInput(event);
}
bool GameCanvas::canGainFocus() const override
{
return true;
}
class GameCanvas : public tgui::CanvasSFML{
public:
using Ptr = std::shared_ptr<GameCanvas>;
GameCanvas(flecs::world& w);
static GameCanvas::Ptr create(flecs::world& w);
bool canHandleKeyPress(const tgui::Event::KeyEvent& event) override;
void keyPressed (const tgui::Event::KeyEvent& event) override;
bool leftMousePressed(tgui::Vector2f pos) override;
void leftMouseReleased(tgui::Vector2f pos) override;
void rightMousePressed(tgui::Vector2f pos) override;
void rightMouseReleased(tgui::Vector2f pos) override;
void mouseMoved(tgui::Vector2f pos) override;
bool isFocused() const{
bool f = tgui::CanvasSFML::isFocused();
std::cout << "GameCanvas::isFocused(): " << (f ? "True" : "False") << std::endl;
return f;
}
tgui::SignalTyped<tgui::Event::KeyEvent> onKeyPress = {"onKeyPress"};
protected:
tgui::Signal& getSignal(tgui::String signalName) override;
private:
flecs::world world;
};
#include "gameCanvas.hpp"
GameCanvas::GameCanvas(flecs::world& w) : tgui::CanvasSFML(), world(w) {
onKeyPress(
[this](const tgui::Event::KeyEvent& event){
Tag::InputCtrl* ctrl = world.lookup("Tag::GameScene").get_mut<Tag::InputCtrl>();
ctrl->ctrl->onKeyEvent(event);
}
);
}
GameCanvas::Ptr GameCanvas::create(flecs::world& w){
auto canvas = std::make_shared<GameCanvas>(w);
return canvas;
}
void GameCanvas::keyPressed (const tgui::Event::KeyEvent& event){
std::cout << "GameCanvas::keyPressed()" << std::endl;
tgui::CanvasSFML::keyPressed(event);
onKeyPress.emit(this, event);
}
bool GameCanvas::leftMousePressed(tgui::Vector2f pos){
tgui::CanvasSFML::leftMousePressed(pos);
return false;
}
void GameCanvas::leftMouseReleased(tgui::Vector2f pos){
tgui::CanvasSFML::leftMouseReleased(pos);
std::cout << "GameCanvas::leftMouseReleased()" << std::endl;
}
void GameCanvas::rightMousePressed(tgui::Vector2f pos){
tgui::CanvasSFML::rightMousePressed(pos);
}
void GameCanvas::rightMouseReleased(tgui::Vector2f pos){
tgui::CanvasSFML::rightMouseReleased(pos);
}
void GameCanvas::mouseMoved(tgui::Vector2f pos){
tgui::CanvasSFML::mouseMoved(pos);
Tag::InputCtrl* ctrl = world.lookup("Tag::GameScene").get_mut<Tag::InputCtrl>();
ctrl->ctrl->onMouseMoveEvent(pos - getPosition());
}
bool GameCanvas::canHandleKeyPress(const tgui::Event::KeyEvent& event){
std::cout << "GameCanvas::canHandleKeyPress()" << std::endl;
return true;
}
tgui::Signal& GameCanvas::getSignal(tgui::String signalName) {
std::cout << "GameCanvas::getSignal()" << std::endl;
if (signalName == onKeyPress.getName())
return onKeyPress;
else
return tgui::CanvasSFML::getSignal(std::move(signalName));
}

auto gui = world.get_mut<Tag::GuiRoot>();
auto hudRoot = tgui::HorizontalLayout::create();
// LEFT WIDGETS
auto leftPanel = tgui::VerticalLayout::create();
leftPanel->setFocusable(false);
auto topLeft = tgui::Panel::create();
topLeft->getRenderer()->setBackgroundColor(sf::Color::Green);
leftPanel->add(topLeft);
auto canvas = tgui::CanvasSFML::create();
leftPanel->add(canvas, "GameCanvas");
world.set( Tag::GameCanvas{canvas} );
leftPanel->setRatio(canvas, 15.0f);
auto bottomLeft = tgui::Panel::create();
bottomLeft->getRenderer()->setBackgroundColor(sf::Color::Blue);
leftPanel->add(bottomLeft);
hudRoot->add(leftPanel, "LeftPanel");
// RIGHT WIDGETS
auto rightPanel = tgui::VerticalLayout::create();
// rightPanel->setFocusable(false);
auto topRight = tgui::Panel::create();
topRight->getRenderer()->setBackgroundColor(sf::Color::Green);
rightPanel->add(topRight);
auto bottomRight = tgui::Panel::create();
bottomRight->getRenderer()->setBackgroundColor(sf::Color::Blue);
rightPanel->add(bottomRight);
hudRoot->add(rightPanel, "RightPanel");
hudRoot->setRatio(rightPanel, 0.3f);
hudRoot->setVisible(false);
gui->gui->add(hudRoot, "HudRoot");
canvas->clear(sf::Color::Black);
window->clear(sf::Color::White);
// render sprites to canvas
canvas->display();
gui->draw();
window->display()