Skip to content

Commit

Permalink
wip: modify highlight nearest target methods for action block layer
Browse files Browse the repository at this point in the history
  • Loading branch information
SyntaxGalaxy committed Jan 11, 2025
1 parent 24aede4 commit 71d5592
Showing 1 changed file with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,29 +127,60 @@ protected void addBlockBeans(ArrayList<ActionBlockBean> actionBlocks, int index)
// Configured for ActionBlockLayerView
@Override
public void highlightNearestTarget(ArrayList<ActionBlockBean> blocks, float x, float y) {
if (canDrop(blocks, x, y)) {
int index = 0;
for (int i = 0; i < blockLayout.getChildCount(); i++) {
View child = blockLayout.getChildAt(i);
if (CanvaMathUtils.isCoordinatesInsideTargetView(
child, getLogicEditor().getEditorSectionView(), x, y)) {
index = i;
break;
}
}
if (blockLayout.getChildAt(index) instanceof ActionBlockBeanView blockBeanView) {
if (blockBeanView.canDrop(blocks, x, y)) {
blockBeanView.highlightNearestTarget(blocks, x, y);
return;
}
}

index = getIndex(x, y);
if (canDrop(blocks, index)) {
getLogicEditor().removeDummyHighlighter();
LayoutParams highlighterLp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
highlighterLp.setMargins(0, BlockMarginConstants.CHAINED_ACTION_BLOCK_TOP_MARGIN, 0, 0);
NearestTargetHighlighterView highlighter = new NearestTargetHighlighterView(getContext(), blocks.get(0));
getLogicEditor().setDummyHighlighter(highlighter);
int index = getIndex(x, y);
blockLayout.addView(highlighter, index);

highlighter.setLayoutParams(highlighterLp);
}
}

// Configured for ActionBlockLayerView
@Override
public void highlightNearestTarget(ActionBlockBean block, float x, float y) {
int index = 0;
for (int i = 0; i < blockLayout.getChildCount(); i++) {
View child = blockLayout.getChildAt(i);
if (CanvaMathUtils.isCoordinatesInsideTargetView(
child, getLogicEditor().getEditorSectionView(), x, y)) {
index = i;
break;
}
}
if (blockLayout.getChildAt(index) instanceof ActionBlockBeanView blockBeanView) {
if (blockBeanView.canDrop(block, x, y)) {
blockBeanView.highlightNearestTarget(block, x, y);
return;
}
}

index = getIndex(x, y);
if (canDrop(block, x, y)) {
getLogicEditor().removeDummyHighlighter();
LayoutParams highlighterLp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
highlighterLp.setMargins(0, BlockMarginConstants.CHAINED_ACTION_BLOCK_TOP_MARGIN, 0, 0);
NearestTargetHighlighterView highlighter = new NearestTargetHighlighterView(getContext(), block);
getLogicEditor().setDummyHighlighter(highlighter);
int index = getIndex(x, y);
blockLayout.addView(highlighter, index);
highlighter.setLayoutParams(highlighterLp);
}
Expand Down

0 comments on commit 71d5592

Please sign in to comment.