Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrollbar dragging batch two #60953

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/martialarts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2125,7 +2125,10 @@ bool ma_style_callback::key( const input_context &ctxt, const input_event &event
} );
ui.mark_resize();

scrollbar sb;

input_context ict;
sb.set_draggable( ict );
ict.register_action( "UP" );
ict.register_action( "DOWN" );
ict.register_action( "PAGE_UP" );
Expand All @@ -2137,7 +2140,14 @@ bool ma_style_callback::key( const input_context &ctxt, const input_event &event
werase( w );
fold_and_print_from( w, point( 2, 1 ), width, selected, c_light_gray, text );
draw_border( w, BORDER_COLOR, string_format( _( " Style: %s " ), ma.name ) );
draw_scrollbar( w, selected, height, iLines, point_south, BORDER_COLOR, true );
sb.offset_x( 0 )
.offset_y( 1 )
.content_size( iLines )
.viewport_pos( selected )
.viewport_size( height )
.slot_color( BORDER_COLOR )
.scroll_to_last( false )
.apply( w );
wnoutrefresh( w );
} );

Expand All @@ -2154,6 +2164,9 @@ bool ma_style_callback::key( const input_context &ctxt, const input_event &event

if( action == "QUIT" ) {
break;
} else if( sb.handle_dragging( action, ict.get_coordinates_text( catacurses::stdscr ),
selected ) ) {
// Scrollbar has handled action
} else if( action == "DOWN" ) {
selected++;
} else if( action == "UP" ) {
Expand Down
75 changes: 65 additions & 10 deletions src/newcharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,7 @@ void set_traits( tab_manager &tabs, avatar &u, pool_type pool )
bool recalc_traits = false;
// pointer for memory footprint reasons
std::array<std::vector<const trait_and_var *>, 3> sorted_traits;
std::array<scrollbar, 3> trait_sbs;
std::string filterstring;

for( int i = 0; i < 3; i++ ) {
Expand Down Expand Up @@ -1390,6 +1391,9 @@ void set_traits( tab_manager &tabs, avatar &u, pool_type pool )

input_context ctxt( "NEW_CHAR_TRAITS" );
tabs.set_up_tab_navigation( ctxt );
for( scrollbar &sb : trait_sbs ) {
sb.set_draggable( ctxt );
}
ctxt.register_cardinal();
ctxt.register_action( "PAGE_UP", to_translation( "Fast scroll up" ) );
ctxt.register_action( "PAGE_DOWN", to_translation( "Fast scroll down" ) );
Expand Down Expand Up @@ -1517,8 +1521,7 @@ void set_traits( tab_manager &tabs, avatar &u, pool_type pool )
page_width - 2 ) );
}

scrollbar()
.offset_x( page_width * iCurrentPage )
trait_sbs[iCurrentPage].offset_x( page_width * iCurrentPage )
.offset_y( 5 )
.content_size( traits_size[iCurrentPage] )
.viewport_pos( start )
Expand Down Expand Up @@ -1587,8 +1590,23 @@ void set_traits( tab_manager &tabs, avatar &u, pool_type pool )

ui_manager::redraw();
const std::string action = ctxt.handle_input();
std::array< int, 3> cur_sb_pos = iStartPos;
bool scrollbar_handled = false;
for( int i = 0; i < static_cast<int>( trait_sbs.size() ); ++i ) {
if( trait_sbs[i].handle_dragging( action, ctxt.get_coordinates_text( catacurses::stdscr ),
cur_sb_pos[i] ) ) {
if( cur_sb_pos[i] != iStartPos[i] ) {
iStartPos[i] = cur_sb_pos[i];
iCurrentLine[i] = iStartPos[i] + ( iContentHeight - 1 ) / 2;
}
scrollbar_handled = true;
}
}

