Skip to content

Commit

Permalink
Pull ggtucker column changes to fix several column issues
Browse files Browse the repository at this point in the history
From this pull request:

ocornut/imgui#913

Preserve column widths when resizing
Force column dividers to always stay visible

Also adds GetColumnWidth() call
  • Loading branch information
mikesart committed Apr 20, 2017
1 parent a3995da commit 979bafe
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 106 deletions.
34 changes: 18 additions & 16 deletions src/gpuvis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ static int imgui_ini_load_settings_cb( CIniFile *inifile, int index, ImGuiIniDat
template < size_t T >
void imgui_headers( const char *title, const std::array< const char *, T > &headers )
{
ImGui::Columns( headers.size(), "events" );
ImGuiColumnsFlags flags = 0;

ImGui::BeginColumns( title, headers.size(), flags );

for ( const char *str : headers )
{
Expand Down Expand Up @@ -765,7 +767,7 @@ void TraceWin::render_color_picker()
if ( !ImGui::CollapsingHeader( "Color Picker", ImGuiTreeNodeFlags_DefaultOpen ) )
return;

ImGui::Columns( 2 );
ImGui::BeginColumns( "ColorPicker", 2, 0 );
ImGui::SetColumnOffset( 1, imgui_scale( 200.0f ) );

/*
Expand Down Expand Up @@ -800,7 +802,7 @@ void TraceWin::render_color_picker()
col_set( ( colors_t )m_selected_color, color );
}

ImGui::Columns( 1 );
ImGui::EndColumns();
}

const char *filter_get_key_func( StrPool *strpool, const char *name, size_t len )
Expand Down Expand Up @@ -1201,7 +1203,7 @@ void TraceWin::render_trace_info()
ImGui::NextColumn();
}

ImGui::Columns( 1 );
ImGui::EndColumns();
}
}

Expand All @@ -1227,7 +1229,7 @@ void TraceWin::render_trace_info()
}
}

ImGui::Columns( 1 );
ImGui::EndColumns();
}
}

Expand Down Expand Up @@ -1326,30 +1328,30 @@ static float get_keyboard_scroll_lines( float visible_rows )
}

template< size_t T>
void TraceWin::save_restore_column_sizes( CIniFile &inifile,
void TraceWin::save_restore_column_sizes( CIniFile &inifile, const char *name,
const std::array< const char *, T > &columns )
{
if ( !m_columns_inited )
{
// Try to restore the column sizes from our ini file.
for ( size_t i = 1; i < columns.size(); i++ )
for ( size_t i = 0; i < columns.size(); i++ )
{
float val = inifile.GetFloat( string_format( "column_offset%lu", i ).c_str(), -1.0f );
float val = inifile.GetFloat( string_format( "%s_column_width_%lu", name, i ).c_str(), -1.0f );
if ( val <= 0.0f )
break;

ImGui::SetColumnOffset( i, val );
ImGui::SetColumnWidth( i, val );
}

m_columns_inited = true;
}
else if ( ImGui::IsWindowHovered() && ImGui::IsMouseReleased( 0 ) )
{
// Someone released the mouse - save column sizes in case they were changed.
for ( size_t i = 1; i < columns.size(); i++ )
for ( size_t i = 0; i < columns.size(); i++ )
{
inifile.PutFloat( string_format( "column_offset%lu", i ).c_str(),
ImGui::GetColumnOffset( i ) );
inifile.PutFloat( string_format( "%s_column_width_%lu", name, i ).c_str(),
ImGui::GetColumnWidth( i ) );
}
}
}
Expand Down Expand Up @@ -1439,7 +1441,7 @@ void TraceWin::render_events_list( CIniFile &inifile )
{ "Id", "Time Stamp", "Task", "Event", "context", "Info" };
imgui_headers( "events", columns );

save_restore_column_sizes( inifile, columns );
save_restore_column_sizes( inifile, "event_list", columns );

if ( start_idx > 0 )
{
Expand Down Expand Up @@ -1600,7 +1602,7 @@ void TraceWin::render_events_list( CIniFile &inifile )
m_events_list_popup_eventid = INVALID_ID;
}

ImGui::Columns( 1 );
ImGui::EndColumns();
ImGui::EndChild();
}

Expand Down Expand Up @@ -1856,7 +1858,7 @@ void TraceConsole::render( TraceLoader &loader )

if ( ImGui::CollapsingHeader( "Opened Event Files", ImGuiTreeNodeFlags_DefaultOpen ) )
{
ImGui::Columns( 2, "files" );
ImGui::BeginColumns( "EventFiles", 2 );

ImGui::Separator();

Expand Down Expand Up @@ -1885,7 +1887,7 @@ void TraceConsole::render( TraceLoader &loader )
}
}

ImGui::Columns( 1 );
ImGui::EndColumns();
ImGui::Separator();
}

Expand Down
2 changes: 1 addition & 1 deletion src/gpuvis.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class TraceWin
void handle_graph_keyboard_scroll();

template< size_t T >
void save_restore_column_sizes( CIniFile &inifile,
void save_restore_column_sizes( CIniFile &inifile, const char *name,
const std::array< const char *, T > &columns );

void handle_mouse_graph( class graph_info_t &gi );
Expand Down
Loading

0 comments on commit 979bafe

Please sign in to comment.