The serious flaw of Dynamic
is a combination of facts:
it is triggered/refreshed by any kind of mutation of a symbol,
careful metaprogramming/construction of symbols is really cumbersome
An example is worth a thousand words so:
{ Dynamic@x[[1]], Dynamic@x[[2]]}
You can't trigger one without other one being affected even if the value didn't change. And writing:
{ Dynamic @ x1, Dynamic @ x2 }
will be tough to automatically scale/maintain for regular users. A real world example can be found here:
Allow multiple GUI elements to react dynamically to interaction with a single element
The code in the answer is not something you'd love to write on daily basis:
DynamicModule[{}, Graphics[{
( ToExpression[
"{sA:=state" <> ToString[#] <> ", sB:=state" <> ToString[#2] <> "}",
StandardForm,
Hold
] /. Hold[spec_] :> With[spec,
{ Dynamic @ If[TrueQ[sA || sB], Red, Black],
Line[{pts[#1], pts[#2]}]
}
]
) & @@@ edges
,
PointSize[0.025],
(
ToExpression[
"{sA:=state" <> ToString[#] <> "}",
StandardForm,
Hold
] /. Hold[spec_] :> With[spec,
{ Dynamic @ If[TrueQ[sA], Red, Black],
EventHandler[ Point @ pts[#],
{"MouseEntered" :> (sA = True), "MouseExited" :> (sA = False)}
]
}
]
) & /@ names
},
ImageSize -> Large]
]
Very often a smart, specific solution can be applied but it would be nice to be able to do mindless things and not be limited by syntax/design issues but real limitations of how much FrontEnd can handle.
What can we do to make programming of idioms presented in the linked question more approachable?
Related topic: How to track Part of Symbol or How to symbolize Parts of Symbol without copying data
Comments
Post a Comment