eclipse-platform / eclipse.platform.swt

Eclipse SWT
https://www.eclipse.org/swt/
Eclipse Public License 2.0
118 stars 137 forks source link

Support `SWT.VIRTUAL` for `Composite` #624

Open SyntevoAlex opened 1 year ago

SyntevoAlex commented 1 year ago

In SWT, Composite is very often used as layout container - that is, the user's needs typically are

However, the actual OS control is not needed:

There is a number of downsides of actually creating a control:

There are more exotic issues as well:

The suggestion is to implement something like SWT.VIRTUAL style for Composite, where

According to my idea, SWT users will use SWT.VIRTUAL manually in each place where they're good with "thin layout container" behavior.

tmssngr commented 1 year ago

I already have tried to reduce the level of nesting a little bit and created nestable layouts. However, recently I've discovered a problem that still is on my todo-list to be fixed: radio buttons that are inside the same composite with other controls, e.g. checkboxes, magically are moved to the end of the tab list. This can be reproduced in SmartGit's preferences dialog, pages "Commands", "User interface" or - even worse - "Standard window" (which contains 2 radio button groups).

vogella commented 1 year ago

Such a feature would be awesome @SyntevoAlex

I have a client who uses tons of Composites just for layouting his widgets and as this client has tons of widgets he runs into no more handlers exceptions. Having a Composite without an underlying widget only for layouting would be great.

laeubi commented 1 year ago

If composites are only created for Layout purpose, then this could maybe easier handled by a layout manager, I'm already working on another layout manager at the moment (not finished yet) but found that this is often a better approach as the "classic" SWT LayoutMangers are often hard to use. If you want to switch visibility for multiple items at once, maybe an ControlGroup class would be more suitable, where one can not only switch visibility, but maybe even enablement of multiple items at once and can add/remove items, e.g.

ControlGroup group = new ControlGroup(control1, control2, control3, ...);
group.setVisible(false);

But without an example what layout / managing requirements are there is a bit hard to guess, using Composite for that seem to me very risky as it has many tasks (e.g. what should be happen for listeners? Parent relative computations) and so on...

tmssngr commented 1 year ago

I already have tried to reduce the level of nesting a little bit and created nestable layouts. However, recently I've discovered a problem that still is on my todo-list to be fixed: radio buttons that are inside the same composite with other controls, e.g. checkboxes, magically are moved to the end of the tab list. This can be reproduced in SmartGit's preferences dialog, pages "Commands", "User interface" or - even worse - "Standard window" (which contains 2 radio button groups).

See https://github.com/eclipse-platform/eclipse.platform.swt/issues/634

SyntevoAlex commented 1 year ago

I see that both @laeubi and @tmssngr prefer Layout approach instead of virtual Composite.

I understand and agree that implementing it in Composite may have some bugs. Still, I think that it's an approach that allows to adjust old code much more easily. Where it fails, code could be left as is or switched to Layout approach.

Either way, I was instructed to not spend time developing the Composite approach.