Merge pull request #503 from tvoeroes/timeline-animation-tweaks

Timeline animation tweaks
This commit is contained in:
Bartosz Taudul 2022-12-19 21:03:18 +01:00 committed by GitHub
commit 16d9491148
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 40 deletions

View File

@ -32,13 +32,9 @@ void TimelineController::End( double pxns, int offset, const ImVec2& wpos, bool
} }
const auto scrollPos = ImGui::GetScrollY(); const auto scrollPos = ImGui::GetScrollY();
if( scrollPos == 0 && m_scroll != 0 ) if( ( scrollPos == 0 && m_scroll != 0 ) || offset > m_height )
{ {
m_height = 0; m_height = offset;
}
else
{
if( offset > m_height ) m_height = offset;
} }
m_scroll = scrollPos; m_scroll = scrollPos;
} }

View File

@ -12,7 +12,6 @@ TimelineItem::TimelineItem( View& view, Worker& worker )
: m_visible( true ) : m_visible( true )
, m_showFull( true ) , m_showFull( true )
, m_height( 0 ) , m_height( 0 )
, m_offset( 0 )
, m_view( view ) , m_view( view )
, m_worker( worker ) , m_worker( worker )
{ {
@ -22,8 +21,7 @@ void TimelineItem::Draw( bool firstFrame, double pxns, int& offset, const ImVec2
{ {
if( !IsVisible() ) if( !IsVisible() )
{ {
m_height = 0; if( m_height != 0 ) AdjustThreadHeight( firstFrame, offset, offset );
m_offset = 0;
return; return;
} }
if( IsEmpty() ) return; if( IsEmpty() ) return;
@ -31,7 +29,7 @@ void TimelineItem::Draw( bool firstFrame, double pxns, int& offset, const ImVec2
const auto w = ImGui::GetContentRegionAvail().x - 1; const auto w = ImGui::GetContentRegionAvail().x - 1;
const auto ty = ImGui::GetTextLineHeight(); const auto ty = ImGui::GetTextLineHeight();
const auto ostep = ty + 1; const auto ostep = ty + 1;
const auto yPos = AdjustThreadPosition( wpos.y, offset ); const auto yPos = wpos.y + offset;
const auto dpos = wpos + ImVec2( 0.5f, 0.5f ); const auto dpos = wpos + ImVec2( 0.5f, 0.5f );
const auto oldOffset = offset; const auto oldOffset = offset;
auto draw = ImGui::GetWindowDrawList(); auto draw = ImGui::GetWindowDrawList();
@ -44,9 +42,8 @@ void TimelineItem::Draw( bool firstFrame, double pxns, int& offset, const ImVec2
{ {
if( !DrawContents( pxns, offset, wpos, hover, yMin, yMax ) && !m_view.GetViewData().drawEmptyLabels ) if( !DrawContents( pxns, offset, wpos, hover, yMin, yMax ) && !m_view.GetViewData().drawEmptyLabels )
{ {
m_height = 0;
m_offset = 0;
offset = oldOffset; offset = oldOffset;
AdjustThreadHeight( firstFrame, oldOffset, offset );
ImGui::PopClipRect(); ImGui::PopClipRect();
ImGui::PopID(); ImGui::PopID();
return; return;
@ -123,44 +120,31 @@ void TimelineItem::Draw( bool firstFrame, double pxns, int& offset, const ImVec2
void TimelineItem::AdjustThreadHeight( bool firstFrame, int oldOffset, int& offset ) void TimelineItem::AdjustThreadHeight( bool firstFrame, int oldOffset, int& offset )
{ {
const auto speed = 4.0;
const auto baseMove = 1.0;
const auto h = offset - oldOffset; const auto h = offset - oldOffset;
if( m_height > h )
{
m_height = h;
offset = oldOffset + m_height;
}
else if( m_height < h )
{
if( firstFrame ) if( firstFrame )
{ {
m_height = h; m_height = h;
offset = oldOffset + h; }
else if( m_height != h )
{
const auto diff = h - m_height;
const auto preClampMove = diff * speed * ImGui::GetIO().DeltaTime;
if( diff > 0 )
{
const auto move = preClampMove + baseMove;
m_height = int( std::min<double>( m_height + move, h ) );
} }
else else
{ {
const auto diff = h - m_height; const auto move = preClampMove - baseMove;
const auto move = std::max( 2.0, diff * 10.0 * ImGui::GetIO().DeltaTime ); m_height = int( std::max<double>( m_height + move, h ) );
m_height = int( std::min<double>( m_height + move, h ) ); }
s_wasActive = true;
}
offset = oldOffset + m_height; offset = oldOffset + m_height;
s_wasActive = true;
}
}
}
float TimelineItem::AdjustThreadPosition( float wy, int& offset )
{
if( m_offset < offset )
{
m_offset = offset;
}
else if( m_offset > offset )
{
const auto diff = m_offset - offset;
const auto move = std::max( 2.0, diff * 10.0 * ImGui::GetIO().DeltaTime );
offset = m_offset = int( std::max<double>( m_offset - move, offset ) );
s_wasActive = true;
}
return offset + wy;
} }
void TimelineItem::VisibilityCheckbox() void TimelineItem::VisibilityCheckbox()

View File

@ -47,10 +47,8 @@ protected:
private: private:
void AdjustThreadHeight( bool firstFrame, int oldOffset, int& offset ); void AdjustThreadHeight( bool firstFrame, int oldOffset, int& offset );
float AdjustThreadPosition( float wy, int& offset );
int m_height; int m_height;
int m_offset;
protected: protected:
View& m_view; View& m_view;

View File

@ -333,6 +333,7 @@ void View::DrawTimeline()
const auto wpos = ImGui::GetCursorScreenPos(); const auto wpos = ImGui::GetCursorScreenPos();
const auto dpos = wpos + ImVec2( 0.5f, 0.5f ); const auto dpos = wpos + ImVec2( 0.5f, 0.5f );
// note that m_tc.GetHeight() returns the height from the previous draw
const auto h = std::max<float>( m_tc.GetHeight(), ImGui::GetContentRegionAvail().y - 4 ); // magic border value const auto h = std::max<float>( m_tc.GetHeight(), ImGui::GetContentRegionAvail().y - 4 ); // magic border value
ImGui::ItemSize( ImVec2( w, h ) ); ImGui::ItemSize( ImVec2( w, h ) );