3

This is one of those annoying things that you put aside for years before making a post of it. Put a dynamic Graphics into a gui object (Button, Panel, etc.), and the result will show the graphics with the stylesheet default background until the mouse is moved over the object. In my example, I've used the ReverseColor stylesheet (Format > Stylesheet > ReverseColor) as it demonstrates my problem more clearly, but it happens with the default stylesheet's white background the same way.

Example 1

If the graphics is wrapped in Dynamic it appears with the stylesheet background. Note, that Button is even worse, as the label need not be dynamic to be malformed.

icon = Graphics[{Green, Disk[]}, ImageSize -> {15, 15}, Background -> None];

{Button[Row@{icon}, {}],
 Panel[Row@{icon}],
 Pane[Row@{icon}, BaseStyle -> {Background -> White}],
 Framed[Row@{icon}, Background -> White]}

{Button[Dynamic@Row@{icon}, {}],
 Panel[Dynamic@Row@{icon}],
 Pane[Dynamic@Row@{icon}, BaseStyle -> {Background -> White}],
 Framed[Dynamic@Row@{icon}, Background -> White]}

enter image description here

Note, that you don't have to click on anything, just move the mouse over the output. Clearly, as the output is in a list, it is enough to update one of them.

Example 2

Any function that wraps the dynamic graphics and appears on screen (i.e. is not Identity, HoldForm or similar) results in bad behaviour.

{
 Panel[Dynamic@icon],
 Panel[Dynamic@{icon}],
 Panel[Dynamic@Row@{icon}],
 Panel[Dynamic@Column@{icon}],
 Panel[Dynamic@Grid@{{icon}}]
 }

enter image description here

Example 3

I assume, that Button internally puts a Dynamic around its first argument, as it appears with the black background even if there is no Dynamic around the graphics. Furthermore, if a FinishDynamic[] is issued right after (has to appear on screen, hence the List wrapper), one can clearly see that the Button appears first malformed after which it turns ok.

Button[icon]
Pause[.5];
List@FinishDynamic[]

enter image description here

Q1: Why Background -> None uses the stylesheet background instead of inheriting the background of the wrapping gui object? It seems like, that Graphics inherits the background for from the immediately wrapping function (for one level), and if it has no Background specification, it reverts to the stylesheet's.

Q2: Why is this behaviour corrected when mouse moves over the object?

Q3: Why is there a Dynamic internally around the first argument of Button?

Is it a graphics-card related glitch? Can we consider it a bug?

István Zachar
  • 47,032
  • 20
  • 143
  • 291

0 Answers0