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

Place cursor at highlighted item name in construction and crafting menus as expected by screen readers #39588

Merged
merged 1 commit into from
Apr 15, 2020
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
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
53 changes: 39 additions & 14 deletions src/crafting_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,6 @@ const recipe *select_crafting_recipe( int &batch_size )

w_head = catacurses::newwin( headHeight, width, point( wStart, 0 ) );
w_subhead = catacurses::newwin( subHeadHeight, width, point( wStart, 3 ) );
w_data = catacurses::newwin( dataHeight, width, point( wStart,
headHeight + subHeadHeight ) );

if( isWide ) {
item_info_width = width - FULL_SCREEN_WIDTH - 2;
Expand All @@ -229,6 +227,9 @@ const recipe *select_crafting_recipe( int &batch_size )
w_iteminfo = {};
}

w_data = catacurses::newwin( dataHeight, width - item_info_width,
point( wStart, headHeight + subHeadHeight ) );

ui.position( point( wStart, 0 ), point( width, TERMY ) );
} );
ui.mark_resize();
Expand Down Expand Up @@ -360,6 +361,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 +371,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 +386,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 +402,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 +418,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 @@ -467,8 +489,6 @@ const recipe *select_crafting_recipe( int &batch_size )
const int xpos = 30;

if( display_mode == 0 ) {
const int width = getmaxx( w_data ) - xpos - item_info_width;

auto player_skill = g->u.get_skill_level( current[line]->skill_used );
std::string difficulty_color =
current[ line ]->difficulty > player_skill ? "yellow" : "green";
Expand All @@ -483,7 +503,7 @@ const recipe *select_crafting_recipe( int &batch_size )
( !current[line]->skill_used ? "" : primary_skill_level )
) );

ypos += fold_and_print( w_data, point( xpos, ypos ), width, col,
ypos += fold_and_print( w_data, point( xpos, ypos ), pane, col,
_( "Other skills: %s" ),
current[line]->required_skills_string( &g->u ) );

Expand Down Expand Up @@ -551,7 +571,6 @@ const recipe *select_crafting_recipe( int &batch_size )
}

draw_scrollbar( w_data, line, dataLines, recmax, point_zero );
wrefresh( w_data );

if( isWide && !current.empty() ) {
item_info_data data = item_info_data_from_recipe( current[line], count, item_info_scroll );
Expand All @@ -561,6 +580,12 @@ 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() );
}
wrefresh( w_data );
} );

do {
Expand Down