mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
Improve horizontal zoom accuracy
This commit is contained in:
@@ -250,18 +250,26 @@ public class MatchScreen extends FScreen {
|
|||||||
|
|
||||||
//adjust scroll top to keep y position the same
|
//adjust scroll top to keep y position the same
|
||||||
float newScrollHeight = getScrollHeight() - staticHeight;
|
float newScrollHeight = getScrollHeight() - staticHeight;
|
||||||
float yAfter = y * newScrollHeight / oldScrollHeight;
|
float ratio = newScrollHeight / oldScrollHeight;
|
||||||
|
float yAfter = y * ratio;
|
||||||
setScrollTop(oldScrollTop + yAfter - y);
|
setScrollTop(oldScrollTop + yAfter - y);
|
||||||
|
|
||||||
|
//make scroll panes wide enough to support scrolling cards into view
|
||||||
|
zoom = newScrollHeight / (getHeight() - staticHeight);
|
||||||
|
for (FScrollPane scrollPane : horzScrollPanes.keySet()) {
|
||||||
|
float minScrollWidth = scrollPane.getWidth() * zoom;
|
||||||
|
if (scrollPane.getScrollWidth() < minScrollWidth) {
|
||||||
|
scrollPane.setScrollWidth(minScrollWidth);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//adjust scroll left of all horizontal scroll panes to keep x position the same
|
//adjust scroll left of all horizontal scroll panes to keep x position the same
|
||||||
float startX = x;
|
float startX = x;
|
||||||
for (Entry<FScrollPane, Pair<Float, Float>> entry : horzScrollPanes.entrySet()) {
|
for (Entry<FScrollPane, Pair<Float, Float>> entry : horzScrollPanes.entrySet()) {
|
||||||
FScrollPane horzScrollPane = entry.getKey();
|
FScrollPane horzScrollPane = entry.getKey();
|
||||||
float oldScrollLeft = entry.getValue().getLeft();
|
float oldScrollLeft = entry.getValue().getLeft();
|
||||||
x = startX + oldScrollLeft;
|
x = startX + oldScrollLeft;
|
||||||
float oldScrollWidth = entry.getValue().getRight();
|
float xAfter = x * ratio;
|
||||||
float newScrollWidth = horzScrollPane.getScrollWidth();
|
|
||||||
float xAfter = x * newScrollWidth / oldScrollWidth;
|
|
||||||
horzScrollPane.setScrollLeft(oldScrollLeft + xAfter - x);
|
horzScrollPane.setScrollLeft(oldScrollLeft + xAfter - x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,10 +40,18 @@ public abstract class FScrollPane extends FContainer {
|
|||||||
return scrollBounds.width;
|
return scrollBounds.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setScrollWidth(float scrollWidth0) {
|
||||||
|
scrollBounds.width = scrollWidth0;
|
||||||
|
}
|
||||||
|
|
||||||
public float getScrollHeight() {
|
public float getScrollHeight() {
|
||||||
return scrollBounds.height;
|
return scrollBounds.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setScrollHeight(float scrollHeight0) {
|
||||||
|
scrollBounds.height = scrollHeight0;
|
||||||
|
}
|
||||||
|
|
||||||
public float getMaxScrollLeft() {
|
public float getMaxScrollLeft() {
|
||||||
return getScrollWidth() - getWidth();
|
return getScrollWidth() - getWidth();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user