if( tabs.handle_input( action, ctxt ) ) {
break; // Tab has changed or user has quit the screen
} else if( scrollbar_handled ) {
// No action required, scrollbar has handled it
} else if( action == "LEFT" ) {
iCurWorkingPage = next_avail_page( true );
} else if( action == "RIGHT" ) {
Expand Down Expand Up @@ -1920,6 +1938,7 @@ void set_profession( tab_manager &tabs, avatar &u, pool_type pool )
scrolling_text_view details( w_details_pane );
bool details_recalc = true;
const int iHeaderHeight = 5;
scrollbar list_sb;
const auto init_windows = [&]( ui_adaptor & ui ) {
iContentHeight = TERMY - iHeaderHeight - 1;
w = catacurses::newwin( TERMY, TERMX, point_zero );
Expand All @@ -1934,6 +1953,7 @@ void set_profession( tab_manager &tabs, avatar &u, pool_type pool )
input_context ctxt( "NEW_CHAR_PROFESSIONS" );
tabs.set_up_tab_navigation( ctxt );
details.set_up_navigation( ctxt, scrolling_key_scheme::angle_bracket_scroll );
list_sb.set_draggable( ctxt );
ctxt.register_cardinal();
ctxt.register_action( "PAGE_UP", to_translation( "Fast scroll up" ) );
ctxt.register_action( "PAGE_DOWN", to_translation( "Fast scroll down" ) );
Expand Down Expand Up @@ -2022,8 +2042,7 @@ void set_profession( tab_manager &tabs, avatar &u, pool_type pool )
sorted_profs[i]->gender_appropriate_name( u.male ) );
}

scrollbar()
.offset_x( 0 )
list_sb.offset_x( 0 )
.offset_y( 5 )
.content_size( profs_length )
.viewport_pos( iStartPos )
Expand Down Expand Up @@ -2076,11 +2095,18 @@ void set_profession( tab_manager &tabs, avatar &u, pool_type pool )
const int recmax = profs_length;
const int scroll_rate = recmax > 20 ? 10 : 2;
const int id_for_curr_description = cur_id;
int scrollbar_pos = iStartPos;

