| 279 | } |
| 280 | |
| 281 | void OuterMenu::add_button(shared_ptr<MenuButton> btn, int x, int y) |
| 282 | { |
| 283 | ASSERT(x >= 0 && x < m_width); |
| 284 | ASSERT(y >= 0 && y < m_height); |
| 285 | |
| 286 | MenuButton*& item = m_buttons[y*m_width + x]; |
| 287 | ASSERT(item == nullptr); |
| 288 | item = btn.get(); |
| 289 | |
| 290 | // TODO: once we add event capturing, move handlers to menu |
| 291 | btn->on_focusin_event([this, x, y](const Event&) { |
| 292 | if (m_description_indexes[y*this->m_width+x] != -1) |
| 293 | descriptions->current() = m_description_indexes[y*this->m_width+x]; |
| 294 | return false; |
| 295 | }); |
| 296 | btn->on_mouseenter_event([btn](const MouseEvent&) { |
| 297 | if (focus_button_on_mouseenter) |
| 298 | ui::set_focused_widget(btn.get()); |
| 299 | return false; |
| 300 | }); |
| 301 | btn->on_mousemove_event([btn](const MouseEvent&) { |
| 302 | ui::set_focused_widget(btn.get()); |
| 303 | return false; |
| 304 | }); |
| 305 | |
| 306 | if (descriptions) |
| 307 | { |
| 308 | auto desc_text = make_shared<Text>(formatted_string(btn->description, WHITE)); |
| 309 | desc_text->set_wrap_text(true); |
| 310 | descriptions->add_child(std::move(desc_text)); |
| 311 | m_description_indexes[y*m_width + x] = descriptions->num_children()-1; |
| 312 | } |
| 313 | |
| 314 | Widget *r = nullptr; |
| 315 | for (Widget *p = btn.get(); p; p = p->_get_parent()) |
| 316 | r = p; |
| 317 | ASSERT(r); |
| 318 | m_grid->add_child(r->get_shared(), x, y); |
| 319 | } |
| 320 | |
| 321 | void OuterMenu::scroll_button_into_view(MenuButton *btn) |
| 322 | { |
no test coverage detected