fix virtual scrollable
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2025-05-14 19:11:25 -04:00
parent cb98eac750
commit c136762d16
2 changed files with 22 additions and 12 deletions

View File

@ -1774,6 +1774,7 @@ Chest furniture
Interaction editing debug menu Interaction editing debug menu
Fix chest physics&interaction data Fix chest physics&interaction data
Break out collidable template edit into dedicated component Break out collidable template edit into dedicated component
Fix virtual scrollable

View File

@ -16,13 +16,24 @@ import electrosphere.renderer.ui.events.ScrollEvent;
*/ */
public class VirtualScrollable extends StandardContainerElement implements DrawableElement, ScrollableElement { 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; double scroll = 0;
//the scrollable callback /**
* the scrollable callback
*/
ScrollEventCallback callback; ScrollEventCallback callback;
//should we draw this element /**
* should we draw this element
*/
boolean visible = true; boolean visible = true;
/** /**
@ -30,8 +41,8 @@ public class VirtualScrollable extends StandardContainerElement implements Drawa
*/ */
public VirtualScrollable(int width, int height){ public VirtualScrollable(int width, int height){
super(); super();
setWidth(width); this.setWidth(width);
setHeight(height); this.setHeight(height);
Yoga.YGNodeStyleSetOverflow(this.yogaNode, Yoga.YGOverflowScroll); Yoga.YGNodeStyleSetOverflow(this.yogaNode, Yoga.YGOverflowScroll);
} }
@ -46,13 +57,13 @@ public class VirtualScrollable extends StandardContainerElement implements Drawa
for(Element child : childList){ for(Element child : childList){
if(child instanceof DrawableElement){ if(child instanceof DrawableElement){
DrawableElement drawableChild = (DrawableElement) child; DrawableElement drawableChild = (DrawableElement) child;
if(childIsInBounds(drawableChild)){ if(this.childIsInBounds(drawableChild)){
drawableChild.draw( drawableChild.draw(
renderPipelineState, renderPipelineState,
openGLState, openGLState,
framebuffer, framebuffer,
framebufferPosX, framebufferPosX,
framebufferPosY framebufferPosY - (int)scroll
); );
} }
} }
@ -97,7 +108,7 @@ public class VirtualScrollable extends StandardContainerElement implements Drawa
* @param event The scroll event * @param event The scroll event
*/ */
private void defaultScrollHandling(ScrollEvent event){ private void defaultScrollHandling(ScrollEvent event){
scroll = scroll + event.getScrollAmount(); scroll = scroll + event.getScrollAmount() * DEFAULT_SCROLL_SCALE;
if(scroll > 0){ if(scroll > 0){
scroll = 0; scroll = 0;
} }
@ -111,9 +122,7 @@ public class VirtualScrollable extends StandardContainerElement implements Drawa
if(scroll < - maxScroll){ if(scroll < - maxScroll){
scroll = -maxScroll; scroll = -maxScroll;
} }
for(Element childElement : this.getChildren()){ // this.setPositionY((int)scroll);
childElement.setPositionX((int)(childElement.getAbsoluteX() + scroll));
}
} }
@Override @Override
@ -124,7 +133,7 @@ public class VirtualScrollable extends StandardContainerElement implements Drawa
if(callback != null){ if(callback != null){
propagate = callback.execute(scrollEvent); propagate = callback.execute(scrollEvent);
} else { } else {
defaultScrollHandling(scrollEvent); this.defaultScrollHandling(scrollEvent);
propagate = false; propagate = false;
} }
} }