fix virtual scrollable
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2025-05-14 21:46:08 -04:00
parent baea1e1906
commit ed82580d01
3 changed files with 33 additions and 8 deletions

View File

@ -1785,6 +1785,7 @@ Move around entity debug tab classes
Grid alignment data editing in debug menus Grid alignment data editing in debug menus
Grid alignment offsets work Grid alignment offsets work
Inventory state in non-creatures actually saves/loads to/from disk Inventory state in non-creatures actually saves/loads to/from disk
Fix virtual scrollable mouse alignment for events

View File

@ -36,6 +36,11 @@ public class VirtualScrollable extends StandardContainerElement implements Drawa
*/ */
boolean visible = true; boolean visible = true;
/**
* The child div
*/
Div childDiv;
/** /**
* Constructor * Constructor
*/ */
@ -44,6 +49,9 @@ public class VirtualScrollable extends StandardContainerElement implements Drawa
this.setWidth(width); this.setWidth(width);
this.setHeight(height); this.setHeight(height);
Yoga.YGNodeStyleSetOverflow(this.yogaNode, Yoga.YGOverflowScroll); Yoga.YGNodeStyleSetOverflow(this.yogaNode, Yoga.YGOverflowScroll);
this.childDiv = Div.createCol();
this.childDiv.setPositionType(YogaPositionType.Relative);
super.addChild(this.childDiv);
} }
@Override @Override
@ -54,7 +62,7 @@ public class VirtualScrollable extends StandardContainerElement implements Drawa
int framebufferPosX, int framebufferPosX,
int framebufferPosY int framebufferPosY
) { ) {
for(Element child : childList){ for(Element child : this.childDiv.getChildren()){
if(child instanceof DrawableElement){ if(child instanceof DrawableElement){
DrawableElement drawableChild = (DrawableElement) child; DrawableElement drawableChild = (DrawableElement) child;
if(this.childIsInBounds(drawableChild)){ if(this.childIsInBounds(drawableChild)){
@ -63,7 +71,7 @@ public class VirtualScrollable extends StandardContainerElement implements Drawa
openGLState, openGLState,
framebuffer, framebuffer,
framebufferPosX, framebufferPosX,
framebufferPosY - (int)scroll framebufferPosY
); );
} }
} }
@ -77,7 +85,7 @@ public class VirtualScrollable extends StandardContainerElement implements Drawa
*/ */
private boolean childIsInBounds(DrawableElement element){ private boolean childIsInBounds(DrawableElement element){
boolean rVal = true; boolean rVal = true;
if(element.getAbsoluteY() + scroll < this.getAbsoluteY() || element.getAbsoluteY() + scroll > this.getHeight() + this.getAbsoluteY()){ if(element.getAbsoluteY() < this.getAbsoluteY() || element.getAbsoluteY() > this.getHeight() + this.getAbsoluteY()){
return false; return false;
} }
return rVal; return rVal;
@ -114,17 +122,24 @@ public class VirtualScrollable extends StandardContainerElement implements Drawa
} }
//calculate max scroll //calculate max scroll
double maxScroll = 0; double maxScroll = 0;
for(Element child : this.getChildren()){ maxScroll = this.childDiv.getHeight() - this.getHeight();
if(child.getAbsoluteY() + child.getHeight() > maxScroll){
maxScroll = child.getAbsoluteY() + child.getHeight() - this.getHeight();
}
}
if(scroll < - maxScroll){ if(scroll < - maxScroll){
scroll = -maxScroll; scroll = -maxScroll;
} }
this.childDiv.setPositionY((int)scroll);
// this.setPositionY((int)scroll); // this.setPositionY((int)scroll);
} }
@Override
public void addChild(Element child) {
this.childDiv.addChild(child);
}
@Override
public void removeChild(Element child) {
this.childDiv.removeChild(child);
}
@Override @Override
public boolean handleEvent(Event event){ public boolean handleEvent(Event event){
boolean propagate = true; boolean propagate = true;

View File

@ -65,8 +65,17 @@ public interface ContainerElement extends Element {
* The position type of a yoga node * The position type of a yoga node
*/ */
public static enum YogaPositionType { public static enum YogaPositionType {
/**
* Relative to the nearest positioned ancestor
*/
Absolute, Absolute,
/**
* Relative to its normal position
*/
Relative, Relative,
/**
* Not affected by top/bottom/left/right properties
*/
Static, Static,
} }