2
$\begingroup$

Let's say we have a Rectangle with color which depends of CurrentValue["MouseOver"]:

Deploy@Framed@Graphics[
       Dynamic @ {If[CurrentValue["MouseOver"], Red, Green], Rectangle[]}
       , ImagePadding -> 10]

enter image description here

  • With cursor over the Rectangle[] the color switches to Red as expected,
  • also if one put the "MouseDown" and drag it around it is still Red,
  • however if you put the "MouseDown" outside the rectangle, on the padded area, and drag it to the rectangle it will not switch the color till "MouseUp".

Is there any way to avoid such behaviour in general?

I can create some workarounds for particular situations but I'm looking for a general solution. I was thinking about EventHandler's PassEvents options but it seems it is a deeper problem (I've failed with this approach :)).


It looks like the problem is the "MouseDown" event is blocking some functions, for example:

$\endgroup$
3
  • $\begingroup$ It doesn't switch until MouseMoved after MouseUp. It's as if MouseMoved and MouseDragged are mutually exclusive, and MouseOver is only updated on MouseMoved? $\endgroup$ Sep 30, 2013 at 10:17
  • $\begingroup$ @TimothyWofford I do not see this, only MouseUp is enough for switch in my case, maybe it's OS dependent? It seems rather that MouseDown is blocking some events detections, try: Dynamic@CurrentValue["ControlKey"] and press Ctrl when the Mouse is down. $\endgroup$
    – Kuba
    Sep 30, 2013 at 10:26
  • $\begingroup$ @Kuba I belive that dynamic interactivity in general is halted during mouse down, at least that has always been my experience (With slider interactions and such being excluded). For instance try DynamicWrapper[ Dynamic[t], Refresh[t = AbsoluteTime[], UpdateInterval -> 0.1] ], and press the mouse button. $\endgroup$
    – jVincent
    Sep 30, 2013 at 10:37

1 Answer 1

1
$\begingroup$

Original (incorrect) answer

When you press in the white area and drag into the green square, you begin a selection just like when you select objects for copy-paste operations. The workaround I propose is to prevent the selection process to begin in the first place.

First way: Create the cell with the option Selectable -> False

CellPrint@Cell[BoxData[ToBoxes@
  Deploy@Framed@Graphics[
   Dynamic@{If[CurrentValue["MouseOver"], Red, Green], 
     Rectangle[]}, ImagePadding -> 10]
  ], Selectable -> False]

Second way: If the cell is already created, press Ctrl+Shift+E and edit the cell options to include Selectable -> False, press Ctrl+Shift+E again.

Update

The following code should produce the result you want:

CellPrint@Cell[BoxData[ToBoxes@
  Framed@Graphics[
    Dynamic@{If[CurrentValue["MouseOver"], Red, Green], 
      Rectangle[]}, ImagePadding -> 10]
  ], Selectable -> False]
$\endgroup$
5
  • $\begingroup$ Mmm ... it works only if you begin from outside the padded area. So, the above is not an answer, yet. I have updated the answer. $\endgroup$
    – Hector
    Sep 30, 2013 at 11:11
  • $\begingroup$ @Hector now it works :) thanks, it seems Deploy is messing around a little. $\endgroup$
    – Kuba
    Sep 30, 2013 at 11:17
  • $\begingroup$ @Kuba: the strange thing is that Deploy is supposed to disable selection. $\endgroup$
    – Hector
    Sep 30, 2013 at 11:18
  • $\begingroup$ @Kuba: I think the problem is that ContentSelectable -> False does not change the properties of the frame. $\endgroup$
    – Hector
    Sep 30, 2013 at 11:22
  • $\begingroup$ @Hector It seems it is really what it is all about. It even helps with DynamicWrapper[ Dynamic[t], Refresh[t = AbsoluteTime[], UpdateInterval -> 0.1] ] $\endgroup$
    – Kuba
    Sep 30, 2013 at 11:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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