Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 400339 - Button is clipped to the right
Summary: Button is clipped to the right
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.3   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.3 M6   Edit
Assignee: Silenio Quarti CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 340067
  Show dependency tree
 
Reported: 2013-02-08 11:58 EST by Anatoly Spektor CLA
Modified: 2013-05-24 09:26 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Anatoly Spektor CLA 2013-02-08 11:58:37 EST
Here is the snippet that helps reproducing the bug:

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;


public class button_test {

	  public static void main(String[] args) {
		    Display display = new Display();
		    Shell shell = new Shell(display);
		    shell.setSize(200, 200);
		    shell.setText("Dialogs");
		    shell.open();

		    final Button opener = new Button(shell, SWT.PUSH);
		    opener.setText("Click Me");
		    opener.setBounds(20, 20, 50, 25);

		   
		    while (!shell.isDisposed()) {
		      if (!display.readAndDispatch())
		        display.sleep();
		    }
		    display.dispose();
		  }
}

Try running it in GTK2 and GTK3 and you will see that in GTK3 button is clipped to the right.


I think this could be connected with calculation of the default (maybe minimal) button sizing. 

I would be glad if someone could take a look at this issue.
Comment 1 Anatoly Spektor CLA 2013-02-18 17:15:25 EST
Update:

If you take a look at the snippet I have provided there is one more issues: Button is clipped at the bottom as well.

Here is update to the snippet that shows this problem more clearly:

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
public class button_test {

	  public static void main(String[] args) {
		    Display display = new Display();
		    Shell shell = new Shell(display);
		    shell.setSize(200, 200);
		    shell.setText("Button Clipped");
		    shell.open();

		    final Button opener = new Button(shell, SWT.TOGGLE);
		    opener.setBounds(30, 30, 50, 25);

		   
		    while (!shell.isDisposed()) {
		      if (!display.readAndDispatch())
		        display.sleep();
		    }
		    display.dispose();
		  }
}


This issue arises because of difference in default size calculation of button and GtkLabel in GTK2 and GTK3.
To solve this problem I have used CSS provider to set button default properties to zero thus button is properly shown. (works for SWT.PUSH as well as for SWT.TOGGLE).

  Here is the patch I propose :

http://fedorapeople.org/cgit/aspektor/public_git/eclipse.platform.swt.git/commit/?h=add_css

(this patch does not solve clipping-to-the-right issue but it is definitely a step forward in solving clipping issues as it solved button height clipping issue)
Comment 2 Alexander Kurtakov CLA 2013-02-21 16:29:20 EST
Pushed as it affects GTK 3 only. Thanks for the patch. Fixing one thing is still better than both being broken.
Comment 3 Anatoly Spektor CLA 2013-02-25 12:25:47 EST
(In reply to comment #1)
> Update:
> 
> If you take a look at the snippet I have provided there is one more issues:
> Button is clipped at the bottom as well.
> 
> Here is update to the snippet that shows this problem more clearly:
> 
> import org.eclipse.swt.*;
> import org.eclipse.swt.widgets.*;
> public class button_test {
> 
> 	  public static void main(String[] args) {
> 		    Display display = new Display();
> 		    Shell shell = new Shell(display);
> 		    shell.setSize(200, 200);
> 		    shell.setText("Button Clipped");
> 		    shell.open();
> 
> 		    final Button opener = new Button(shell, SWT.TOGGLE);
> 		    opener.setBounds(30, 30, 50, 25);
> 
> 		   
> 		    while (!shell.isDisposed()) {
> 		      if (!display.readAndDispatch())
> 		        display.sleep();
> 		    }
> 		    display.dispose();
> 		  }
> }
> 
> 
> This issue arises because of difference in default size calculation of
> button and GtkLabel in GTK2 and GTK3.
> To solve this problem I have used CSS provider to set button default
> properties to zero thus button is properly shown. (works for SWT.PUSH as
> well as for SWT.TOGGLE).
> 
>   Here is the patch I propose :
> 
> http://fedorapeople.org/cgit/aspektor/public_git/eclipse.platform.swt.git/
> commit/?h=add_css
> 
> (this patch does not solve clipping-to-the-right issue but it is definitely
> a step forward in solving clipping issues as it solved button height
> clipping issue)

The current patch has a problem, as it was pointed out by Aleksandr Kurtakov, it affects not only Button but also Toolitem, which probably should have different CSS style initialization. Also, as css_provider was added to SCREEN, it slowed down loading of ControlExample.

 What I have done to solve  issues stated above:

 1. Switched from adding css_provider to screen, to adding css_provider as a GtkStyleContex for widgets that require styling.

 2. Added helper function initButtonStyle(), where I have put all the implementation. It is done because css styling should be added in multiple places (SWT.PUSH and SWT.TOGGLE), and it looks cleaner if implementation is in separate method.
 
 As a result Toolitem is not affected, button height-clipping issue is resolved  and as style is not added to screen ControlExample loads with the same speed.

 Please find patch below:

http://fedorapeople.org/cgit/aspektor/public_git/eclipse.platform.swt.git/commit/?h=button_init_style
Comment 4 Silenio Quarti CLA 2013-03-20 10:41:02 EDT
Fixed 

http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=84c0976432fbbed8dec67966f85ffe2e213c592a

This is happening because the SWTFixed was always setting the preferred size to its children.  The function gtk_widget_get_preferred_size() behaves different than gtk_widget_get_child_requisition() in that it does not return the size set with gtk_widget_set_size_request().  This is how Control.resizeHandle() forces the size of the handle to match the fixedHandle (in GTK2).  The fix emulates this behavior with non-deprecated API.