Skip to content

Commit

Permalink
Place cursor at item names in construction and crafting menu as expec…
Browse files Browse the repository at this point in the history
…ted by screen readers
  • Loading branch information
Qrox committed Apr 15, 2020
1 parent b793146 commit b3fb930
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
13 changes: 11 additions & 2 deletions src/construction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,13 +540,17 @@ construction_id construction_menu( const bool blueprint )
// Determine where in the master list to start printing
calcStartPos( offset, select, w_list_height, constructs.size() );
// Print the constructions between offset and max (or how many will fit)
cata::optional<point> cursor_pos;
for( size_t i = 0; static_cast<int>( i ) < w_list_height &&
( i + offset ) < constructs.size(); i++ ) {
int current = i + offset;
std::string con_name = constructs[current];
bool highlight = ( current == select );

trim_and_print( w_list, point( 0, i ), w_list_width,
const point print_from( 0, i );
if( highlight ) {
cursor_pos = print_from;
}
trim_and_print( w_list, print_from, w_list_width,
construction_color( con_name, highlight ), _( con_name ) );
}

Expand Down Expand Up @@ -600,6 +604,11 @@ construction_id construction_menu( const bool blueprint )

draw_scrollbar( w_con, select, w_list_height, constructs.size(), point( 0, 3 ) );
wrefresh( w_con );

// place the cursor at the selected construction name as expected by screen readers
if( cursor_pos ) {
wmove( w_list, cursor_pos.value() );
}
wrefresh( w_list );
} );

Expand Down
42 changes: 34 additions & 8 deletions src/crafting_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ const recipe *select_crafting_recipe( int &batch_size )
mvwputch( w_data, point( 0, dataHeight - 1 ), BORDER_COLOR, LINE_XXOO ); // |_
mvwputch( w_data, point( width - 1, dataHeight - 1 ), BORDER_COLOR, LINE_XOOX ); // _|

cata::optional<point> cursor_pos;
int recmin = 0, recmax = current.size();
if( recmax > dataLines ) {
if( line <= recmin + dataHalfLines ) {
Expand All @@ -369,8 +370,13 @@ const recipe *select_crafting_recipe( int &batch_size )
tmp_name = string_format( _( "%2dx %s" ), i + 1, tmp_name );
}
mvwprintz( w_data, point( 2, i - recmin ), c_dark_gray, "" ); // Clear the line
nc_color col = i == line ? available[i].selected_color() : available[i].color();
mvwprintz( w_data, point( 2, i - recmin ), col, utf8_truncate( tmp_name, 28 ) );
const bool highlight = i == line;
const nc_color col = highlight ? available[i].selected_color() : available[i].color();
const point print_from( 2, i - recmin );
if( highlight ) {
cursor_pos = print_from;
}
mvwprintz( w_data, print_from, col, utf8_truncate( tmp_name, 28 ) );
}
} else if( line >= recmax - dataHalfLines ) {
for( int i = recmax - dataLines; i < recmax; ++i ) {
Expand All @@ -379,8 +385,13 @@ const recipe *select_crafting_recipe( int &batch_size )
tmp_name = string_format( _( "%2dx %s" ), i + 1, tmp_name );
}
mvwprintz( w_data, point( 2, dataLines + i - recmax ), c_light_gray, "" ); // Clear the line
nc_color col = i == line ? available[i].selected_color() : available[i].color();
mvwprintz( w_data, point( 2, dataLines + i - recmax ), col,
const bool highlight = i == line;
const nc_color col = highlight ? available[i].selected_color() : available[i].color();
const point print_from( 2, dataLines + i - recmax );
if( highlight ) {
cursor_pos = print_from;
}
mvwprintz( w_data, print_from, col,
utf8_truncate( tmp_name, 28 ) );
}
} else {
Expand All @@ -390,8 +401,13 @@ const recipe *select_crafting_recipe( int &batch_size )
tmp_name = string_format( _( "%2dx %s" ), i + 1, tmp_name );
}
mvwprintz( w_data, point( 2, dataHalfLines + i - line ), c_light_gray, "" ); // Clear the line
nc_color col = i == line ? available[i].selected_color() : available[i].color();
mvwprintz( w_data, point( 2, dataHalfLines + i - line ), col,
const bool highlight = i == line;
const nc_color col = highlight ? available[i].selected_color() : available[i].color();
const point print_from( 2, dataHalfLines + i - line );
if( highlight ) {
cursor_pos = print_from;
}
mvwprintz( w_data, print_from, col,
utf8_truncate( tmp_name, 28 ) );
}
}
Expand All @@ -401,8 +417,13 @@ const recipe *select_crafting_recipe( int &batch_size )
if( batch ) {
tmp_name = string_format( _( "%2dx %s" ), i + 1, tmp_name );
}
nc_color col = i == line ? available[i].selected_color() : available[i].color();
mvwprintz( w_data, point( 2, i ), col, utf8_truncate( tmp_name, 28 ) );
const bool highlight = i == line;
const nc_color col = highlight ? available[i].selected_color() : available[i].color();
const point print_from( 2, i );
if( highlight ) {
cursor_pos = print_from;
}
mvwprintz( w_data, print_from, col, utf8_truncate( tmp_name, 28 ) );
}
}

Expand Down Expand Up @@ -561,6 +582,11 @@ const recipe *select_crafting_recipe( int &batch_size )
data.use_full_win = true;
draw_item_info( w_iteminfo, data );
}

if( cursor_pos ) {
// place the cursor at the selected item name as expected by screen readers
wmove( w_data, cursor_pos.value() );
}
} );

do {
Expand Down

0 comments on commit b3fb930

Please sign in to comment.