if( tabs.handle_input( action, ctxt ) ) {
break; // Tab has changed or user has quit the screen
} else if( details.handle_navigation( action, ctxt ) ) {
//NO FURTHER ACTION REQUIRED
} else if( list_sb.handle_dragging( action, ctxt.get_coordinates_text( catacurses::stdscr ),
scrollbar_pos ) ) {
if( scrollbar_pos != iStartPos ) {
iStartPos = scrollbar_pos;
cur_id = iStartPos + ( iContentHeight - 1 ) / 2;
}
} else if( action == "DOWN" ) {
cur_id++;
if( cur_id > recmax - 1 ) {
Expand Down Expand Up @@ -2273,6 +2299,7 @@ void set_hobbies( tab_manager &tabs, avatar &u, pool_type pool )
scrolling_text_view details( w_details_pane );
bool details_recalc = true;
const int iHeaderHeight = 5;
scrollbar list_sb;

const auto init_windows = [&]( ui_adaptor & ui ) {
iContentHeight = TERMY - iHeaderHeight - 1;
Expand All @@ -2288,6 +2315,7 @@ void set_hobbies( tab_manager &tabs, avatar &u, pool_type pool )
input_context ctxt( "NEW_CHAR_PROFESSIONS" );
tabs.set_up_tab_navigation( ctxt );
details.set_up_navigation( ctxt, scrolling_key_scheme::angle_bracket_scroll );
list_sb.set_draggable( ctxt );
ctxt.register_cardinal();
ctxt.register_action( "PAGE_UP", to_translation( "Fast scroll up" ) );
ctxt.register_action( "PAGE_DOWN", to_translation( "Fast scroll down" ) );
Expand Down Expand Up @@ -2366,8 +2394,7 @@ void set_hobbies( tab_manager &tabs, avatar &u, pool_type pool )
sorted_hobbies[i]->gender_appropriate_name( u.male ) );
}

scrollbar()
.offset_x( 0 )
list_sb.offset_x( 0 )
.offset_y( 5 )
.content_size( profs_length )
.viewport_pos( iStartPos )
Expand Down Expand Up @@ -2410,11 +2437,18 @@ void set_hobbies( tab_manager &tabs, avatar &u, pool_type pool )
const std::string action = ctxt.handle_input();
const int recmax = profs_length;
const int scroll_rate = recmax > 20 ? 10 : 2;
int scrollbar_pos = iStartPos;

if( tabs.handle_input( action, ctxt ) ) {
break; // Tab has changed or user has quit the screen
} else if( details.handle_navigation( action, ctxt ) ) {
//NO FURTHER ACTION REQUIRED
} else if( list_sb.handle_dragging( action, ctxt.get_coordinates_text( catacurses::stdscr ),
scrollbar_pos ) ) {
if( scrollbar_pos != iStartPos ) {
iStartPos = scrollbar_pos;
cur_id = iStartPos + ( iContentHeight - 1 ) / 2;
}
} else if( action == "DOWN" ) {
cur_id++;
if( cur_id > recmax - 1 ) {
Expand Down Expand Up @@ -2611,8 +2645,10 @@ void set_skills( tab_manager &tabs, avatar &u, pool_type pool )
std::vector<std::string> keybinding_hint;
int iContentHeight = 0;
const int iHeaderHeight = 5;
scrollbar list_sb;
input_context ctxt( "NEW_CHAR_SKILLS" );
details.set_up_navigation( ctxt, scrolling_key_scheme::angle_bracket_scroll );
list_sb.set_draggable( ctxt );
ctxt.register_cardinal();
ctxt.register_action( "PAGE_UP", to_translation( "Fast scroll up" ) );
ctxt.register_action( "PAGE_DOWN", to_translation( "Fast scroll down" ) );
Expand Down Expand Up @@ -2794,8 +2830,7 @@ void set_skills( tab_manager &tabs, avatar &u, pool_type pool )
}
}

scrollbar()
.offset_x( 0 )
list_sb.offset_x( 0 )
.offset_y( 5 )
.content_size( num_skills )
.viewport_pos( cur_offset )
Expand All @@ -2812,11 +2847,22 @@ void set_skills( tab_manager &tabs, avatar &u, pool_type pool )
ui_manager::redraw();
const std::string action = ctxt.handle_input();
const int pos_for_curr_description = cur_pos;
int scrollbar_pos = cur_offset;

if( tabs.handle_input( action, ctxt ) ) {
break; // Tab has changed or user has quit the screen
} else if( details.handle_navigation( action, ctxt ) ) {
// NO FURTHER ACTION REQUIRED
} else if( list_sb.handle_dragging( action, ctxt.get_coordinates_text( catacurses::stdscr ),
scrollbar_pos ) ) {
if( scrollbar_pos != cur_offset ) {
cur_offset = scrollbar_pos;
cur_pos = cur_offset + ( iContentHeight - 1 ) / 2; // Get approximate location
get_next( false, false ); // Then make sure it's a skill rather than a heading
if( cur_pos < num_skills / 2 ) {
get_next( true, false ); // Go back to where we were to ensure we can drag to the top
}
}
} else if( action == "DOWN" ) {
get_next( false, false );
} else if( action == "UP" ) {
Expand Down Expand Up @@ -3011,6 +3057,7 @@ void set_scenario( tab_manager &tabs, avatar &u, pool_type pool )
scrolling_text_view details( w_details_pane );
bool details_recalc = true;
const int iHeaderHeight = 5;
scrollbar list_sb;

const auto init_windows = [&]( ui_adaptor & ui ) {
iContentHeight = TERMY - iHeaderHeight - 1;
Expand All @@ -3027,6 +3074,7 @@ void set_scenario( tab_manager &tabs, avatar &u, pool_type pool )
input_context ctxt( "NEW_CHAR_SCENARIOS" );
tabs.set_up_tab_navigation( ctxt );
details.set_up_navigation( ctxt, scrolling_key_scheme::angle_bracket_scroll );
list_sb.set_draggable( ctxt );
ctxt.register_cardinal();
ctxt.register_action( "PAGE_UP", to_translation( "Fast scroll up" ) );
ctxt.register_action( "PAGE_DOWN", to_translation( "Fast scroll down" ) );
Expand Down Expand Up @@ -3116,8 +3164,8 @@ void set_scenario( tab_manager &tabs, avatar &u, pool_type pool )

}

scrollbar()
.offset_x( 0 )

list_sb.offset_x( 0 )
.offset_y( 5 )
.content_size( scens_length )
.viewport_pos( iStartPos )
Expand Down Expand Up @@ -3177,11 +3225,18 @@ void set_scenario( tab_manager &tabs, avatar &u, pool_type pool )
const std::string action = ctxt.handle_input();
const int scroll_rate = scens_length > 20 ? 5 : 2;
const int id_for_curr_description = cur_id;
int scrollbar_pos = iStartPos;

if( tabs.handle_input( action, ctxt ) ) {
break; // Tab has changed or user has quit the screen
} else if( details.handle_navigation( action, ctxt ) ) {
// NO FURTHER ACTION REQUIRED
} else if( list_sb.handle_dragging( action, ctxt.get_coordinates_text( catacurses::stdscr ),
scrollbar_pos ) ) {
if( scrollbar_pos != iStartPos ) {
iStartPos = scrollbar_pos;
cur_id = iStartPos + ( iContentHeight - 1 ) / 2;
}
} else if( action == "DOWN" ) {
cur_id++;
if( cur_id > scens_length - 1 ) {
Expand Down
Loading