aboutsummaryrefslogtreecommitdiff
path: root/src/components/Scrollbar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/Scrollbar.cpp')
-rw-r--r--src/components/Scrollbar.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/components/Scrollbar.cpp b/src/components/Scrollbar.cpp
index 76c5c1a..ac713e9 100644
--- a/src/components/Scrollbar.cpp
+++ b/src/components/Scrollbar.cpp
@@ -109,4 +109,40 @@ void Scrollbar::Refresh() {
elements.push_back(bar);
}
+void Scrollbar::Focus(double XorY){
+ double MTCanvasHeight = status->CanvasHeight - status->ScrollbarWidth;
+ double MTCanvasWidth = status->CanvasWidth - status->ScrollbarWidth;
+ // Check horizontal or vertical and if should scroll
+ if(IsHorizontal && status->MoveTableMaxX > MTCanvasWidth){
+ // First normalize:
+ XorY-=MTCanvasWidth; // Do not scroll on first page
+ XorY=std::max(0.0,XorY); // Ensure focus is greater than 0
+ XorY=std::min(XorY,(status->MoveTableMaxX-MTCanvasWidth)); // Ensure focus is than scroll max
+ // Then compute percent and apply scroll
+ double percent = XorY / (status->MoveTableMaxX-MTCanvasWidth);
+ status->ScrollX =
+ -(status->MoveTableMaxX - MTCanvasWidth) * percent;
+ // Do not forget to update scrollbar:
+ double maxScroll = bg.width - bar.width;
+ bar.x = maxScroll * percent;
+ bar.x = std::max(bg.x, bar.x);
+ bar.x = std::min(bg.x + maxScroll, bar.x);
+ }
+ else if(status->MoveTableMaxY > MTCanvasHeight){
+ // First normalize:
+ XorY-=MTCanvasHeight; // Do not scroll on first page
+ XorY=std::max(0.0,XorY); // Ensure focus is greater than 0
+ XorY=std::min(XorY,(status->MoveTableMaxY-MTCanvasHeight)); // Ensure focus is than scroll max
+ // Then compute percent and apply scroll
+ double percent = XorY / (status->MoveTableMaxY-MTCanvasHeight);
+ status->ScrollY =
+ -(status->MoveTableMaxY - MTCanvasHeight) * percent;
+ // Do not forget to update scrollbar:
+ double maxScroll = bg.height - bar.height;
+ bar.y = maxScroll * percent;
+ bar.y = std::max(bg.y, bar.y);
+ bar.y = std::min(bg.y + maxScroll, bar.y);
+ }
+}
+
} // namespace cgeditor \ No newline at end of file