You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by tv...@apache.org on 2009/03/24 23:14:47 UTC
svn commit: r758057 - in /incubator/pivot/trunk/wtk/src/pivot/wtk:
Component.java content/ListViewItemEditor.java
content/TreeViewNodeEditor.java
Author: tvolkert
Date: Tue Mar 24 22:14:45 2009
New Revision: 758057
URL: http://svn.apache.org/viewvc?rev=758057&view=rev
Log:
Implemented Component#constrainToViewportBounds()
Modified:
incubator/pivot/trunk/wtk/src/pivot/wtk/Component.java
incubator/pivot/trunk/wtk/src/pivot/wtk/content/ListViewItemEditor.java
incubator/pivot/trunk/wtk/src/pivot/wtk/content/TreeViewNodeEditor.java
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/Component.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/Component.java?rev=758057&r1=758056&r2=758057&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/Component.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/Component.java Tue Mar 24 22:14:45 2009
@@ -1512,44 +1512,47 @@
}
/**
- * Alters the specified bounds such that they fit within the viewport of
- * all <tt>Viewport</tt> ancestors of this component.
+ * Constrains the specified bounds such that they fit within the bounds of
+ * all <tt>Viewport</tt> ancestors of this component. For
+ * non-<tt>Viewport</tt> ancestors, it will constrain to the component
+ * bounds of the ancestor.
+ *
+ * @return
+ * The constrained bounds, in this component's coordinate space.
*/
- public void constrainToViewportBounds(Bounds area) {
- // TODO
- /*
+ public Bounds constrainToViewportBounds(int x, int y, int width, int height) {
Component component = this;
- int top = area.y;
- int left = area.x;
- int bottom = area.y + area.height - 1;
- int right = area.x + area.width - 1;
+ int xOffset = 0;
+ int yOffset = 0;
while (component != null) {
- int minTop = 0;
- int minLeft = 0;
- int maxBottom = component.getHeight() - 1;
- int maxRight = component.getWidth() - 1;
+ int viewportWidth = component.getWidth();
+ int viewportHeight = component.getHeight();
if (component instanceof Viewport) {
Viewport viewport = (Viewport)component;
Bounds viewportBounds = viewport.getViewportBounds();
- // Adjust constraints per the viewport bounds
- minTop = viewportBounds.y;
- minLeft = viewportBounds.x;
- maxBottom = viewportBounds.y + viewportBounds.height - 1;
- maxRight = viewportBounds.x + viewportBounds.width - 1;
+ xOffset += viewportBounds.x;
+ yOffset += viewportBounds.y;
+
+ viewportWidth = viewportBounds.width;
+ viewportHeight = viewportBounds.height;
}
- top = component.y + Math.max(top, minTop);
- left = component.x + Math.max(left, minLeft);
- bottom = component.y + Math.max(Math.min(bottom, maxBottom), -1);
- right = component.x + Math.max(Math.min(right, maxRight), -1);
+ x = Math.max(x, xOffset);
+ y = Math.max(y, yOffset);
+ width = Math.min(width, xOffset + viewportWidth - x);
+ height = Math.min(height, yOffset + viewportHeight - y);
+
+ xOffset -= component.getX();
+ yOffset -= component.getY();
component = component.getParent();
}
- */
+
+ return new Bounds(x, y, width, height);
}
/**
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/content/ListViewItemEditor.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/content/ListViewItemEditor.java?rev=758057&r1=758056&r2=758057&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/content/ListViewItemEditor.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/content/ListViewItemEditor.java Tue Mar 24 22:14:45 2009
@@ -216,10 +216,11 @@
// Scroll to make the text as visible as possible
listView.scrollAreaToVisible(editBounds.x, editBounds.y,
- textBounds.width, editBounds.height);
+ textBounds.width + padding.left + 1, editBounds.height);
// Constrain the bounds by what is visible through Viewport ancestors
- listView.constrainToViewportBounds(editBounds);
+ editBounds = listView.constrainToViewportBounds(editBounds.x, editBounds.y,
+ editBounds.width, editBounds.height);
textInput.setText(listItem.getText());
textInput.setPreferredWidth(editBounds.width);
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/content/TreeViewNodeEditor.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/content/TreeViewNodeEditor.java?rev=758057&r1=758056&r2=758057&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/content/TreeViewNodeEditor.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/content/TreeViewNodeEditor.java Tue Mar 24 22:14:45 2009
@@ -242,10 +242,11 @@
// Scroll to make the text as visible as possible
treeView.scrollAreaToVisible(editBounds.x, editBounds.y,
- textBounds.width, editBounds.height);
+ textBounds.width + padding.left + 1, editBounds.height);
// Constrain the bounds by what is visible through Viewport ancestors
- treeView.constrainToViewportBounds(editBounds);
+ editBounds = treeView.constrainToViewportBounds(editBounds.x, editBounds.y,
+ editBounds.width, editBounds.height);
textInput.setText(nodeData.getText());
textInput.setPreferredWidth(editBounds.width);