<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to hide\unhide GUI elements effectively? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-hide-unhide-GUI-elements-effectively/m-p/824799#M100455</link>
    <description>&lt;P&gt;Depends on your final application and what you consider "robust" and easy to manage, but there are different options:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;You could use if boxes
&lt;UL&gt;
&lt;LI&gt;XPath might be helpful&lt;/LI&gt;
&lt;LI&gt;You could also just wrap your buttons inside some container, so you would only need one if box per mode&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;You could use &amp;lt;&amp;lt; Visibility("Collapse")&lt;/LI&gt;
&lt;LI&gt;You could update button text/actions dynamically when changes happen&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not necessarily they way I would do it, but this is just here to give some potential ideas&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

mode_options = {"Mode1", "Mode2"};

gui = V List Box(
	modeSelector = ComboBox(modeSelectorOptions, 
		&amp;lt;&amp;lt; Set Function(Function({this},
			this &amp;lt;&amp;lt; Inval;
			selection = Contains(mode_options, this &amp;lt;&amp;lt; Get Selected);
			ibs &amp;lt;&amp;lt; Set(0);
			ibs[selection] &amp;lt;&amp;lt; Set(1);
			this &amp;lt;&amp;lt; Update Window;
		));
	),
	Button Box("All Modes", Write("Always active")),
	If Box(0, 
		V List Box(
			Button Box("GUI ELEMENT for Mode1", Write("Button pressed")),
			Button Box("GUI ELEMENT for Mode1", Write("Button pressed")),
			Button Box("GUI ELEMENT for Mode1", Write("Button pressed"))
		)
	),
	If Box(0, 
		V List Box(
			Button Box("GUI ELEMENT for Mode2", Write("Button pressed")),
			Button Box("GUI ELEMENT for Mode2", Write("Button pressed")),
			Button Box("GUI ELEMENT for Mode2", Write("Button pressed"))
		)
	)
);

ibs = gui &amp;lt;&amp;lt; Xpath("//IfBox");

// JMP things
modeSelector &amp;lt;&amp;lt; Set(2, Run Script(0));
modeSelector &amp;lt;&amp;lt; Set(1, Run Script(1));

nw = New Window("Test",&amp;lt;&amp;lt; Show Toolbars(0),&amp;lt;&amp;lt;ShowMenu(0), gui);

Write();&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 21 Dec 2024 06:13:44 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2024-12-21T06:13:44Z</dc:date>
    <item>
      <title>How to hide\unhide GUI elements effectively?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-hide-unhide-GUI-elements-effectively/m-p/824762#M100448</link>
      <description>&lt;P&gt;I have GUI that hides or unhides some elements depending on the selector.&lt;/P&gt;&lt;P&gt;For now I have encapsulated all the elements that change in respective&amp;nbsp; If Box()'es, and change each on of them when ComboBox selector changes, like so:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

modeSelectorOptions = {"Mode1", "Mode2"};
gui = V List Box(
	modeSelector = ComboBox(modeSelectorOptions, 
		&amp;lt;&amp;lt; Set Function(
			Function(
				{this}, 
				Match(this &amp;lt;&amp;lt; Get Selected(),
				modeSelectorOptions[1], Write("\!nMode1");IB1&amp;lt;&amp;lt; Set (1); IB2 &amp;lt;&amp;lt; Set(0)/*many more when script expanded*/,
				modeSelectorOptions[2],	Write("\!nMode2");IB1&amp;lt;&amp;lt; Set (0); IB2 &amp;lt;&amp;lt; Set(1)/*many more when script expanded*/,
				)
			)
		);
	),
	Button Box("All Modes", Write("Always active")),
	IB1 = If Box(1, Button Box("GUI ELEMENT for Mode1", Write("Button pressed"))), 
	IB2 = If Box(0, Button Box("GUI ELEMENT for Mode2", Write("Button pressed")))
	
);

NW = New Window("Test",&amp;lt;&amp;lt; Show Toolbars(0),&amp;lt;&amp;lt;ShowMenu(0), gui);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This works, but it is not very scalable.&lt;/P&gt;&lt;P&gt;I need to hide or unhide certain elements depending on the mode throughout the whole window with many elements. I have to encapsulate each of those changing elements in an If Box(), name it and don't forget to include it in the Match statement of the &lt;EM&gt;modeSelector&lt;/EM&gt;.&lt;/P&gt;&lt;P&gt;It is not very scalable, especially when I move into 10-20 different elements.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any way to, let's say, just raise a corresponding flag in Match statement, define all the IF boxes with those flags and then just give command to redraw them?&lt;/P&gt;&lt;P&gt;Something like this, where redrawIfBoxes is an expression that redraws all the IF boxes so that changed flag takes effect:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

modeSelectorOptions = {"Mode1", "Mode2"};
mode1Flag = 1;
mode2Flag = 0;
gui = V List Box(
	modeSelector = ComboBox(modeSelectorOptions, 
		&amp;lt;&amp;lt; Set Function(
			Function(
				{this}, 
				Match(this &amp;lt;&amp;lt; Get Selected(),
				modeSelectorOptions[1], Write("\!nMode1");mode1Flag = 1;mode2Flag = 0;redrawIfBoxes,
				modeSelectorOptions[2],	Write("\!nMode2");mode1Flag = 0;mode2Flag = 1;redrawIfBoxes,
				)
			)
		);
	),
	Button Box("All Modes", Write("Always active")),
	IB1 = If Box(mode1Flag, Button Box("GUI ELEMENT for Mode1", Write("Button pressed"))), 
	IB2 = If Box(mode2Flag, Button Box("GUI ELEMENT for Mode2", Write("Button pressed")))
	
);

