From 30db87011e0c722bcc34b967311e7b8e77c80229 Mon Sep 17 00:00:00 2001 From: SyntaxGalaxy <96680248+SyntaxGalaxy@users.noreply.github.com> Date: Mon, 30 Dec 2024 20:24:19 +0530 Subject: [PATCH] fixes: some fixes in logic editor in dropping blocks functionality --- .../icst/logic/editor/view/LogicEditorView.java | 14 +++++++++++++- .../logic/lib/view/ActionBlockDropZoneView.java | 3 ++- .../lib/view/MainActionBlockDropZoneView.java | 3 ++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/logiceditor/src/main/java/com/icst/logic/editor/view/LogicEditorView.java b/logiceditor/src/main/java/com/icst/logic/editor/view/LogicEditorView.java index d44b14a3..6c2da0a0 100644 --- a/logiceditor/src/main/java/com/icst/logic/editor/view/LogicEditorView.java +++ b/logiceditor/src/main/java/com/icst/logic/editor/view/LogicEditorView.java @@ -236,10 +236,16 @@ public void dropBlock(float x, float y) { ActionBlockDropZoneView newZone = new ActionBlockDropZoneView( getContext(), new LogicEditorConfiguration(), this); + + LogicEditorCanvaView.LayoutParams lp = new LogicEditorCanvaView.LayoutParams( + LogicEditorCanvaView.LayoutParams.WRAP_CONTENT, + LogicEditorCanvaView.LayoutParams.WRAP_CONTENT); + newZone.addActionBlocksBeans(blocks, 0); newZone.setX(x); newZone.setY(y); getLogicEditorCanva().addView(newZone); + newZone.setLayoutParams(lp); blockDropZones.add(newZone); } else if (draggingBean instanceof ActionBlockBean block) { @@ -249,10 +255,16 @@ public void dropBlock(float x, float y) { ActionBlockDropZoneView newZone = new ActionBlockDropZoneView( getContext(), new LogicEditorConfiguration(), this); + + LogicEditorCanvaView.LayoutParams lp = new LogicEditorCanvaView.LayoutParams( + LogicEditorCanvaView.LayoutParams.WRAP_CONTENT, + LogicEditorCanvaView.LayoutParams.WRAP_CONTENT); + newZone.addActionBlocksBeans(blocks, 0); newZone.setX(x); newZone.setY(y); getLogicEditorCanva().addView(newZone); + newZone.setLayoutParams(lp); blockDropZones.add(newZone); } } @@ -280,7 +292,7 @@ public void removeOldReferences() { } else if (parent instanceof ActionBlockDropZoneView regularChain) { int index = regularChain.indexOfChild(actionBlockBeanView); regularChain.getChildAt(index).setOnTouchListener(null); - regularChain.removeViews(index, regularChain.getBlocksSize() - index); + regularChain.removeViews(index, regularChain.getChildCount() - index); regularChain.dereferenceActionBlocks(index); } } diff --git a/logiceditor/src/main/java/com/icst/logic/lib/view/ActionBlockDropZoneView.java b/logiceditor/src/main/java/com/icst/logic/lib/view/ActionBlockDropZoneView.java index 8be2d05f..56db39ff 100644 --- a/logiceditor/src/main/java/com/icst/logic/lib/view/ActionBlockDropZoneView.java +++ b/logiceditor/src/main/java/com/icst/logic/lib/view/ActionBlockDropZoneView.java @@ -77,7 +77,8 @@ public boolean isTerminated() { } public void dereferenceActionBlocks(int index) { - for (int i = index; i <= blockBeans.size(); ++i) { + int numberOfBlocks = blockBeans.size(); + for (int i = index; i < numberOfBlocks; ++i) { blockBeans.remove(index); } } diff --git a/logiceditor/src/main/java/com/icst/logic/lib/view/MainActionBlockDropZoneView.java b/logiceditor/src/main/java/com/icst/logic/lib/view/MainActionBlockDropZoneView.java index 61845520..f0a53e82 100644 --- a/logiceditor/src/main/java/com/icst/logic/lib/view/MainActionBlockDropZoneView.java +++ b/logiceditor/src/main/java/com/icst/logic/lib/view/MainActionBlockDropZoneView.java @@ -101,7 +101,8 @@ public boolean isTerminated() { } public void dereferenceActionBlocks(int index) { - for (int i = index; i <= blockBeans.size(); ++i) { + int numberOfBlocks = blockBeans.size(); + for (int i = index; i < numberOfBlocks; ++i) { blockBeans.remove(index); } }