Skip to content

Commit

Permalink
Merge pull request CleverRaven#78185 from CleverRaven/ui-item-action-…
Browse files Browse the repository at this point in the history
…columns

Draw item name in separate column of item action menu
  • Loading branch information
Night-Pryanik authored Nov 27, 2024
2 parents 9edfa14 + d916229 commit ad13310
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/item_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,27 +339,20 @@ void game::item_action_menu( item_location loc )
auto iter = menu_items.begin();
std::advance( iter, iactions.size() );
sort_menu( iter, menu_items.end() );
// Determine max lengths, to print the menu nicely.
std::pair<int, int> max_len;
for( const auto &elem : menu_items ) {
max_len.first = std::max( max_len.first, utf8_width( std::get<1>( elem ), true ) );
max_len.second = std::max( max_len.second, utf8_width( std::get<2>( elem ), true ) );
}
// Fill the menu.
for( const auto &elem : menu_items ) {
std::string ss;
ss += std::get<1>( elem );
ss += std::string( max_len.first - utf8_width( std::get<1>( elem ), true ), ' ' );
ss += std::string( 4, ' ' );

ss += std::get<2>( elem );
ss += std::string( max_len.second - utf8_width( std::get<2>( elem ), true ), ' ' );
std::string ss_ctxt;
ss_ctxt += std::get<2>( elem );

const std::optional<input_event> bind = key_bound_to( ctxt, std::get<0>( elem ) );
const bool enabled = assigned_action( std::get<0>( elem ) );
const std::string desc = std::get<3>( elem ) ;

kmenu.addentry_desc( num, enabled, bind, ss, desc );
kmenu.entries[num].ctxt = ss_ctxt;
num++;
}

Expand Down

0 comments on commit ad13310

Please sign in to comment.