Community
Participate
Working Groups
As outlined in bug 332887, some of the SWT snippets use incorrect positioning. I will provide patches that change the positioning to be more portable.
Created attachment 186657 [details] Corrects positioning of snippet 1 to 200 The majority of the changes set a Grid- or FillLayout on the main shell of the snippet
I see, the problem is: setting a layout and calling setLocation/setSize/setBounds is still not correct code (not setting a good example). For example, the first snippet 100: This part Shell shell = new Shell(display); shell.setBounds(10, 10, 200, 200); Text text = new Text(shell, SWT.MULTI); text.setBounds(10, 10, 150, 150); should be replaced by Shell shell = new Shell(display); shell.setBounds(10, 10, 200, 200); shell.setLayout(new GridLayout()); Text text = new Text(shell, SWT.MULTI); text.setLayoutData(new GridData(150, 150)); and that still change the behavior a bit (the 10, 10 location).
Sorry, this was not inteded. Of course, the calls to setBounds/setSize/setLocation must be replaced with appropriate calls to setLayoutData. If you can live with the remaining change in behavior (i.e. the 10, 10 location), I will rework the patch accordingly.
(In reply to comment #3) > Sorry, this was not inteded. Of course, the calls to > setBounds/setSize/setLocation must be replaced with appropriate calls to > setLayoutData. > If you can live with the remaining change in behavior (i.e. the 10, 10 > location), I will rework the patch accordingly. I'm not sure if this is an interesting change. But since you are doing the work and I will review it. Maybe is better (less change to the code and no change in the behaviour) to call: Rectangle clientArea = parent.getClientArea(); and add clientArea.x and clientArea.y to every x,y passed in for setLocation/setBounds method. What do you think ?
(In reply to comment #4) > [ ... ] > Maybe is better (less change to the code and no change in the behaviour) to > call: > Rectangle clientArea = parent.getClientArea(); > and add clientArea.x and clientArea.y to every x,y passed in for > setLocation/setBounds method. > > What do you think ? Admittedly, I started out with the getClientArea() approach on the first few snippets. Later on I went on to using layout managers as I thought that the snippets should also set a good example in terms of how to position widgets in SWT. However, as we started out to fix the positioning and not to 'improve' the snippets, I would favor the getClientArea() approach that you suggested. So, if you don't object, I will rework the patch to use getClientArea().
Sounds good to me.
Created attachment 187981 [details] Corrects the positioning of snippet 1 to 99 The patch corrects the positioning by adding the client area offset when setLocation/setBounds is called.
Patched released. Thank you very much for time.
Created attachment 188607 [details] Snippet 100 to 199: Corrects the positioning In the same way as the previous patch, this one corrects the positioning by adding the client area offset when setLocation/setBounds is called.
I just provided a patch for the next chunk: snippet 100 to 199
(In reply to comment #10) > I just provided a patch for the next chunk: snippet 100 to 199 Released, Thank you more to come ?
(In reply to comment #11) > [ ... ] > Released, Thank you > > more to come ? Thanks for accepting the changes. Yes, there is more to come (200 - max-snippet). I just thought smaller chunks were less scary ;) I will let you know when I attach the last patch.
Created attachment 188960 [details] Corrects the positioning of snippet 200 til end This should be the last patch. Again, it corrects the positioning by adding the client area offset when setLocation/setBounds is called.
Fixed in HEAD, Thank you again!