From c136762d1609d8deda452a2f3281854af80ae270 Mon Sep 17 00:00:00 2001 From: austin Date: Wed, 14 May 2025 19:11:25 -0400 Subject: [PATCH] fix virtual scrollable --- docs/src/progress/renderertodo.md | 1 + .../ui/elements/VirtualScrollable.java | 33 ++++++++++++------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index f32c7d97..35c637fb 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1774,6 +1774,7 @@ Chest furniture Interaction editing debug menu Fix chest physics&interaction data Break out collidable template edit into dedicated component +Fix virtual scrollable diff --git a/src/main/java/electrosphere/renderer/ui/elements/VirtualScrollable.java b/src/main/java/electrosphere/renderer/ui/elements/VirtualScrollable.java index e7b2dc9d..6f3973b1 100644 --- a/src/main/java/electrosphere/renderer/ui/elements/VirtualScrollable.java +++ b/src/main/java/electrosphere/renderer/ui/elements/VirtualScrollable.java @@ -16,13 +16,24 @@ import electrosphere.renderer.ui.events.ScrollEvent; */ public class VirtualScrollable extends StandardContainerElement implements DrawableElement, ScrollableElement { - //the current amount of scroll applied to this element + /** + * Default scaling applied to scrolling + */ + static final float DEFAULT_SCROLL_SCALE = 5.0f; + + /** + * the current amount of scroll applied to this element + */ double scroll = 0; - //the scrollable callback + /** + * the scrollable callback + */ ScrollEventCallback callback; - //should we draw this element + /** + * should we draw this element + */ boolean visible = true; /** @@ -30,8 +41,8 @@ public class VirtualScrollable extends StandardContainerElement implements Drawa */ public VirtualScrollable(int width, int height){ super(); - setWidth(width); - setHeight(height); + this.setWidth(width); + this.setHeight(height); Yoga.YGNodeStyleSetOverflow(this.yogaNode, Yoga.YGOverflowScroll); } @@ -46,13 +57,13 @@ public class VirtualScrollable extends StandardContainerElement implements Drawa for(Element child : childList){ if(child instanceof DrawableElement){ DrawableElement drawableChild = (DrawableElement) child; - if(childIsInBounds(drawableChild)){ + if(this.childIsInBounds(drawableChild)){ drawableChild.draw( renderPipelineState, openGLState, framebuffer, framebufferPosX, - framebufferPosY + framebufferPosY - (int)scroll ); } } @@ -97,7 +108,7 @@ public class VirtualScrollable extends StandardContainerElement implements Drawa * @param event The scroll event */ private void defaultScrollHandling(ScrollEvent event){ - scroll = scroll + event.getScrollAmount(); + scroll = scroll + event.getScrollAmount() * DEFAULT_SCROLL_SCALE; if(scroll > 0){ scroll = 0; } @@ -111,9 +122,7 @@ public class VirtualScrollable extends StandardContainerElement implements Drawa if(scroll < - maxScroll){ scroll = -maxScroll; } - for(Element childElement : this.getChildren()){ - childElement.setPositionX((int)(childElement.getAbsoluteX() + scroll)); - } + // this.setPositionY((int)scroll); } @Override @@ -124,7 +133,7 @@ public class VirtualScrollable extends StandardContainerElement implements Drawa if(callback != null){ propagate = callback.execute(scrollEvent); } else { - defaultScrollHandling(scrollEvent); + this.defaultScrollHandling(scrollEvent); propagate = false; } }