# New display format needed: “drag box”

I want to create a new display type, especially for numbers or text, but potentially for arbitrary objects as well. I want a "drag box" where not all of the number (object) is visible, but dragging left and right on the object itself slides it left and right (or in a generalized form both x and y).

No scroll bars should be visible, and it should be tightly integrated much like Framed so that it can be used in different places without difficulty.

In Chat Szabolcs showed how to get the basic functionality. However, there are problems with this implementation as he notes:

1. the N[Pi,100] shouldn't be recalculated constantly

2. ... Dynamic doesn't work inside the ScrollPosition setting ...

3. when the mouse leaves the region, it stops working, and for good usability it shouldn't

I don't observe #3 on my system (Win7/mma7) but I do note another problem: Dragging the text left (looking at the least significant digits) it is possible to drag the object completely out of frame. Dragging it right does not move it out of frame but causes a memory of the drag such that it appears "stuck" when you start dragging left, though it eventually moves.

• How can this function be implemented most efficiently and flexibly?

• Can it be made to work inside a Text object the way Frame does?

-
I'm not sure I understood very well the subtleties. Wouldn't for example the N[Pi, 100] recalculation be fixed by injecting it with With or something? Btw, Win7/mma 8, when I drag it right to the most significant digits I can drag it out of frame, but not to the left. I mean, you have to drag it inside the cell for it to work – Rojo Jun 17 '12 at 19:14
@Rojo What I meant was that I was lazy to fix up the solution there. These were problems that need to be fixed. Of course it can be injected with With, I just didn't do it on the first try. – Szabolcs Jun 18 '12 at 9:44
@Mr.Wizard You don't need to worry about points and credit when dealing with me ;-) I don't want to post an answer, I think Rojo's answer works quite well. – Szabolcs Jun 18 '12 at 16:41
@Szabolcs okay; it just felt odd to wait until you were out to post but that's the way my schedule worked yesterday. – Mr.Wizard Jun 18 '12 at 16:51

I'm not sure I understood the concerns, so let me know how this works. The N[Pi , 50] isn't recalculated since Dragger doesn't have the attributes HoldFirst or family. Seems it can be dragged anywhere. And I don't know about the rest.

Dragger[exp_, size_] :=
With[{maxsize =
First[ImageSize /. Options[Rasterize@exp, ImageSize]] - 0.95 size},
DynamicModule[{x = 0., b = False, ref},
MouseAppearance[
EventHandler[
Pane[Pane[exp, 100000], ImageSize -> size,
ScrollPosition :>
Dynamic[{If[b,
Clip[x + ref - First@MousePosition["ScreenAbsolute"], {0.,
maxsize}], x], 0.},
Null &]], {"MouseDown" :> (ref =
First@MousePosition["ScreenAbsolute"]; b = True),
"MouseUp" :> (b = False;
x =
Clip[x + ref - First@MousePosition["ScreenAbsolute"], {0.,
maxsize}])}], "FrameLRResize"]]]


I thought this would be inefficient in that it would update for every change in MousePosition, so I was ready to wrap a Refresh such as If[b, Refresh[..., UpdateInterval:>0.05]..., but in my tests it is smarter than I thought and doesn't try to update when b is False

So you should run Dragger[N[Pi, 50], 100] to test it

-
This snaps back to the original position when I let go of the mouse button (actually when a move a pixel or two after). Is that the intent? Also, I can still drag the text out of frame when dragging while moving the mouse left. +1 for working on this however. :-) – Mr.Wizard Jun 17 '12 at 20:18
No, it wasn't the intent. But I'm doing this through remote desktop on a clumsy connection so it's hard to see the subtleties of the interactivity. Just now I understood what you meant with the dragging left issue. It doesn't seem to be snapping back to the original position for me. – Rojo Jun 17 '12 at 20:35
@Mr.Wizard Editing to add an ugly patch for the left dragging thing – Rojo Jun 17 '12 at 20:43
You don't really need :> in ScrollPosition. -> will do. – Szabolcs Jun 18 '12 at 9:49