use of com.android.tools.idea.uibuilder.graphics.NlGraphics in project android by JetBrains.
the class AbsoluteLayoutHandler method createDragHandler.
@Override
@Nullable
public DragHandler createDragHandler(@NotNull ViewEditor editor, @NotNull NlComponent layout, @NotNull List<NlComponent> components, @NotNull DragType type) {
return new DragHandler(editor, this, layout, components, type) {
@Override
public void paint(@NotNull NlGraphics graphics) {
int deltaX = lastX - startX;
int deltaY = lastY - startY;
for (NlComponent component : components) {
int x = component.x + deltaX;
int y = component.y + deltaY;
int w = component.w;
int h = component.h;
graphics.useStyle(NlDrawingStyle.DROP_PREVIEW);
graphics.drawRect(x, y, w, h);
}
}
@Override
public void commit(@AndroidCoordinate int x, @AndroidCoordinate int y, int modifiers, @NotNull InsertType insertType) {
// TODO: Remove all existing layout parameters; if you're dragging from one layout type to another, you don't
// want stale layout parameters (e.g. layout_alignLeft from a previous RelativeLayout in a new GridLayout, and so on.)
int deltaX = x - startX;
int deltaY = y - startY;
for (NlComponent component : components) {
component.setAttribute(ANDROID_URI, ATTR_LAYOUT_X, editor.pxToDpWithUnits(component.x - layout.x + deltaX));
component.setAttribute(ANDROID_URI, ATTR_LAYOUT_Y, editor.pxToDpWithUnits(component.y - layout.y + deltaY));
}
insertComponents(-1, insertType);
}
};
}
use of com.android.tools.idea.uibuilder.graphics.NlGraphics in project android by JetBrains.
the class PreferenceScreenDragHandlerTest method drawDropPreviewLine.
@Test
public void drawDropPreviewLine() {
PreferenceGroupDragHandler handler = newPreferenceScreenDragHandler(newPreferenceScreen());
NlGraphics graphics = Mockito.mock(NlGraphics.class);
handler.update(360, 690, 0);
handler.drawDropPreviewLine(graphics);
handler.update(360, 740, 0);
handler.drawDropPreviewLine(graphics);
Mockito.verify(graphics).drawBottom(new Rectangle(0, 607, 768, 104));
Mockito.verify(graphics).drawTop(new Rectangle(0, 711, 768, 104));
}
use of com.android.tools.idea.uibuilder.graphics.NlGraphics in project android by JetBrains.
the class RelativeLayoutHandler method createDragHandler.
@Override
@Nullable
public DragHandler createDragHandler(@NotNull ViewEditor editor, @NotNull NlComponent layout, @NotNull List<NlComponent> components, @NotNull DragType type) {
final RelativeDragHandler moveHandler = new RelativeDragHandler(editor, layout, components);
return new DragHandler(editor, this, layout, components, type) {
@Nullable
@Override
public String update(@AndroidCoordinate int x, @AndroidCoordinate int y, int modifiers) {
super.update(x, y, modifiers);
NlComponent primary = components.get(0);
int deltaX = lastX - startX;
int deltaY = lastY - startY;
moveHandler.updateMove(primary, deltaX, deltaY, modifiers);
return null;
}
@Override
public void paint(@NotNull NlGraphics graphics) {
GuidelinePainter.paint(graphics, moveHandler);
}
@Override
public void commit(@AndroidCoordinate int x, @AndroidCoordinate int y, int modifiers, @NotNull InsertType insertType) {
moveHandler.removeCycles();
NlComponent previous = null;
for (NlComponent component : components) {
if (previous == null) {
moveHandler.applyConstraints(component);
} else {
// Arrange the nodes next to each other, depending on which
// edge we are attaching to. For example, if attaching to the
// top edge, arrange the subsequent nodes in a column below it.
//
// TODO: Try to do something smarter here where we detect
// constraints between the dragged edges, and we preserve these.
// We have to do this carefully though because if the
// constraints go through some other nodes not part of the
// selection, this doesn't work right, and you might be
// dragging several connected components, which we'd then
// need to stitch together such that they are all visible.
moveHandler.attachPrevious(previous, component);
}
previous = component;
}
insertAddedComponents(insertType);
}
private void insertAddedComponents(@NotNull InsertType insertType) {
List<NlComponent> added = components.stream().filter(component -> component.getParent() != layout).collect(Collectors.toList());
editor.getModel().addComponents(added, layout, null, insertType);
}
};
}
use of com.android.tools.idea.uibuilder.graphics.NlGraphics in project android by JetBrains.
the class RelativeLayoutHandler method paintConstraints.
@Override
public boolean paintConstraints(@NotNull ScreenView screenView, @NotNull Graphics2D graphics, @NotNull NlComponent component) {
NlGraphics g = new NlGraphics(graphics, screenView);
Iterable<NlComponent> iterable = component.getChildren();
List<NlComponent> children = Lists.newArrayList(iterable);
ConstraintPainter.paintSelectionFeedback(g, component, children, true, TextDirection.LEFT_TO_RIGHT);
return false;
}
use of com.android.tools.idea.uibuilder.graphics.NlGraphics in project android by JetBrains.
the class RelativeLayoutHandler method createResizeHandler.
@Override
@Nullable
public ResizeHandler createResizeHandler(@NotNull ViewEditor editor, @NotNull NlComponent component, @Nullable SegmentType horizontalEdgeType, @Nullable SegmentType verticalEdgeType) {
NlComponent parent = component.getParent();
if (parent == null) {
return null;
}
final RelativeResizeHandler resizeHandler = new RelativeResizeHandler(editor, parent, component, horizontalEdgeType, verticalEdgeType);
return new ResizeHandler(editor, this, component, horizontalEdgeType, verticalEdgeType) {
@Nullable
@Override
public String update(@AndroidCoordinate int x, @AndroidCoordinate int y, int modifiers, @NotNull @AndroidCoordinate Rectangle newBounds) {
super.update(x, y, modifiers, newBounds);
resizeHandler.updateResize(component, newBounds, modifiers);
return null;
}
@Override
public void commit(@AndroidCoordinate int px, @AndroidCoordinate int py, int modifiers, @NotNull @AndroidCoordinate Rectangle newBounds) {
resizeHandler.removeCycles();
resizeHandler.applyConstraints(component);
}
@Override
public void paint(@NotNull NlGraphics graphics) {
GuidelinePainter.paint(graphics, resizeHandler);
}
};
}
Aggregations