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

[DO NOT MERGE] clang-tidy ui.cpp #78616

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
37 changes: 17 additions & 20 deletions src/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,36 +248,36 @@ static std::optional<input_event> hotkey_from_char( const int ch )

uilist_entry::uilist_entry( const std::string &txt )
: retval( -1 ), enabled( true ), hotkey( std::nullopt ), txt( txt ),
text_color( c_red_red ), _txt_nocolor_cached( "" ), _ctxt_nocolor_cached( "" )
text_color( c_red_red )
{

}

uilist_entry::uilist_entry( const std::string &txt, const std::string &desc )
: retval( -1 ), enabled( true ), hotkey( std::nullopt ), txt( txt ),
desc( desc ), text_color( c_red_red ), _txt_nocolor_cached( "" ), _ctxt_nocolor_cached( "" )
desc( desc ), text_color( c_red_red )
{

}

uilist_entry::uilist_entry( const std::string &txt, const int key )
: retval( -1 ), enabled( true ), hotkey( hotkey_from_char( key ) ), txt( txt ),
text_color( c_red_red ), _txt_nocolor_cached( "" ), _ctxt_nocolor_cached( "" )
text_color( c_red_red )
{

}

uilist_entry::uilist_entry( const std::string &txt, const std::optional<input_event> &key )
: retval( -1 ), enabled( true ), hotkey( key ), txt( txt ),
text_color( c_red_red ), _txt_nocolor_cached( "" ), _ctxt_nocolor_cached( "" )
text_color( c_red_red )
{

}

uilist_entry::uilist_entry( const int retval, const bool enabled, const int key,
const std::string &txt )
: retval( retval ), enabled( enabled ), hotkey( hotkey_from_char( key ) ), txt( txt ),
text_color( c_red_red ), _txt_nocolor_cached( "" ), _ctxt_nocolor_cached( "" )
text_color( c_red_red )
{

}
Expand All @@ -286,23 +286,23 @@ uilist_entry::uilist_entry( const int retval, const bool enabled,
const std::optional<input_event> &key,
const std::string &txt )
: retval( retval ), enabled( enabled ), hotkey( key ), txt( txt ),
text_color( c_red_red ), _txt_nocolor_cached( "" ), _ctxt_nocolor_cached( "" )
text_color( c_red_red )
{

}

uilist_entry::uilist_entry( const int retval, const bool enabled, const int key,
const std::string &txt, const std::string &desc )
: retval( retval ), enabled( enabled ), hotkey( hotkey_from_char( key ) ), txt( txt ),
desc( desc ), text_color( c_red_red ), _txt_nocolor_cached( "" ), _ctxt_nocolor_cached( "" )
desc( desc ), text_color( c_red_red )
{

}

uilist_entry::uilist_entry( const int retval, const bool enabled,
const std::optional<input_event> &key, const std::string &txt, const std::string &desc )
: retval( retval ), enabled( enabled ), hotkey( key ), txt( txt ),
desc( desc ), text_color( c_red_red ), _txt_nocolor_cached( "" ), _ctxt_nocolor_cached( "" )
desc( desc ), text_color( c_red_red )
{

}
Expand All @@ -311,8 +311,7 @@ uilist_entry::uilist_entry( const int retval, const bool enabled, const int key,
const std::string &txt, const std::string &desc,
const std::string &column )
: retval( retval ), enabled( enabled ), hotkey( hotkey_from_char( key ) ), txt( txt ),
desc( desc ), ctxt( column ), text_color( c_red_red ), _txt_nocolor_cached( "" ),
_ctxt_nocolor_cached( "" )
desc( desc ), ctxt( column ), text_color( c_red_red )
{

}
Expand All @@ -322,8 +321,7 @@ uilist_entry::uilist_entry( const int retval, const bool enabled,
const std::string &txt, const std::string &desc,
const std::string &column )
: retval( retval ), enabled( enabled ), hotkey( key ), txt( txt ),
desc( desc ), ctxt( column ), text_color( c_red_red ), _txt_nocolor_cached( "" ),
_ctxt_nocolor_cached( "" )
desc( desc ), ctxt( column ), text_color( c_red_red )
{

}
Expand All @@ -332,21 +330,20 @@ uilist_entry::uilist_entry( const int retval, const bool enabled, const int key,
const std::string &txt,
const nc_color &keycolor, const nc_color &txtcolor )
: retval( retval ), enabled( enabled ), hotkey( hotkey_from_char( key ) ), txt( txt ),
hotkey_color( keycolor ), text_color( txtcolor ), _txt_nocolor_cached( "" ),
_ctxt_nocolor_cached( "" )
hotkey_color( keycolor ), text_color( txtcolor )
{

}

