Skip to content

Commit

Permalink
fix(frontend): support addChildBefore method
Browse files Browse the repository at this point in the history
  • Loading branch information
TimeBather committed Nov 13, 2024
1 parent eb77548 commit 552086c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ public DomNode(T context) {
this.domContext = context;
}

public boolean addChildBefore(DomNode<T> child, DomNode<T> before){
int index = children.indexOf(before);
if(index == -1)
return false;
return addChildAt(index,child);
}

public boolean addChildAt(int i, DomNode<T> child){
if(child.parent != null)
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,34 @@ public LayoutContext<?,GuiDomNode> getLayoutManager() {

protected BackgroundRenderer background = new BackgroundRenderer();

@HostAccess.Export
@Override
public boolean addChildBefore(DomNode<GuiContext> child, DomNode<GuiContext> before) {
this.domContext.queueDuringRender(()->{
int index = children.indexOf(before);
if(index == -1)
return;
addChildInstant(index, child);
});
return true;
}

@HostAccess.Export
@Override
public boolean addChildAt(int i, DomNode<GuiContext> child) {
this.domContext.queueDuringRender(()->{
if(child instanceof GuiDomNode domNode)
getLayoutManager().addChild(i,domNode.getLayoutManager());
styles.notifyUpdate();
super.addChildAt(i,child);
addChildInstant(i, child);
});
return true;
}

protected void addChildInstant(int i, DomNode<GuiContext> child){
if(child instanceof GuiDomNode domNode)
getLayoutManager().addChild(i,domNode.getLayoutManager());
styles.notifyUpdate();
super.addChildAt(i,child);
}

@HostAccess.Export
@Override
public boolean removeChild(DomNode<GuiContext> child) {
Expand Down

0 comments on commit 552086c

Please sign in to comment.