diff options
author | Tor Norbye <tnorbye@google.com> | 2010-10-06 15:30:37 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2010-10-06 17:31:32 -0700 |
commit | 1b7aa69940848edc01a44ec2c79a22c0f0b33259 (patch) | |
tree | 9b1f4e7e8d57da51e5b9e7a0a2b44924e943699b /eclipse/plugins/com.android.ide.eclipse.adt/gscripts/android.widget.LinearLayout.groovy | |
parent | 69b73d4b186ad4074a746bafcc425512e050e385 (diff) | |
download | sdk-1b7aa69940848edc01a44ec2c79a22c0f0b33259.zip sdk-1b7aa69940848edc01a44ec2c79a22c0f0b33259.tar.gz sdk-1b7aa69940848edc01a44ec2c79a22c0f0b33259.tar.bz2 |
Visual adjustments to the layout feedback
This changeset makes a number of adjustments to the visual feedback
shown during layout dragging & dropping, selection, etc.
These are:
1. Render text on top of a translucent mask (white on a transparent
gray rectangle). This ensures that the text is readable regardless of
what content is under the text. We can't just use the background color
for the normal SWT drawString for two reasons: First, we need to
control the alpha of the background only (since we want the text to be
opaque and the background to be translucent), and second, we often
want to draw multiple lines of text, so we need to manually draw a
background rectangle which accommodates the maximum width of ALL the
lines such taht we don't have a ragged background.
2. Paint the outline mode lines using solid, translucent lines. And
adjust the bounding box computation in this case by 1 pixel such that
when you have adjacent boxes (such as in LinearLayout), you don't end
up with two thin lines next to each other creating a thick line.
3. Change the DrawingStyle internal API from "foreground" and
"background" colors to "stroke" (border) and "fill" (interior), with
individual alphas. This makes the color definitions simpler (for
example we don't need two separate styles, one for the selection
border and one for the selection interior).
4. Make the hover more subtle, using no border and just a light
translucent gray rectangle to only slightly draw attention to the view
under the mouse.
5. Change the appearance of selection to light blue and use a long
dashed border around it. The anchor lines are more faint and more
translucent to make them stand out less.
6. Change the appearance of the drop-preview to use a dash patterned
border identical to the selection border, but colored orange instead.
The matching border pattern will hopefully reinforce that the
drop-preview line is where the selection (also dashed) will go.
7. Use green to show available drop zones (the grid surrounding a
target in RelativeLayout, and the positions between elements in
LinearLayout).
8. For invalid drops, use a white X on a red background as the overlay
fill.
9. I replaced the oval+X pattern from the LayoutHelpers and replaced
them with the orange dashed insert-position lines. I also adjusted the
LinearLayout to draw the bounding boxes such that the middle of the
bounding box, rather than the top left edge, are aligned with the
insert position.
Change-Id: I85c77b9fa84b732a78aac635442f96e7ccfc3983
Diffstat (limited to 'eclipse/plugins/com.android.ide.eclipse.adt/gscripts/android.widget.LinearLayout.groovy')
-rwxr-xr-x | eclipse/plugins/com.android.ide.eclipse.adt/gscripts/android.widget.LinearLayout.groovy | 58 |
1 files changed, 42 insertions, 16 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/gscripts/android.widget.LinearLayout.groovy b/eclipse/plugins/com.android.ide.eclipse.adt/gscripts/android.widget.LinearLayout.groovy index 1865044..ac6543b 100755 --- a/eclipse/plugins/com.android.ide.eclipse.adt/gscripts/android.widget.LinearLayout.groovy +++ b/eclipse/plugins/com.android.ide.eclipse.adt/gscripts/android.widget.LinearLayout.groovy @@ -80,12 +80,24 @@ public class AndroidWidgetLinearLayoutRule extends BaseLayout { targetNode.getChildren().each { def bc = it.getBounds(); if (bc.isValid()) { - // add an insertion point between the last point and the start of this child - int v = isVertical ? bc.y : bc.x; - v = (last + v) / 2; - indexes.add( [v, pos++] ); + // First see if this node looks like it's the same as one of the *dragged* bounds + boolean isDragged = false; + for (element in elements) { + // This tries to determine if an INode corresponds to an IDragElement, by + // comparing their bounds. + if (bc == element.getBounds()) { + isDragged = true; + } + } - last = isVertical ? (bc.y + bc.h) : (bc.x + bc.w); + if (!isDragged) { + // add an insertion point between the last point and the start of this child + int v = isVertical ? bc.y : bc.x; + v = (last + v) / 2; + indexes.add( [v, pos++] ); + + last = isVertical ? (bc.y + bc.h) : (bc.x + bc.w); + } } } @@ -123,8 +135,6 @@ public class AndroidWidgetLinearLayoutRule extends BaseLayout { gc.drawRect(b); gc.useStyle(DrawingStyle.DROP_ZONE); - gc.setLineStyle(IGraphics.LineStyle.LINE_DOT); - gc.setLineWidth(1); def indexes = feedback.userData.indexes; boolean isVertical = feedback.userData.isVertical; @@ -149,17 +159,26 @@ public class AndroidWidgetLinearLayoutRule extends BaseLayout { int x = currX; int y = currY; - // Draw a mark at the drop point. - gc.setLineStyle(IGraphics.LineStyle.LINE_SOLID); - gc.setLineWidth(2); - - gc.drawLine(x - 10, y - 10, x + 10, y + 10); - gc.drawLine(x + 10, y - 10, x - 10, y + 10); - gc.drawOval(x - 10, y - 10, x + 10, y + 10); - Rect be = elements[0].getBounds(); - if (be.isValid()) { + // Draw a mark at the drop point. + if (!be.isValid()) { + // We don't have valid bounds; this typically means we are dragging a new + // View from the palette whose bounds are unknown, so we simply show a single + // dividing line in the center of the position between the children + gc.useStyle(DrawingStyle.DROP_PREVIEW); + if (feedback.userData.width != null) { + int width = feedback.userData.width; + int fromX = x - width / 2; + int toX = x + width / 2; + gc.drawLine(fromX, y, toX, y); + } else if (feedback.userData.height != null) { + int height = (int)feedback.userData.height; + int fromY = y - height / 2; + int toY = y + height / 2; + gc.drawLine(x, fromY, x, toY); + } + } else { // At least the first element has a bound. Draw rectangles // for all dropped elements with valid bounds, offset at // the drop point. @@ -172,11 +191,16 @@ public class AndroidWidgetLinearLayoutRule extends BaseLayout { if (pb.isValid()) { if (isVertical) { offsetX = b.x - pb.x; + // Place the -center- of the bounds at child boundary! + offsetY -= be.h / 2; } else { offsetY = b.y - pb.y; + // Place the -center- of the bounds at child boundary! + offsetX -= be.w / 2; } } + gc.useStyle(DrawingStyle.DROP_PREVIEW); for (element in elements) { drawElement(gc, element, offsetX, offsetY); } @@ -221,9 +245,11 @@ public class AndroidWidgetLinearLayoutRule extends BaseLayout { if (isVertical) { data.currX = b.x + b.w / 2; data.currY = bestIndex; + data.width = b.w; } else { data.currX = bestIndex; data.currY = b.y + b.h / 2; + data.height = b.h; } data.insertPos = bestPos; |