13
$\begingroup$

I would like to make an Epilog moveable. For example, the following code generates a Manipulate with a framed pane containing some notes. I would like the user to be able to move those notes anywhere inside the graphics area using a drag and drop. This will allow the user to see what's behind it without completing hiding the notes using the checkbox provided.

Manipulate[
 Plot[Sin[a*x] - .3, {x, -3, 3}, 
  Epilog -> 
   Inset[If[t, 
     Framed[Pane[
       "I want the user to have the abilty to move this box anywhere
inside this white area so the user can see what's behind it.", 70], 
      Background -> LightBlue, RoundingRadius -> 4, 
      BaseStyle -> Gray], ""], {Right, Bottom}, {Right, Bottom}]], {a,
   1, 10}, {{t, True, "Hide/Show Notes"}, {True, False}}]

enter image description here

How would I go about programming this? I was thinking about using a locator control but not sure if this is the best way. I want to be able to click ANYWHERE on the framed pane and drag it anywhere in the graphics area. It seems like there should be a simple way to do this. Ideas?

$\endgroup$
  • 2
    $\begingroup$ I would like the user to be able to move those notes anywhere inside the graphics area using a drag and drop From usability point of view, I do not think this is a good idea for GUI. I do not want to look at something where I have to move stuff using the mouse on it to see what behind them or around them. User will also have to know they can use the mouse to do this. This is all too hectic if you ask me. Having a button to show/hide notes is a fine idea. But not having user move the notes around with the mouse. $\endgroup$ – Nasser Dec 25 '17 at 8:05
  • 1
    $\begingroup$ one way: add the control {{loc, {1, 1}}, {-3, -2}, {3, 1}, ControlType -> Locator, Appearance -> None} to Manipulate and replace the first {Right, Bottom} inside Inset with loc. $\endgroup$ – kglr Dec 25 '17 at 8:08
  • $\begingroup$ Hmmm... you may be right. But on the flip side the user does not "have to" move stuff to see what's behind it. I have a checkbox for that. Also, it is intuitive to try and move a things that are in the way with the mouse, so I don't see that being an issue. I look at this as something most of time people won't need, but there are some times when I really want to move a note box a little bit to get a slightly better view, but I can't. I'll post solution and see what people think as far as usability. $\endgroup$ – Michael McCain Dec 25 '17 at 8:11
  • 1
    $\begingroup$ As I said, having a check box to show/hide notations, is good idea. It is the user needing to reach to the mouse and move stuff around which I do not think is needed. But it is your GUI and you are free to do it as you want., I was just giving my 2 cents worth opinion ;) $\endgroup$ – Nasser Dec 25 '17 at 8:30
  • $\begingroup$ Something like this mathematica.stackexchange.com/questions/14556/…? $\endgroup$ – Mike Honeychurch Dec 25 '17 at 8:52
14
$\begingroup$

Related: 14556 and 7547

Using Locator to give you the control you are seeking :

Manipulate[
 Plot[Sin[a*x] - .3, {x, -3, 3}, Epilog -> {Dynamic[If[t,
      Locator[Dynamic[pt], 
       Framed[Pane[
         "I want the user to have the abilty to move this box \
anywhere
         inside this white area so the user can see what's behind \
it.", 70], Background -> LightBlue, RoundingRadius -> 4, 
        BaseStyle -> Gray],
       Background -> White, ImageSize -> 150], {}]]}],

 {a, 1, 10},
 {{t, True, "Hide/Show Notes"}, {True, False}},
 {pt, Scaled[{0.5, 0.5}], None}
 ]

enter image description here

$\endgroup$
  • $\begingroup$ Yes! This works great! I tried extending this to a three dimensional plot but running into issues. Is this possible using the same technique? Ooops... yes locators don't work in 3d right? Any tips on how to get similar functionality for 3 dimensional graphics. $\endgroup$ – Michael McCain Dec 25 '17 at 9:36
  • 1
    $\begingroup$ @MichaelMcCain if you wanted to use a Locator maybe you could try with one dimension constant so that the locator moves within a plane in the 3D. But depends on your use case how good that would look. $\endgroup$ – Mike Honeychurch Dec 25 '17 at 10:35
  • $\begingroup$ I see. I'll play around with that idea. It does seem to be not nearly as straightforward, Thank you! $\endgroup$ – Michael McCain Dec 25 '17 at 10:47
8
$\begingroup$
Manipulate[Plot[Sin[a x] - .3, {x, -3, 3}, Epilog ->  Dynamic@Inset[If[t, Framed[
       Pane["I want the user to have the abilty to move this box \
anywhere
        inside this white area so the user can see what's behind it.",
         70], Background -> LightBlue, RoundingRadius -> 4, 
       BaseStyle -> Gray], ""], loc, Center]], 
 {a, 1, 10}, 
 {{t, True, "Hide/Show Notes"}, {True, False}}, 
 {{loc, {1, 1}}, {-3, -2}, {3, 1}, ControlType -> Locator, Appearance -> None}]

enter image description here

$\endgroup$
  • $\begingroup$ This works great however, I would I would only like to it move the notebox if you click and drag on the notebox. It currently moves if you click anywhere. Ideas? Sorry I had to uncheck answer because it didn't quite solve the problem as described. $\endgroup$ – Michael McCain Dec 25 '17 at 8:20
  • $\begingroup$ @MichaelMcCain, can't think of a way to do that with locators off the top of my head . I will update if i find a fix. $\endgroup$ – kglr Dec 25 '17 at 8:22
  • $\begingroup$ Ok... Thanks Kglr! I will keep at it as well! $\endgroup$ – Michael McCain Dec 25 '17 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.