I think my error here might be due to my misunderstanding of how RenderWindow pollEvent() works. The problem I am having is with the following code:
void InputHandler::processMenuInputs(const std::optional<sf::Event>& e) {
if (e->is<sf::Event::Resized>()) {
// rerender interactables if menu size is changed
menuManager.queueInteractableLocationUpdate();
menuManager.queueFrameLocationUpdate();
}
if (const auto *textEntered = e->getIf<sf::Event::TextEntered>()) {
// if text entered worked
std::cout << "text enter detected\n";
if (menuManager.textboxInput(textEntered->unicode)) return;
std::cout << "text entered but not returned\n";
}
if (const auto *keyPressed = e->getIf<sf::Event::KeyPressed>()) {
std::cout << "processing key\n";
processMenuKeyPressed(*keyPressed);
}
}
When I press a key I get the following output:
processing key
text enter detected
My understanding was that pollEvent() returns an event, which is just data. I then am interpreting that data into different types of events such as textEntered or keyPressed using the getIf with std::optional. However, the output I see in the terminal isn't what I expected, I expect to see "text enter detected" first, and "processing key" last due to the order of the if statements. Why is the order reversed? Another thing is why does the code trigger twice, and why does the code print both things?
The reason I was doing this is because I was hoping that if the menuManager accepted the textEntered event, then I would not run the keyPressed event. Am I doing something wrong, or is there a different way to get this functionality?