1010
1111#include < fmt/format.h>
1212
13+ #if defined(_ENABLE_REPLAY_RENDERING)
14+ #include " graphics/video_renderer.hpp"
15+ #endif
1316
1417custom_ui::RecordingComponent::RecordingComponent (
1518 ServiceProvider* service_provider,
@@ -24,7 +27,7 @@ custom_ui::RecordingComponent::RecordingComponent(
2427 ui::Direction::Horizontal,
2528 std::array<double , 1 >{ 0.9 }, ui::RelativeMargin{layout.get_rect (), ui::Direction::Vertical,0.05 }, std::pair<double , double >{ 0.05 , 0.03 },
2629 layout,false
27- },m_metadata{std::move (metadata)}{
30+ },m_metadata{std::move (metadata)},m_current_focus_id{m_main_layout. focus_id ()} {
2831
2932
3033 auto text_layout_index = m_main_layout.add <ui::TileLayout>(
@@ -36,19 +39,26 @@ custom_ui::RecordingComponent::RecordingComponent(
3639 auto * text_layout = m_main_layout.get <ui::TileLayout>(text_layout_index);
3740
3841
39- m_main_layout.add <ui::TextButton>(
42+ auto render_button_index = m_main_layout.add <ui::TextButton>(
4043 service_provider, " Render" , service_provider->font_manager ().get (FontId::Default), Color::white (),
41- focus_helper.focus_id (),
42- [](const ui::TextButton&) -> bool {
43- // TODO: do rendering here, allow hover and click in this situation, it doesn't work as of now
44-
45- return false ;
46- },
44+ focus_helper.focus_id (), [](const ui::TextButton&) -> bool { return false ; },
4745 std::pair<double , double >{ 0.95 , 0.85 },
4846 ui::Alignment{ ui::AlignmentHorizontal::Middle, ui::AlignmentVertical::Center },
4947 std::pair<double , double >{ 0.1 , 0.1 }
5048 );
5149
50+ auto * render_button = m_main_layout.get <ui::TextButton>(render_button_index);
51+
52+ render_button->disable ();
53+
54+ #if defined(_ENABLE_REPLAY_RENDERING)
55+ VideoRendererBackend::is_supported_async ([render_button](bool is_supported) {
56+ if (is_supported) {
57+ render_button->enable ();
58+ }
59+ });
60+ #endif
61+
5262 text_layout->add <ui::Label>(
5363 service_provider, " name: ?" , service_provider->font_manager ().get (FontId::Default), Color::white (),
5464 std::pair<double , double >{ 0.5 , 0.5 },
@@ -96,24 +106,78 @@ void custom_ui::RecordingComponent::render(const ServiceProvider& service_provid
96106 m_main_layout.render (service_provider);
97107}
98108
99- helper::BoolWrapper<std::pair< ui::EventHandleType, ui::Widget*>> custom_ui::RecordingComponent::handle_event (
109+ ui::Widget::EventHandleResult custom_ui::RecordingComponent::handle_event (
100110 const std::shared_ptr<input::InputManager>& input_manager,
101111 const SDL_Event& event
102112) {
103113
114+ auto * render_button = m_main_layout.get <ui::TextButton>(1 );
115+
104116 if (has_focus () and input_manager->get_navigation_event (event) == input::NavigationEvent::OK) {
105- return {
106- true ,
107- { ui::EventHandleType::RequestAction, this }
108- };
117+ if (m_current_focus_id == m_main_layout.focus_id ()) {
118+ return {
119+ true ,
120+ { ui::EventHandleType::RequestAction, this , nullptr }
121+ };
122+ }
123+
124+ if (m_current_focus_id == render_button->focus_id ()) {
125+ return {
126+ true ,
127+ { ui::EventHandleType::RequestAction, render_button, nullptr }
128+ };
129+ }
130+
131+ spdlog::error (" Recording selector has invalid focused element: {}" , m_current_focus_id);
132+ }
133+
134+ if (has_focus ()
135+ and (input_manager->get_navigation_event (event) == input::NavigationEvent::LEFT
136+ or input_manager->get_navigation_event (event) == input::NavigationEvent::RIGHT)) {
137+
138+ if (m_current_focus_id == m_main_layout.focus_id ()) {
139+ m_current_focus_id = render_button->focus_id ();
140+ return true ;
141+ }
142+
143+ if (m_current_focus_id == render_button->focus_id ()) {
144+ m_current_focus_id = m_main_layout.focus_id ();
145+ return true ;
146+ }
147+
148+ spdlog::error (" Recording selector has invalid focused element: {}" , m_current_focus_id);
109149 }
110150
111151
112152 if (const auto hover_result = detect_hover (input_manager, event); hover_result) {
153+
154+
155+ if (const auto render_button_hover_result = render_button->detect_hover (input_manager, event);
156+ render_button_hover_result) {
157+
158+ if (render_button_hover_result.is (ui::ActionType::Clicked)) {
159+
160+ if (not has_focus ()) {
161+ return {
162+ true ,
163+ { ui::EventHandleType::RequestFocus, this , nullptr }
164+ };
165+ }
166+
167+ return {
168+ true ,
169+ { ui::EventHandleType::RequestAction, render_button, this }
170+ };
171+ }
172+
173+ return true ;
174+ }
175+
113176 if (hover_result.is (ui::ActionType::Clicked)) {
177+
114178 return {
115179 true ,
116- { has_focus () ? ui::EventHandleType::RequestAction : ui::EventHandleType::RequestFocus, this }
180+ { has_focus () ? ui::EventHandleType::RequestAction : ui::EventHandleType::RequestFocus, this , nullptr }
117181 };
118182 }
119183 return true ;
0 commit comments