use of android.support.constraint.solver.widgets.ConstraintWidget in project android by JetBrains.
the class WidgetConstraintPanel method updateComponents.
public void updateComponents(@NotNull List<NlComponent> components) {
mComponent = components.isEmpty() ? null : components.get(0);
if (mComponent != null) {
mComponent.addLiveChangeListener(myChangeLiveListener);
mConstraintModel = ConstraintModel.getConstraintModel(mComponent.getModel());
mScene = mConstraintModel.getScene();
mConstraintModel.getSelection().setContinuousListener(e -> widgetChanged());
//TODO: improve the tear-down mechanism
ConstraintWidget widget = mScene.getWidget(mComponent);
if (widget == null)
return;
configureUI();
}
}
use of android.support.constraint.solver.widgets.ConstraintWidget in project android by JetBrains.
the class ScoutArrange method expandVertically.
/**
* Expands widgets vertically in an evenly spaced manner
* @param widgetList
* @param margin
*/
private static void expandVertically(ArrayList<ConstraintWidget> widgetList, int margin) {
WidgetContainer base = (WidgetContainer) widgetList.get(0).getParent();
ConstraintWidget[] pears = new ConstraintWidget[base.getChildren().size()];
pears = base.getChildren().toArray(pears);
Rectangle selectBounds = getBoundingBox(widgetList);
Rectangle clip = new Rectangle();
int gapNorth = gap(Direction.NORTH, selectBounds, pears);
int gapSouth = gap(Direction.SOUTH, selectBounds, pears);
clip.y = selectBounds.y - gapNorth;
clip.height = selectBounds.height + gapSouth + gapNorth;
ArrayList<ConstraintWidget> selectedList = new ArrayList<>(widgetList);
while (!selectedList.isEmpty()) {
ConstraintWidget widget = selectedList.remove(0);
ArrayList<ConstraintWidget> col = new ArrayList<>();
col.add(widget);
for (Iterator<ConstraintWidget> iterator = selectedList.iterator(); iterator.hasNext(); ) {
ConstraintWidget elem = iterator.next();
if (isSameColumn(widget, elem)) {
if (!col.contains(elem)) {
col.add(elem);
}
iterator.remove();
}
}
ConstraintWidget[] colArray = new ConstraintWidget[col.size()];
colArray = col.toArray(colArray);
Arrays.sort(colArray, sSortY);
int gaps = (colArray.length - 1) * margin;
int totalHeight = (clip.height - gaps - 2 * margin);
for (int i = 0; i < colArray.length; i++) {
int y = margin * i + (i * (totalHeight)) / colArray.length;
ConstraintWidget constraintWidget = colArray[i];
constraintWidget.setY(y + clip.y + margin);
int yend = margin * i + (totalHeight * (i + 1)) / colArray.length;
constraintWidget.setVerticalDimensionBehaviour(ConstraintWidget.DimensionBehaviour.FIXED);
constraintWidget.setHeight(yend - y);
}
}
}
use of android.support.constraint.solver.widgets.ConstraintWidget in project android by JetBrains.
the class ScoutArrange method expandHorizontally.
/**
* Expands widgets horizontally in an evenly spaced manner
* @param widgetList
* @param margin
*/
public static void expandHorizontally(ArrayList<ConstraintWidget> widgetList, int margin) {
WidgetContainer base = (WidgetContainer) widgetList.get(0).getParent();
ConstraintWidget[] pears = new ConstraintWidget[base.getChildren().size()];
pears = base.getChildren().toArray(pears);
Rectangle selectBounds = getBoundingBox(widgetList);
Rectangle clip = new Rectangle();
int gapWest = gap(Direction.WEST, selectBounds, pears);
int gapEast = gap(Direction.EAST, selectBounds, pears);
clip.x = selectBounds.x - gapWest;
clip.width = selectBounds.width + gapEast + gapWest;
ArrayList<ConstraintWidget> selectedList;
selectedList = new ArrayList<ConstraintWidget>(widgetList);
while (!selectedList.isEmpty()) {
ConstraintWidget widget = selectedList.remove(0);
ArrayList<ConstraintWidget> row = new ArrayList<>();
row.add(widget);
for (Iterator<ConstraintWidget> iterator = selectedList.iterator(); iterator.hasNext(); ) {
ConstraintWidget elem = iterator.next();
if (isSameRow(widget, elem)) {
if (!row.contains(elem)) {
row.add(elem);
}
iterator.remove();
}
}
ConstraintWidget[] rowArray = new ConstraintWidget[row.size()];
rowArray = row.toArray(rowArray);
Arrays.sort(rowArray, sSortX);
int gaps = (rowArray.length - 1) * margin;
int totalWidth = (clip.width - gaps - 2 * margin);
for (int i = 0; i < rowArray.length; i++) {
int x = margin * i + (i * (totalWidth)) / rowArray.length;
ConstraintWidget constraintWidget = rowArray[i];
constraintWidget.setX(x + clip.x + margin);
int xend = margin * i + (totalWidth * (i + 1)) / rowArray.length;
constraintWidget.setHorizontalDimensionBehaviour(ConstraintWidget.DimensionBehaviour.FIXED);
constraintWidget.setWidth(xend - x);
}
}
}
use of android.support.constraint.solver.widgets.ConstraintWidget in project android by JetBrains.
the class ScoutArrange method nearestHorizontal.
/**
* find the nearest widget in a list of widgets only considering the horizontal location
*
* @param nextTo find nearest to this widget
* @param list list to search
* @return the nearest in the list
*/
private static ConstraintWidget nearestHorizontal(ConstraintWidget nextTo, ArrayList<ConstraintWidget> list) {
int min = Integer.MAX_VALUE;
ConstraintWidget ret = null;
int nextToLeft = nextTo.getX();
int nextToRight = nextToLeft + nextTo.getWidth();
for (ConstraintWidget widget : list) {
if (widget == nextTo) {
continue;
}
int left = widget.getX();
int right = left + widget.getWidth();
int dist = Math.abs(left - nextToLeft);
dist = Math.min(dist, Math.abs(left - nextToRight));
dist = Math.min(dist, Math.abs(right - nextToRight));
dist = Math.min(dist, Math.abs(right - nextToLeft));
if (dist < min) {
min = dist;
ret = widget;
}
}
return ret;
}
use of android.support.constraint.solver.widgets.ConstraintWidget in project android by JetBrains.
the class ScoutArrange method gap.
/**
* Calculate the gap in to the nearest widget
*
* @param direction the direction to check
* @param list list of other widgets (root == list[0])
* @return the distance on that side
*/
public static int gap(Direction direction, Rectangle region, ConstraintWidget[] list) {
int rootWidth = list[0].getParent().getWidth();
int rootHeight = list[0].getParent().getHeight();
Rectangle rect = new Rectangle();
switch(direction) {
case NORTH:
{
rect.y = 0;
rect.x = region.x + 1;
rect.width = region.width - 2;
rect.height = region.y;
}
break;
case SOUTH:
{
rect.y = region.y + region.height + 1;
rect.x = region.x + 1;
rect.width = region.width - 2;
rect.height = rootHeight - rect.y;
}
break;
case WEST:
{
rect.y = region.y + 1;
rect.x = 0;
rect.width = region.x;
rect.height = region.height - 2;
}
break;
case EAST:
{
rect.y = region.y + 1;
rect.x = region.x + region.width + 1;
rect.width = rootWidth - rect.x;
rect.height = region.height - 2;
}
break;
}
int min = Integer.MAX_VALUE;
for (int i = 0; i < list.length; i++) {
ConstraintWidget widget = list[i];
Rectangle r = getRectangle(widget);
if (r.intersects(rect)) {
int dist = (int) distance(r, region);
if (min > dist) {
min = dist;
}
}
}
if (min > Math.max(rootHeight, rootWidth)) {
switch(direction) {
case NORTH:
return region.y;
case SOUTH:
return rootHeight - (region.y + region.height);
case WEST:
return region.x;
case EAST:
return rootWidth - (region.x + region.width);
}
}
return min;
}
Aggregations