NW = New Window("Test",&amp;lt;&amp;lt; Show Toolbars(0),&amp;lt;&amp;lt;ShowMenu(0), gui);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Dec 2024 23:03:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-hide-unhide-GUI-elements-effectively/m-p/824762#M100448</guid>
      <dc:creator>miguello</dc:creator>
      <dc:date>2024-12-20T23:03:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to hide\unhide GUI elements effectively?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-hide-unhide-GUI-elements-effectively/m-p/824772#M100449</link>
      <description>&lt;P&gt;For now I have it done this way:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

modeSelectorOptions = {"Mode1", "Mode2"};
mode1Flag = 1;
mode2Flag = 0;
mode1IfBoxes = {IB1, IB3, IB5};
mode2IfBoxes = {IB2, IB4, IB6};
gui = V List Box(
	modeSelector = ComboBox(modeSelectorOptions, 
		&amp;lt;&amp;lt; Set Function(
			Function(
				{this}, 
				Match(this &amp;lt;&amp;lt; Get Selected(),
				modeSelectorOptions[1], Write("\!nMode1");mode1Flag = 1;mode2Flag = 0;redrawIfBoxes,
				modeSelectorOptions[2],	Write("\!nMode2");mode1Flag = 0;mode2Flag = 1;redrawIfBoxes,
				)
			)
		);
	),
	Button Box("All Modes", Write("Always active")),
	IB1 = If Box(mode1Flag, Button Box("GUI ELEMENT for Mode1", Write("Button pressed"))), 
	IB2 = If Box(mode2Flag, Button Box("GUI ELEMENT for Mode2", Write("Button pressed"))),
	IB3 = If Box(mode1Flag, Button Box("GUI ELEMENT for Mode1", Write("Button pressed"))), 
	IB4 = If Box(mode2Flag, Button Box("GUI ELEMENT for Mode2", Write("Button pressed"))),
	IB5 = If Box(mode1Flag, Button Box("GUI ELEMENT for Mode1", Write("Button pressed"))), 
	IB6 = If Box(mode2Flag, Button Box("GUI ELEMENT for Mode2", Write("Button pressed")))
	
);
redrawIfBoxes = Expr(
	mode1IfBoxes &amp;lt;&amp;lt; Set (mode1Flag);
	mode2IfBoxes &amp;lt;&amp;lt; Set (mode2Flag);
);

NW = New Window("Test",&amp;lt;&amp;lt; Show Toolbars(0),&amp;lt;&amp;lt;ShowMenu(0), gui);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Let me know if there is a more robust way.&lt;BR /&gt;With more modes redrawIfBoxes can be changed from Expression to Function to match list of IfBoxes to a specific flag without ever needing to update the function.&lt;/P&gt;&lt;P&gt;The only two places to update - lists of If Boxes and Match statement in selector combobox.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Dec 2024 23:57:20 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-hide-unhide-GUI-elements-effectively/m-p/824772#M100449</guid>
      <dc:creator>miguello</dc:creator>
      <dc:date>2024-12-20T23:57:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to hide\unhide GUI elements effectively?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-hide-unhide-GUI-elements-effectively/m-p/824799#M100455</link>
      <description>&lt;P&gt;Depends on your final application and what you consider "robust" and easy to manage, but there are different options:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;You could use if boxes
&lt;UL&gt;
&lt;LI&gt;XPath might be helpful&lt;/LI&gt;
&lt;LI&gt;You could also just wrap your buttons inside some container, so you would only need one if box per mode&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;You could use &amp;lt;&amp;lt; Visibility("Collapse")&lt;/LI&gt;
&lt;LI&gt;You could update button text/actions dynamically when changes happen&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not necessarily they way I would do it, but this is just here to give some potential ideas&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

mode_options = {"Mode1", "Mode2"};

gui = V List Box(
	modeSelector = ComboBox(modeSelectorOptions, 
		&amp;lt;&amp;lt; Set Function(Function({this},
			this &amp;lt;&amp;lt; Inval;
			selection = Contains(mode_options, this &amp;lt;&amp;lt; Get Selected);
			ibs &amp;lt;&amp;lt; Set(0);
			ibs[selection] &amp;lt;&amp;lt; Set(1);
			this &amp;lt;&amp;lt; Update Window;
		));
	),
	Button Box("All Modes", Write("Always active")),
	If Box(0, 
		V List Box(
			Button Box("GUI ELEMENT for Mode1", Write("Button pressed")),
			Button Box("GUI ELEMENT for Mode1", Write("Button pressed")),
			Button Box("GUI ELEMENT for Mode1", Write("Button pressed"))
		)
	),
	If Box(0, 
		V List Box(
			Button Box("GUI ELEMENT for Mode2", Write("Button pressed")),
			Button Box("GUI ELEMENT for Mode2", Write("Button pressed")),
			Button Box("GUI ELEMENT for Mode2", Write("Button pressed"))
		)
	)
);

ibs = gui &amp;lt;&amp;lt; Xpath("//IfBox");

// JMP things
modeSelector &amp;lt;&amp;lt; Set(2, Run Script(0));
modeSelector &amp;lt;&amp;lt; Set(1, Run Script(1));

nw = New Window("Test",&amp;lt;&amp;lt; Show Toolbars(0),&amp;lt;&amp;lt;ShowMenu(0), gui);

Write();&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 21 Dec 2024 06:13:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-hide-unhide-GUI-elements-effectively/m-p/824799#M100455</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-12-21T06:13:44Z</dc:date>
    </item>
  </channel>
</rss>

