How to remove/hide a layout?

Hi everybody !

How can I remove (or hide) a layout inside a layout ?

for example I have:

(
~win = Window(\test, 200@200);
~win.layout = VLayout(
    * 5.collect{ arg i; HLayout(
        TextField.new.string_( i + "azertyopqsdfghlmwcxvbn ".scramble) ,
        Button.new.maxWidth_(30).states_([[\X]])
        .action_({
            // how to remove my HLayout parent ?
        });
    ) }
);
~win.front;
)

I can access the HLayout elements with ~win.layout.children[x] but I can’t find the solution to update the win.layout without one of its children.

(It off element was in a view, it won’t be a problem because we can close a window, but layout are much more flexible)

Thanks for your help

As I understand it, manipulating the layout’s children directly isn’t really supported (which would explain why you didn’t find a way).

I think I’d recommend:

  • Try placing Views directly into the VLayout, instead of HLayouts.
  • Then each View has an HLayout as its layout.

At that point, you can delete one of the VLayout’s members by calling .remove on the View object. That is, you can’t tell the HLayout to go away – but if the HLayout is in its own View, you can tell the View to go away.

I think views can also be made invisible (.visible_(boolean) I think? I didn’t look it up, maybe that’s wrong), but they probably still take up space even when hidden.

hjh

James is right… Layouts ONLY control the positioning of an object - they are not in any way a part of the hierarchy of a view. You can’t remove a Layout, because it doesn’t really belong to anything (at least, in the same way a View does). The solution is to simply attach your layout to a view, and remove that:

(
~win = Window(\test, 200@200);
~win.layout = VLayout(
	* 5.collect{ 
		arg i; 
		var view;
		view = View().layout_(HLayout(
			TextField.new.string_( i + "azertyopqsdfghlmwcxvbn ".scramble),
			Button.new
				.maxWidth_(30)
				.states_([[\X]])
				.action_({
					view.remove();
				})
		));
	}
);
~win.front;
)

Thanks a lot guys @jamshark70 and @scztt it works perfectly !