use of com.android.tools.idea.uibuilder.scene.SceneComponent in project android by JetBrains.
the class LassoTarget method fillSelectedComponents.
/**
* Fills the given array with selected components, if any
*
* @param components
*/
public void fillSelectedComponents(ArrayList<SceneComponent> components) {
components.clear();
int count = myComponent.getChildCount();
float x1 = Math.min(myOriginX, myLastX);
float x2 = Math.max(myOriginX, myLastX);
float y1 = Math.min(myOriginY, myLastY);
float y2 = Math.max(myOriginY, myLastY);
if ((int) (x2 - x1) == 0 && (int) (y2 - y1) == 0) {
return;
}
Rectangle bounds = new Rectangle((int) x1, (int) y1, (int) (x2 - x1), (int) (y2 - y1));
for (int i = 0; i < count; i++) {
SceneComponent component = myComponent.getChild(i);
if (component.intersects(bounds)) {
components.add(component);
}
}
}
use of com.android.tools.idea.uibuilder.scene.SceneComponent in project android by JetBrains.
the class DragTarget method updateAttributes.
protected void updateAttributes(AttributesTransaction attributes, int x, int y) {
SceneComponent targetLeftComponent = getTargetComponent(SdkConstants.SHERPA_URI, ourLeftAttributes);
SceneComponent targetRightComponent = getTargetComponent(SdkConstants.SHERPA_URI, ourRightAttributes);
checkIsInChain();
if (targetLeftComponent != null && targetRightComponent != null) {
if (!myIsInHorizontalChain) {
int dx1 = getLeftTargetOrigin(targetLeftComponent) + getMarginValue(SdkConstants.ATTR_LAYOUT_MARGIN_LEFT);
int dx2 = getRightTargetOrigin(targetRightComponent) - getMarginValue(SdkConstants.ATTR_LAYOUT_MARGIN_RIGHT);
float dw = dx2 - dx1 - myComponent.getDrawWidth();
float bias = (x - dx1) / dw;
if (bias < 0) {
bias = 0;
}
if (bias > 1) {
bias = 1;
}
String biasValue = null;
if ((int) (bias * 1000) != 500) {
bias = (int) (bias * 1000) / 1000f;
biasValue = String.valueOf(bias);
if (biasValue.equalsIgnoreCase("NaN")) {
biasValue = null;
}
}
attributes.setAttribute(SdkConstants.SHERPA_URI, SdkConstants.ATTR_LAYOUT_HORIZONTAL_BIAS, biasValue);
}
} else if (targetLeftComponent != null) {
int dx = x - getLeftTargetOrigin(targetLeftComponent);
applyMargin(attributes, SdkConstants.ATTR_LAYOUT_MARGIN_LEFT, dx);
/*
// TODO: handles RTL correctly
if (myComponent.getNlComponent().getLiveAttribute(SdkConstants.ANDROID_URI, SdkConstants.ATTR_LAYOUT_MARGIN_START) == null) {
// if start isn't defined, create it based on the margin left
attributes.setAttribute(SdkConstants.ANDROID_URI, SdkConstants.ATTR_LAYOUT_MARGIN_START,
myComponent.getNlComponent().getLiveAttribute(SdkConstants.ANDROID_URI, SdkConstants.ATTR_LAYOUT_MARGIN_LEFT));
} else {
applyMargin(attributes, SdkConstants.ATTR_LAYOUT_MARGIN_START, dx);
}
*/
} else if (targetRightComponent != null) {
int dx = getRightTargetOrigin(targetRightComponent) - (x + myComponent.getDrawWidth());
applyMargin(attributes, SdkConstants.ATTR_LAYOUT_MARGIN_RIGHT, dx);
/*
// TODO: handles RTL correctly
if (myComponent.getNlComponent().getLiveAttribute(SdkConstants.ANDROID_URI, SdkConstants.ATTR_LAYOUT_MARGIN_END) == null) {
// if end isn't defined, create it based on the margin right
attributes.setAttribute(SdkConstants.ANDROID_URI, SdkConstants.ATTR_LAYOUT_MARGIN_END,
myComponent.getNlComponent().getLiveAttribute(SdkConstants.ANDROID_URI, SdkConstants.ATTR_LAYOUT_MARGIN_RIGHT));
} else {
applyMargin(attributes, SdkConstants.ATTR_LAYOUT_MARGIN_END, dx);
}
*/
} else {
int dx = x - myComponent.getParent().getDrawX();
String positionX = String.format(SdkConstants.VALUE_N_DP, dx);
attributes.setAttribute(SdkConstants.TOOLS_URI, SdkConstants.ATTR_LAYOUT_EDITOR_ABSOLUTE_X, positionX);
}
SceneComponent targetTopComponent = getTargetComponent(SdkConstants.SHERPA_URI, ourTopAttributes);
SceneComponent targetBottomComponent = getTargetComponent(SdkConstants.SHERPA_URI, ourBottomAttributes);
if (targetTopComponent != null && targetBottomComponent != null) {
if (!myIsInVerticalChain) {
int dy1 = getTopTargetOrigin(targetTopComponent) + getMarginValue(SdkConstants.ATTR_LAYOUT_MARGIN_TOP);
int dy2 = getBottomTargetOrigin(targetBottomComponent) - getMarginValue(SdkConstants.ATTR_LAYOUT_MARGIN_BOTTOM);
float dh = dy2 - dy1 - myComponent.getDrawHeight();
float bias = (y - dy1) / dh;
if (bias < 0) {
bias = 0;
}
if (bias > 1) {
bias = 1;
}
String biasValue = null;
if ((int) (bias * 1000) != 500) {
bias = (int) (bias * 1000) / 1000f;
biasValue = String.valueOf(bias);
if (biasValue.equalsIgnoreCase("NaN")) {
biasValue = null;
}
}
attributes.setAttribute(SdkConstants.SHERPA_URI, SdkConstants.ATTR_LAYOUT_VERTICAL_BIAS, biasValue);
}
} else if (targetTopComponent != null) {
int dy = y - getTopTargetOrigin(targetTopComponent);
applyMargin(attributes, SdkConstants.ATTR_LAYOUT_MARGIN_TOP, dy);
} else if (targetBottomComponent != null) {
int dy = getBottomTargetOrigin(targetBottomComponent) - (y + myComponent.getDrawHeight());
applyMargin(attributes, SdkConstants.ATTR_LAYOUT_MARGIN_BOTTOM, dy);
} else {
int dy = y - myComponent.getParent().getDrawY();
String positionY = String.format(SdkConstants.VALUE_N_DP, dy);
attributes.setAttribute(SdkConstants.TOOLS_URI, SdkConstants.ATTR_LAYOUT_EDITOR_ABSOLUTE_Y, positionY);
}
}
use of com.android.tools.idea.uibuilder.scene.SceneComponent in project android by JetBrains.
the class DragTarget method gatherNotches.
protected void gatherNotches() {
myCurrentNotchX = null;
myCurrentNotchY = null;
myHorizontalNotches.clear();
myVerticalNotches.clear();
SceneComponent parent = myComponent.getParent();
Notch.Provider notchProvider = parent.getNotchProvider();
if (notchProvider != null) {
notchProvider.fill(parent, myComponent, myHorizontalNotches, myVerticalNotches);
}
int count = parent.getChildCount();
for (int i = 0; i < count; i++) {
SceneComponent child = parent.getChild(i);
if (child == myComponent) {
continue;
}
Notch.Provider provider = child.getNotchProvider();
if (provider != null) {
provider.fill(child, myComponent, myHorizontalNotches, myVerticalNotches);
}
}
}
use of com.android.tools.idea.uibuilder.scene.SceneComponent in project android by JetBrains.
the class ConstraintTarget method findChainHead.
private SceneComponent findChainHead(SceneComponent component, ArrayList<String> sideA, ArrayList<String> sideB) {
while (true) {
NlComponent nlComponent = component.getNlComponent();
String attributeA = getConnectionId(nlComponent, SdkConstants.SHERPA_URI, sideA);
if (attributeA == null) {
return component;
}
SceneComponent target = myComponent.getScene().getSceneComponent(attributeA);
if (target == null) {
return component;
}
String attributeB = getConnectionId(target.getNlComponent(), SdkConstants.SHERPA_URI, sideB);
if (attributeB == null) {
return component;
}
if (attributeB.equalsIgnoreCase(nlComponent.getId())) {
component = target;
} else {
return component;
}
}
}
use of com.android.tools.idea.uibuilder.scene.SceneComponent in project android by JetBrains.
the class GuidelineTarget method layout.
@Override
public boolean layout(@NotNull SceneContext sceneTransform, int l, int t, int r, int b) {
int dist = 6;
SceneComponent parent = myComponent.getParent();
if (parent != null) {
if (myIsHorizontal) {
myLeft = parent.getDrawX();
myRight = parent.getDrawX() + parent.getDrawWidth();
myTop = t - dist;
myBottom = t + dist;
} else {
myLeft = l - dist;
myRight = l + dist;
myTop = parent.getDrawY();
myBottom = parent.getDrawY() + parent.getDrawHeight();
}
}
NlComponent component = myComponent.getNlComponent();
String begin = component.getLiveAttribute(SdkConstants.SHERPA_URI, SdkConstants.LAYOUT_CONSTRAINT_GUIDE_BEGIN);
String end = component.getLiveAttribute(SdkConstants.SHERPA_URI, SdkConstants.LAYOUT_CONSTRAINT_GUIDE_END);
String percent = component.getLiveAttribute(SdkConstants.SHERPA_URI, SdkConstants.LAYOUT_CONSTRAINT_GUIDE_PERCENT);
if (begin != null) {
myBegin = ConstraintComponentUtilities.getDpValue(component, begin);
myEnd = -1;
myPercent = -1;
} else if (end != null) {
myBegin = -1;
myEnd = ConstraintComponentUtilities.getDpValue(component, end);
myPercent = -1;
} else if (percent != null) {
myBegin = -1;
myEnd = -1;
try {
myPercent = Float.valueOf(percent);
} catch (NumberFormatException e) {
myPercent = 0;
}
}
return false;
}
Aggregations