MCPcopy Create free account
hub / github.com/crawl/crawl / add_button

Method add_button

crawl-ref/source/outer-menu.cc:281–319  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

279}
280
281void 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
321void OuterMenu::scroll_button_into_view(MenuButton *btn)
322{

Callers 9

_add_menu_sub_itemFunction · 0.80
_choose_nameFunction · 0.80
_add_group_itemMethod · 0.80
_construct_weapon_menuFunction · 0.80
_add_hiscore_rowMethod · 0.80
pick_hintsFunction · 0.80

Calls 9

set_focused_widgetFunction · 0.85
set_wrap_textMethod · 0.80
add_childMethod · 0.80
_get_parentMethod · 0.80
get_sharedMethod · 0.80
formatted_stringClass · 0.70
getMethod · 0.45
currentMethod · 0.45
num_childrenMethod · 0.45

Tested by

no test coverage detected