Pt ModalListPicker::DetermineListHeight(const Pt& _drop_down_size) { auto drop_down_size = _drop_down_size; // Determine the expected height auto border_thick = 2 * GG::Y(ListBox::BORDER_THICK); auto num_rows = std::min<int>(m_num_shown_rows, LB()->NumRows()); auto row_height = (*LB()->FirstRowShown())->Height(); auto expected_height = num_rows * row_height + border_thick; // Shrink the height if too near app edge. auto dist_to_app_edge = GUI::GetGUI()->AppHeight() - m_relative_to_wnd->Bottom(); if (expected_height > dist_to_app_edge && row_height > 0) { auto reduced_num_rows = std::max(GG::Y(1), (dist_to_app_edge - border_thick) / row_height); expected_height = reduced_num_rows * row_height + border_thick; } drop_down_size.y = expected_height; LB()->Resize(drop_down_size); if (!LB()->Selections().empty()) LB()->BringRowIntoView(*(LB()->Selections().begin())); GUI::GetGUI()->PreRenderWindow(LB()); return drop_down_size; }
void ModalListPicker::CompleteConstruction() { m_lb_wnd->SelRowsChangedSignal.connect( boost::bind(&ModalListPicker::LBSelChangedSlot, this, _1)); m_lb_wnd->LeftClickedRowSignal.connect( boost::bind(&ModalListPicker::LBLeftClickSlot, this, _1, _2, _3)); GUI::GetGUI()->WindowResizedSignal.connect( boost::bind(&ModalListPicker::WindowResizedSlot, this, _1, _2)); AttachChild(m_lb_wnd); m_lb_wnd->InstallEventFilter(shared_from_this()); if (INSTRUMENT_ALL_SIGNALS) SelChangedSignal.connect(ModalListPickerSelChangedEcho(*this)); if (m_relative_to_wnd) m_lb_wnd->MoveTo(Pt(m_relative_to_wnd->Left(), m_relative_to_wnd->Bottom())); m_lb_wnd->Hide(); }
void ModalListPicker::CorrectListSize() { // reset size of displayed drop list based on number of shown rows set. // assumes that all rows have the same height. // adds some magic padding for now to prevent the scroll bars showing up. if (!m_relative_to_wnd) return; if (LB()->Visible()) return; LB()->MoveTo(Pt(m_relative_to_wnd->Left(), m_relative_to_wnd->Bottom())); Pt drop_down_size(m_relative_to_wnd->DroppedRowWidth(), m_relative_to_wnd->ClientHeight()); if (LB()->Empty()) { LB()->Resize(drop_down_size); } else { LB()->Show(); // The purpose of this code is to produce a drop down list that // will be exactly m_num_shown_rows high and make sure that the // selected row is prerendered in the same way when the drop down // list is open or closed. // The list needs to be resized twice. The first resize with an // estimated row height will add any list box chrome, like scroll // bars to the list and may change the height of the row. The // second resize uses the corrected row height to finalize the drop // down list size. // Note: Placing a tighter constraint on valid DropDownList rows // of always returning the same fixed height regardless of status // (width, prerender etc.) would mean this code could be reduced to // check height and resize list just once. drop_down_size = DetermineListHeight(drop_down_size); DetermineListHeight(drop_down_size); LB()->Hide(); } }