@@ -146,14 +146,6 @@ void mission_ui_impl::draw_controls()
146146
147147 if ( last_action == " QUIT" ) {
148148 return ;
149- } else if ( last_action == " UP" ) {
150- adjust_selected = true ;
151- ImGui::SetKeyboardFocusHere ( -1 );
152- selected_mission--;
153- } else if ( last_action == " DOWN" ) {
154- adjust_selected = true ;
155- ImGui::SetKeyboardFocusHere ( 1 );
156- selected_mission++;
157149 } else if ( last_action == " NEXT_TAB" || last_action == " RIGHT" ) {
158150 adjust_selected = true ;
159151 selected_mission = 0 ;
@@ -220,17 +212,29 @@ void mission_ui_impl::draw_controls()
220212 ImGui::EndTabBar ();
221213 }
222214
223- if ( selected_mission < 0 ) {
215+ size_t num_entries = umissions.size ();
216+ if ( selected_tab == mission_ui_tab_enum::POINTS_OF_INTEREST ) {
217+ num_entries = upoints_of_interest.size ();
218+ }
219+ const int last_entry = num_entries == 0 ? 0 : ( static_cast <int >( num_entries ) - 1 );
220+ const int previous_selected_mission = selected_mission;
221+ if ( last_action == " UP" ) {
222+ ImGui::SetKeyboardFocusHere ( -1 );
223+ selected_mission--;
224+ } else if ( last_action == " DOWN" ) {
225+ ImGui::SetKeyboardFocusHere ( 1 );
226+ selected_mission++;
227+ } else if ( last_action == " HOME" ) {
224228 selected_mission = 0 ;
229+ } else if ( last_action == " END" ) {
230+ selected_mission = last_entry;
225231 }
226-
227- if ( selected_tab != mission_ui_tab_enum::POINTS_OF_INTEREST &&
228- static_cast <size_t >( selected_mission ) > umissions.size () - 1 ) {
229- selected_mission = umissions.size () - 1 ;
230- } else if ( selected_tab == mission_ui_tab_enum::POINTS_OF_INTEREST &&
231- static_cast <size_t >( selected_mission ) > upoints_of_interest.size () - 1 ) {
232- selected_mission = upoints_of_interest.size () - 1 ;
232+ if ( selected_mission < 0 ) {
233+ selected_mission = last_entry;
234+ } else if ( selected_mission > last_entry ) {
235+ selected_mission = 0 ;
233236 }
237+ adjust_selected |= selected_mission != previous_selected_mission;
234238
235239 // This action needs to be after umissions is populated
236240 if ( last_action == " CONFIRM" ) {
@@ -268,7 +272,7 @@ void mission_ui_impl::draw_controls()
268272 }
269273
270274 if ( ImGui::BeginTable ( " ##MISSION_TABLE" , 2 , ImGuiTableFlags_None,
271- ImVec2 ( window_width, window_height ) ) ) {
275+ ImGui::GetContentRegionAvail ( ) ) ) {
272276 // Missions selection is purposefully thinner than the description, it has less to convey.
273277 if ( selected_tab != mission_ui_tab_enum::POINTS_OF_INTEREST ) {
274278 ImGui::TableSetupColumn ( _ ( " Missions" ), ImGuiTableColumnFlags_WidthStretch,
@@ -303,10 +307,8 @@ void mission_ui_impl::draw_mission_names( std::vector<mission *> missions, int &
303307{
304308 const int num_missions = missions.size ();
305309
306- // roughly 6 lines of header info. title+tab+objective+table headers+2 lines worth of padding between those four
307- const float header_height = ImGui::GetTextLineHeight () * 6 ;
308310 if ( ImGui::BeginListBox ( " ##LISTBOX" , ImVec2 ( table_column_width * 0.75 ,
309- window_height - header_height ) ) ) {
311+ ImGui::GetContentRegionAvail (). y ) ) ) {
310312 for ( int i = 0 ; i < num_missions; i++ ) {
311313 const bool is_selected = selected_mission == i;
312314 ImGui::PushID ( i );
@@ -334,10 +336,8 @@ void mission_ui_impl::draw_point_of_interest_names( std::vector<point_of_interes
334336{
335337 const int num_missions = points_of_interest.size ();
336338
337- // roughly 6 lines of header info. title+tab+objective+table headers+2 lines worth of padding between those four
338- const float header_height = ImGui::GetTextLineHeight () * 6 ;
339339 if ( ImGui::BeginListBox ( " ##LISTBOX" , ImVec2 ( table_column_width * 0.75 ,
340- window_height - header_height ) ) ) {
340+ ImGui::GetContentRegionAvail (). y ) ) ) {
341341 for ( int i = 0 ; i < num_missions; i++ ) {
342342 const bool is_selected = selected_mission == i;
343343 ImGui::PushID ( i );
0 commit comments