const std::string uilist_entry::_txt_nocolor()
const std::string &uilist_entry::_txt_nocolor()
{
if( _txt_nocolor_cached.empty() && !txt.empty() ) {
_txt_nocolor_cached = remove_color_tags( txt );
}
return _txt_nocolor_cached;
}

const std::string uilist_entry::_ctxt_nocolor()
const std::string &uilist_entry::_ctxt_nocolor()
{
if( _ctxt_nocolor_cached.empty() && !ctxt.empty() ) {
_ctxt_nocolor_cached = remove_color_tags( ctxt );
Expand Down Expand Up @@ -678,8 +675,8 @@ void uilist::calc_data()
float expected_num_lines = desc_size.y / ImGui::GetTextLineHeight();
desc_size.y += ( s.ItemSpacing.y * expected_num_lines ) + ( s.ItemSpacing.y * 2.0 );
}
float additional_height = title_size.y + text_size.y + desc_size.y + tabs_size.y + 2.0 *
( s.FramePadding.y + s.WindowBorderSize );
float additional_height = title_size.y + text_size.y + desc_size.y + tabs_size.y +
2.0 * ( s.FramePadding.y + s.WindowBorderSize );

if( vmax * ImGui::GetTextLineHeightWithSpacing() + additional_height >
0.9 * ImGui::GetMainViewport()->Size.y ) {
Expand Down Expand Up @@ -719,8 +716,8 @@ void uilist::calc_data()
extra_space_right = callback->desired_extra_space_right( ) + s.FramePadding.x;
}

float longest_line_width = std::max( std::max( title_size.x, text_size.x ),
std::max( calculated_menu_size.x, desc_size.x ) );
float longest_line_width = std::max( { title_size.x, text_size.x,
calculated_menu_size.x, desc_size.x } );
calculated_bounds.w = extra_space_left + extra_space_right + longest_line_width
+ 2 * ( s.WindowPadding.x + s.WindowBorderSize );
calculated_bounds.h = calculated_menu_size.y + additional_height;
Expand Down
4 changes: 2 additions & 2 deletions src/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ struct uilist_entry {
{}

public:
const std::string _txt_nocolor(); // what it says on the tin
const std::string _ctxt_nocolor(); // second column text
const std::string &_txt_nocolor(); // what it says on the tin
const std::string &_ctxt_nocolor(); // second column text
private:
std::string _txt_nocolor_cached; // cached return values of the above
std::string _ctxt_nocolor_cached;
Expand Down
4 changes: 2 additions & 2 deletions tests/coverage_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ static const flag_id json_flag_FILTHY( "FILTHY" );

static const mtype_id mon_manhack( "mon_manhack" );

static const sub_bodypart_str_id sub_body_part_eyes_right( "eyes_right" );

static const int num_iters = 10000;
static constexpr tripoint_bub_ms dude_pos( HALF_MAPSIZE_X + 4, HALF_MAPSIZE_Y, 0 );
static constexpr tripoint_bub_ms mon_pos( HALF_MAPSIZE_X + 3, HALF_MAPSIZE_Y, 0 );
static constexpr tripoint_bub_ms badguy_pos( HALF_MAPSIZE_X + 1, HALF_MAPSIZE_Y, 0 );

static const sub_bodypart_str_id sub_body_part_eyes_right( "eyes_right" );

static void check_near( const std::string &subject, float actual, const float expected,
const float tolerance )
{
Expand Down
4 changes: 2 additions & 2 deletions tests/iteminfo_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ static const recipe_id recipe_pur_tablets( "pur_tablets" );

static const skill_id skill_survival( "survival" );

static const sub_bodypart_str_id sub_body_part_eyes_right( "eyes_right" );

static const trait_id trait_ANTIFRUIT( "ANTIFRUIT" );
static const trait_id trait_CANNIBAL( "CANNIBAL" );
static const trait_id trait_WOOLALLERGY( "WOOLALLERGY" );

static const vitamin_id vitamin_human_flesh_vitamin( "human_flesh_vitamin" );

static const sub_bodypart_str_id sub_body_part_eyes_right( "eyes_right" );

// ITEM INFO
// =========
//
Expand Down
Loading