This Question is Assumed Answered

1 "correct" answer available (5 pts) 15 "helpful" answers available (3 pts)
5 Replies Last post: Aug 5, 2008 12:36 AM by carl

When TreeControl in ScrollBox. How to get Top TreeNode .

Jul 27, 2008 6:55 PM

Click to view Poseidon.UD's profile Level 2 Poseidon.UD 37 posts since
Jul 3, 2008

a TreeControl in a ScrollBox.
when the TreeControl.height > ScrollBox.Height , appear ScrollBar.
when the Scrollbar is scrolling. the top 1 TreeNode in Scrollbox is changing.
so .How to get the top 1 Node?
and , if i set any TreeNode to Top Node.the Scrollbar can scroll to right position. how can i do?

you may tell me a way to test. i'm good luck .Thank u.

Click to view Kamal's profile Curl Kamal 139 posts since
Oct 17, 2007
1. Re: When TreeControl in ScrollBox. How to get Top TreeNode . Jul 28, 2008 5:22 AM
Do you want to know the first visible TreeNode in your TreeControl that is inside a ScrollBox?
Click to view Poseidon.UD's profile Level 2 Poseidon.UD 37 posts since
Jul 3, 2008
2. Re: When TreeControl in ScrollBox. How to get Top TreeNode . Jul 28, 2008 6:12 PM
in response to: Kamal
yes.
Click to view carl's profile Curl carl 74 posts since
Oct 17, 2007
3. Re: When TreeControl in ScrollBox. How to get Top TreeNode . Jul 28, 2008 6:51 PM
I believe that current-nodes are automatically scrolled into view when possible already, so you might not need to worry about that, unless you want more control over exactly where they are scrolled to. In which case you could look at Visual.scroll-to-include.

This is certainly possible, but you would probably need to use the OPEN-CONTROLS package to do this reasonably. After a change in the scroll position, you could compare the bounds of each child cell of the StandardTreeControlUI with the visible bounds of the ScrollBox, and thereby determine what's actually on screen.

You could theoretically avoid using OPEN-CONTROLS by using a custom tree-item-creation-proc, though this way would be somewhat indirect. If you kept track of the TreeItems returned by your proc, you could try to check to see where each one is relative to the ScrollBox's visible bounds after each change in the ScrollBox, using, for example, the proc "transform-coordinates-with-test". This can be optimized somewhat since you know the order that the TreeItems will be shown in.

(This kind of operation should be easier in 7.0 when using SkinnableTreeControlUI, as that class has more public interfaces to its sub-Graphics.)
Click to view Poseidon.UD's profile Level 2 Poseidon.UD 37 posts since
Jul 3, 2008
4. Re: When TreeControl in ScrollBox. How to get Top TreeNode . Aug 5, 2008 12:09 AM
in response to: carl

how to use Visual.scroll-to-include ? thank u.


Click to view carl's profile Curl carl 74 posts since
Oct 17, 2007
5. Re: When TreeControl in ScrollBox. How to get Top TreeNode . Aug 5, 2008 12:36 AM
in response to: Poseidon.UD
You simply pass it the coordinate(s) relative to the object's origin that you want to be brought into view. The documentation for the method is pretty good, and lists a few additional options you can use if necessary.

Generally you might try scrolling two corners of your Visual into view; with just one corner, you might end up just that one point visible. For just vertical inclusion, you might try something like:

  || Scroll the cell into view by scrolling to bottom then top edges.
  {method package {vertical-scroll-to-include}:void
    def bounds = {self.get-bounds}
    {self.scroll-to-include y = bounds.descent}
    {self.scroll-to-include y = -bounds.ascent}
  }