I am trying to create a framework for visualizing data -- this leads me to create a template with several buttons that can act on the data that was passed into the template.
However, I am running into an issue with scoping where creating a button with a function to call -- calling this function happens in a different scope than where I would have thought based on the location of the button in the code.
I've provided a minimum working example below -- I would expect that when each button is clicked the resulting function call would happen within the original defining scope.
Is there a way to accomplish this?
Thanks!
Names Default To Here ( 1 );
insert_text = Function({tb, msg}, {Default Local},
tb << Add ( "Added", msg )
);
tab_function = Function({msg}, {Default Local},
Tab Box (
"one",
tb1 = Tab Box();
V List Box(
b = Button Box ( "Add", insert_text(tb1, msg))
);,
"two",
tb2 = Tab Box();
V List Box(
b = Button Box ( "Add", insert_text(tb2, msg))
);,
"three",
tb3 = Tab Box();
V List Box(
b = Button Box ( "Add", insert_text(tb3, msg))
);
)
);
New Window(
"Test Window",
tab_function("hi");
)