|
1 | 1 | #include "online_lobby.hpp" |
2 | 2 | #include "graphics/window.hpp" |
3 | 3 | #include "helper/constants.hpp" |
| 4 | +#include "helper/errors.hpp" |
4 | 5 | #include "manager/music_manager.hpp" |
5 | 6 | #include "manager/resource_manager.hpp" |
6 | 7 | #include "ui/components/textinput.hpp" |
@@ -51,10 +52,7 @@ namespace scenes { |
51 | 52 | service_provider->fonts().get(FontId::Symbola), Color::white(), focus_helper.focus_id(), |
52 | 53 | std::pair<double, double>{ 0.9, 0.9 }, |
53 | 54 | ui::Alignment{ ui::AlignmentHorizontal::Middle, ui::AlignmentVertical::Center }, |
54 | | - ui::TextInputMode::Scroll, |
55 | | - [i](const std::string& value) -> void { |
56 | | - spdlog::info("Pressed Enter on TextInput {}: {}", i, value); |
57 | | - } |
| 55 | + ui::TextInputMode::Scroll |
58 | 56 | ); |
59 | 57 | } else { |
60 | 58 | scroll_layout->add<ui::TextButton>( |
@@ -121,7 +119,32 @@ namespace scenes { |
121 | 119 | // description of intentional behaviour of this scene, even if it seems off: |
122 | 120 | // the return button or the scroll layout can have the focus, if the scroll_layout has the focus, it can be scrolled by the scroll wheel and you can move around the focused item of the scroll_layout with up and down, but not with TAB, with tab you can change the focus to the return button, where you can't use the scroll wheel or up / down to change the scroll items, but you still can use click events, they are not affected by focus |
123 | 121 |
|
124 | | - if (m_main_layout.handle_event(event, window)) { |
| 122 | + if (const auto event_result = m_main_layout.handle_event(event, window)) { |
| 123 | + |
| 124 | + if (const auto additional = event_result.get_additional(); additional.has_value()) { |
| 125 | + const auto value = additional.value(); |
| 126 | + |
| 127 | + if (value.first == ui::EventHandleType::RequestAction) { |
| 128 | + |
| 129 | + |
| 130 | + if (auto* text_input = dynamic_cast<ui::TextInput*>(value.second); text_input != nullptr) { |
| 131 | + spdlog::info("Pressed Enter on TextInput {}", text_input->get_text()); |
| 132 | + |
| 133 | + if (text_input->has_focus()) { |
| 134 | + text_input->unfocus(); |
| 135 | + } |
| 136 | + return true; |
| 137 | + } |
| 138 | + |
| 139 | + |
| 140 | + throw std::runtime_error("Requested action on unknown widget, this is a fatal error"); |
| 141 | + } |
| 142 | + |
| 143 | + throw helper::FatalError( |
| 144 | + fmt::format("Unsupported Handle Type: {}", magic_enum::enum_name(additional->first)) |
| 145 | + ); |
| 146 | + } |
| 147 | + |
125 | 148 | return true; |
126 | 149 | } |
127 | 150 |
|
|
0 commit comments