use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.
the class GroupDragHandlerTest method updateUsingOverflowGroupEmptyGroupInMiddle.
@Test
public void updateUsingOverflowGroupEmptyGroupInMiddle() {
NlComponent menu = newMenu(366, 162, 392, 192);
menu.addChild(newOverflowItem(366, 162, 392, 96));
menu.addChild(newGroup(0, 0, -1, -1));
menu.addChild(newOverflowItem(366, 258, 392, 96));
GroupDragHandler handler = newGroupDragHandler(menu);
int y = 90;
y += 48;
handler.update(0, y, 0);
assertEquals(0, handler.getInsertIndex());
y += 48;
handler.update(0, y, 0);
assertEquals(0, handler.getInsertIndex());
y += 48;
handler.update(0, y, 0);
assertEquals(1, handler.getInsertIndex());
y += 48;
handler.update(0, y, 0);
assertEquals(2, handler.getInsertIndex());
y += 48;
handler.update(0, y, 0);
assertEquals(-1, handler.getInsertIndex());
y += 48;
handler.update(0, y, 0);
assertEquals(-1, handler.getInsertIndex());
}
use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.
the class GroupDragHandlerTest method updateUsingOverflowGroupEmptyGroupInFront.
@Test
public void updateUsingOverflowGroupEmptyGroupInFront() {
NlComponent menu = newMenu(366, 162, 392, 192);
menu.addChild(newGroup(0, 0, -1, -1));
menu.addChild(newOverflowItem(366, 162, 392, 96));
menu.addChild(newOverflowItem(366, 258, 392, 96));
GroupDragHandler handler = newGroupDragHandler(menu);
int y = 90;
y += 48;
handler.update(0, y, 0);
assertEquals(0, handler.getInsertIndex());
y += 48;
handler.update(0, y, 0);
assertEquals(1, handler.getInsertIndex());
y += 48;
handler.update(0, y, 0);
assertEquals(2, handler.getInsertIndex());
y += 48;
handler.update(0, y, 0);
assertEquals(2, handler.getInsertIndex());
y += 48;
handler.update(0, y, 0);
assertEquals(-1, handler.getInsertIndex());
y += 48;
handler.update(0, y, 0);
assertEquals(-1, handler.getInsertIndex());
}
use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.
the class NlComponentTreeTest method testSelectionInTreeIsPropagatedToModel.
public void testSelectionInTreeIsPropagatedToModel() {
assertNull(myTree.getSelectionPaths());
assertFalse(myModel.getSelectionModel().getSelection().iterator().hasNext());
NlComponent root = (NlComponent) myTree.getModel().getRoot();
NlComponent node1 = root.getChild(1);
NlComponent node2 = root.getChild(2);
myTree.addSelectionPath(new TreePath(new Object[] { root, node1 }));
myTree.addSelectionPath(new TreePath(new Object[] { root, node2 }));
Iterator<NlComponent> selected = myModel.getSelectionModel().getSelection().iterator();
assertEquals(node1, selected.next());
assertEquals(node2, selected.next());
assertFalse(selected.hasNext());
}
use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.
the class ConstraintPainter method paintConstraint.
/**
* Paints a given match as a constraint.
*
* @param graphics the graphics context
* @param state the handler state
* @param match the match
*/
static void paintConstraint(NlGraphics graphics, GuidelineHandler state, Match match) {
NlComponent node = match.edge.component;
if (node == null) {
return;
}
Insets padding = node.getPadding();
Rectangle targetBounds = node == state.layout ? new Rectangle(node.x + padding.left, node.y + padding.top, Math.max(0, node.w - padding.left - padding.right), Math.max(0, node.h - padding.top - padding.bottom)) : new Rectangle(node.x, node.y, node.w, node.h);
ConstraintType type = match.type;
assert type != null;
Rectangle sourceBounds = state.myBounds;
paintConstraint(graphics, type, node, sourceBounds, node, targetBounds, null, /* allConstraints */
true, /* highlightTargetEdge */
state.myTextDirection);
}
use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.
the class ConstraintPainter method paintSelectionFeedback.
/**
* Paint selection feedback by painting constraints for the selected nodes
* @param graphics the graphics context
* @param parentNode the parent relative layout
* @param childNodes the nodes whose constraints should be painted
* @param showDependents whether incoming constraints should be shown as well
*/
public static void paintSelectionFeedback(NlGraphics graphics, NlComponent parentNode, List<NlComponent> childNodes, boolean showDependents, TextDirection textDirection) {
DependencyGraph dependencyGraph = DependencyGraph.get(parentNode);
Set<NlComponent> horizontalDeps = dependencyGraph.dependsOn(childNodes, false);
Set<NlComponent> verticalDeps = dependencyGraph.dependsOn(childNodes, true);
Set<NlComponent> deps = new HashSet<NlComponent>(horizontalDeps.size() + verticalDeps.size());
deps.addAll(horizontalDeps);
deps.addAll(verticalDeps);
if (deps.size() > 0) {
for (NlComponent node : deps) {
// Don't highlight the selected nodes themselves
if (childNodes.contains(node)) {
continue;
}
Rectangle bounds = getBounds(node);
graphics.useStyle(DEPENDENCY);
graphics.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
}
}
for (NlComponent childNode : childNodes) {
DependencyGraph.ViewData view = dependencyGraph.getView(childNode);
if (view == null) {
continue;
}
// Paint all incoming constraints
if (showDependents) {
paintConstraints(graphics, view.dependedOnBy, textDirection);
}
// Paint all outgoing constraints
paintConstraints(graphics, view.dependsOn, textDirection);
}
}
Aggregations