OSDN Git Service

Adjust hint feedback location
authorTor Norbye <tnorbye@google.com>
Sat, 15 Jan 2011 06:51:04 +0000 (22:51 -0800)
committerTor Norbye <tnorbye@google.com>
Sat, 15 Jan 2011 06:51:04 +0000 (22:51 -0800)
When you select items in the relative layout, the layout attachments
are displayed below the canvas.

This changeset tweaks the positioning of these hints: they are
displayed to the right of the window (instead of below it) if the
canvas is taller than it is wide.

Change-Id: I7e12ed2f1749d4d3e529bab1a765b6a3279ca084

eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SelectionOverlay.java

index dc42b1b..8a5e198 100755 (executable)
@@ -235,7 +235,7 @@ public class LayoutCanvas extends Canvas {
         // mOutlineOverlay and mEmptyOverlay are initialized lazily
         mHoverOverlay = new HoverOverlay(mHScale, mVScale);
         mHoverOverlay.create(display);
-        mSelectionOverlay = new SelectionOverlay();
+        mSelectionOverlay = new SelectionOverlay(this);
         mSelectionOverlay.create(display);
         mImageOverlay = new ImageOverlay(this, mHScale, mVScale);
         mIncludeOverlay = new IncludeOverlay(this);
index eb0601f..90aeebf 100644 (file)
@@ -29,10 +29,15 @@ import java.util.List;
  * The {@link SelectionOverlay} paints the current selection as an overlay.
  */
 public class SelectionOverlay extends Overlay {
+    private final LayoutCanvas mCanvas;
+
     /**
      * Constructs a new {@link SelectionOverlay} tied to the given canvas.
+     *
+     * @param canvas the associated canvas
      */
-    public SelectionOverlay() {
+    public SelectionOverlay(LayoutCanvas canvas) {
+        mCanvas = canvas;
     }
 
     /**
@@ -92,8 +97,23 @@ public class SelectionOverlay extends Overlay {
                 List<String> infos = rulesEngine.callGetSelectionHint(parentNode, node);
                 if (infos != null && infos.size() > 0) {
                     gcWrapper.useStyle(DrawingStyle.HELP);
-                    int x = b.x + 10;
-                    int y = b.y + b.h + 10;
+                    double scale = mCanvas.getScale();
+
+                    // Compute the location to display the help. This is done in
+                    // layout coordinates, so we need to apply the scale in reverse
+                    // when making pixel margins
+                    // TODO: We could take the Canvas dimensions into account to see
+                    // where there is more room.
+                    // TODO: The scrollbars should take the presence of hint text
+                    // into account.
+                    int x, y;
+                    if (b.w > b.h) {
+                        x = (int) (b.x + 3 / scale);
+                        y = (int) (b.y + b.h + 10 / scale);
+                    } else {
+                        x = (int) (b.x + b.w + 10 / scale);
+                        y = (int) (b.y + 3 / scale);
+                    }
                     gcWrapper.drawBoxedStrings(x, y, infos);
                 }
             }