Skip to content

Commit 061b864

Browse files
authored
improve scroll update in scene tree panel (#5193)
* improve scroll upadte in scene tree panel * CR Fixes
1 parent fc392a8 commit 061b864

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

source/MRViewer/MRSceneObjectsListDrawer.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -595,9 +595,9 @@ void SceneObjectsListDrawer::updateSceneWindowScrollIfNeeded_()
595595
scrollInfo.relativeMousePos = ImGui::GetMousePos().y - window->Pos.y;
596596
scrollInfo.absLinePosRatio = window->ContentSize.y == 0.0f ? 0.0f : ( scrollInfo.relativeMousePos + window->Scroll.y ) / window->ContentSize.y;
597597

598-
if ( nextFrameFixScroll_ )
598+
if ( dragModeTrigger_ )
599599
{
600-
nextFrameFixScroll_ = false;
600+
dragModeTrigger_ = false;
601601
window->Scroll.y = std::clamp( prevScrollInfo_.absLinePosRatio * window->ContentSize.y - prevScrollInfo_.relativeMousePos, 0.0f, window->ScrollMax.y );
602602
}
603603
else if ( dragObjectsMode_ )
@@ -616,23 +616,39 @@ void SceneObjectsListDrawer::updateSceneWindowScrollIfNeeded_()
616616
getViewerInstance().incrementForceRedrawFrames();
617617
}
618618
}
619+
else if ( nextFrameFixScroll_ )
620+
{
621+
nextFrameFixScroll_ = false;
622+
float absPos = prevScrollInfo_.absLinePosRatio * window->ContentSize.y - window->Scroll.y;
623+
float addScroll = 0.0f;
624+
if ( absPos < 15 * UI::scale() )
625+
addScroll = absPos - 15 * UI::scale();
626+
else if ( absPos > window->Size.y - 15 * UI::scale() )
627+
addScroll = absPos - ( window->Size.y - 15 * UI::scale() );
628+
auto newScroll = std::clamp( window->Scroll.y + addScroll, 0.0f, window->ScrollMax.y );
629+
if ( newScroll != window->Scroll.y )
630+
{
631+
window->Scroll.y = newScroll;
632+
getViewerInstance().incrementForceRedrawFrames();
633+
}
634+
}
619635

620636
const ImGuiPayload* payloadCheck = ImGui::GetDragDropPayload();
621637
bool dragModeNow = payloadCheck && std::string_view( payloadCheck->DataType ) == "_TREENODE";
622638
if ( dragModeNow && !dragObjectsMode_ )
623639
{
624640
dragObjectsMode_ = true;
625-
nextFrameFixScroll_ = true;
641+
dragModeTrigger_ = true;
626642
getViewerInstance().incrementForceRedrawFrames( 2, true );
627643
}
628644
else if ( !dragModeNow && dragObjectsMode_ )
629645
{
630646
dragObjectsMode_ = false;
631-
nextFrameFixScroll_ = true;
647+
dragModeTrigger_ = true;
632648
getViewerInstance().incrementForceRedrawFrames( 2, true );
633649
}
634650

635-
if ( !nextFrameFixScroll_ )
651+
if ( !dragModeTrigger_ )
636652
prevScrollInfo_ = scrollInfo;
637653
}
638654

source/MRViewer/MRSceneObjectsListDrawer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ class MRVIEWER_CLASS SceneObjectsListDrawer
144144
bool nextFrameFixScroll_{ false };
145145
// flag to know if we are dragging objects now or not
146146
bool dragObjectsMode_{ false };
147+
// dragging either just started, or just stopped
148+
bool dragModeTrigger_{ false };
147149

148150
protected:
149151
std::unordered_map<const Object*, bool> sceneOpenCommands_;

0 commit comments

Comments
 (0)