03-14-2018 10:38 AM
I have a number of buttons, which are made visible or invisible at runtime. I'd like the visible buttons to be evenly distributed. Is there a simple way to programmatically achieve the same results as using the "Distribute Objects" items in the menu bar? Maybe by passing in an array of references to a function?
I know I can accomplish this with property nodes and a little bit of math, but I wanted to see if something already exists.
03-14-2018 11:16 AM
You might check the LabVIEW Tools Network. I did look in OpenG, and didn't find it, but there are others ...
Otherwise, it's Property Nodes and A Bit of Math.
Bob Schor
03-14-2018 04:34 PM
Any time I need to have a bunch of buttons in a grid on the UI I think of using arrays of buttons. There are limitations that need to be worked around, like how array elements can only vary by their value and not properties, but it is more manageable and scaleable.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
03-14-2018 09:34 PM
@buttersworth wrote:
I have a number of buttons, which are made visible or invisible at runtime. I'd like the visible buttons to be evenly distributed. Is there a simple way to programmatically achieve the same results as using the "Distribute Objects" items in the menu bar? Maybe by passing in an array of references to a function?
I know I can accomplish this with property nodes and a little bit of math, but I wanted to see if something already exists.
The "Distribute Objects" method only works on a VI that is in edit mode; it won't work on a running VI.
03-15-2018 04:52 AM
It's good to check for a canned solution. Even better to take a shot at coding it.
Start by placing all of the buttons at the same location (to make life easier).
(Set all Left and Top Position values to the desired location for the Upper Left button.)
Then loop through the references adding a Column offset (Left) or a Row offset (Top) after setting each button.
You will need to use shift registers to keep your current Left and Top values.
I find it easier to use two nested For Loops (Outer for Rows, Inner for Columns - with "moves" only in the Inner loop).
steve
03-15-2018 08:53 AM
@stevem181:
I like your method, and if I were the Original Poster, I would mark it as "The Solution) (hint to Original Poster -- read this sentence!). It is simple, elegant, flexible -- "Who could ask for anything more?" (as the Song Says).
Bob Schor
03-15-2018 09:13 AM
Thanks for the suggestions everybody. For my application, I always want the buttons spread out over the same area (ie the space between them changes depending on how many are visible). And I did want the buttons to have different properties. So it ended up just being a little bit of math and property nodes. Maybe if I find myself with some free time I'll make a library to share that mimics the Distribute Objects tool.