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

View File

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