4
$\begingroup$

I'm trying to create a set of SetterBar within my DynamicModule, but I want to have it so that an individual button gets disabled if a certain button is pressed on a different setter bar. Here is the relevant code:

DynamicModule[{Clo = 1, Cp = 0, Cprj = 0}, GraphicsColumn[{ Column[ {Style[ "Location of C", FontSize -> 10], SetterBar[ Dynamic[Clo], {0 -> "Origin", 1 -> "Tip of B"}]}, Alignment -> Center, Background -> None], Column[{ Style["Location of (A.C)A^", FontSize -> 10], SetterBar[Dynamic[{Cp, Cprj}], { {0, 0} -> Style["Origin of C", FontSize -> 9], {1, 0} -> Style["Tip of C", FontSize -> 9], {0, 1} -> Style["End of (A.B)A^", GrayLevel[Dynamic[(Clo*-0.7) + 0.7]], FontSize -> 9] }]}, Alignment -> Center, Background -> None], Row[{"Clo = ", Dynamic[Clo], " Cp = ", Dynamic[Cp], " Cprj = ", Dynamic[Cprj]}]}]] 

This yields the result of the image below.

Here I clicked on "Origin" and "End of ...", the latter being the original formatting of the labels. Is there a way to actually disable the "End of ..." button while still having it display, if and only if Clo=0? I want to have it so that it is not possible to click on the grayed out option, but possible to toggle between the other two.

$\endgroup$
2
  • 1
    $\begingroup$ Do you get what you need if you replace the second SetterBar with Row[MapThread[ Setter[Dynamic[{Cp, Cprj}], {#}, #2, Enabled -> #3] &, {{{0, 0}, {1, 0}, {0, 1}}, {Style["Origin of C", FontSize -> 9],Style[ "Tip of C", FontSize -> 9], Style["End of (A.B)A^",FontSize -> 9, FontColor -> GrayLevel[Dynamic[(Clo*-0.7) + 0.7]]]}, {True, True, Dynamic[Clo == 1]}}]]? $\endgroup$ Commented Sep 15, 2021 at 15:21
  • $\begingroup$ Yes! that's perfect, thank you! $\endgroup$ Commented Sep 15, 2021 at 15:59

1 Answer 1

6
$\begingroup$

1. Replace your second SetterBar with a row of individual setters and link Enabled option value for the third setter to the value of Clo:

DynamicModule[{Clo = 1, Cp = 0, Cprj = 0}, Column[{Column[{Style["Location of C", FontSize -> 14], SetterBar[Dynamic[Clo], {0 -> "Origin", 1 -> "Tip of B"}]}, Alignment -> Center, Background -> None], Column[{Style["Location of (A.C)" <> ToString[OverHat[A], StandardForm], FontSize -> 14], Row[MapThread[Setter[Dynamic[{Cp, Cprj}], {#}, #2, Enabled -> #3] &, {{{0, 0}, {1, 0}, {0, 1}}, {Style["Origin of C", FontSize -> 12], Style["Tip of C", FontSize -> 12], Style["End of (A.B)" <> ToString[OverHat[A], StandardForm], FontSize -> 12, FontColor -> GrayLevel[Dynamic[-.7 Clo] + 0.7]]}, {True, True, Dynamic[Clo == 1]}}]]}, Alignment -> Center, Background -> None], Row[{"Clo = ", Dynamic[Clo], " Cp = ", Dynamic[Cp], " Cprj = ", Dynamic[Cprj]}]}, Center, 2]] 

enter image description here

2. Alternatively, add the option Enabled -> True to SetterBar[...] and post-process to inject Dynamic[Clo == 1] in desired position in box expression:

postProcess = RawBoxes @* ReplaceAll[sb : SetterBox[_, {{0, 1}}, ___] :> RuleCondition[sb /. True -> Dynamic[Clo == 1]]] @* ToBoxes; DynamicModule[{Clo = 1, Cp = 0, Cprj = 0}, Column[{Column[{Style["Location of C", FontSize -> 14], SetterBar[Dynamic[Clo], {0 -> "Origin", 1 -> "Tip of B"}]}, Alignment -> Center, Background -> None], Column[{Style["Location of (A.C)" <> ToString[OverHat[A], StandardForm], FontSize -> 14], postProcess @ SetterBar[Dynamic[{Cp, Cprj}], {{0, 0} -> Style["Origin of C", FontSize -> 12], {1, 0} -> Style["Tip of C", FontSize -> 12], {0, 1} -> Style[Style["End of (A.B)" <> ToString[OverHat[A], StandardForm], FontSize -> 12], GrayLevel[Dynamic[(Clo*-0.7) + 0.7]]]}, Enabled -> True]}, Alignment -> Center, Background -> None], Row[{"Clo = ", Dynamic[Clo], " Cp = ", Dynamic[Cp], " Cprj = ", Dynamic[Cprj]}]}, Center, 2]] 

enter image description here

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.