| Summary: | [Table] Trimmings calculations incorrect for RAP | ||
|---|---|---|---|
| Product: | [RT] RAP | Reporter: | John Gymer <jgymer> |
| Component: | RWT | Assignee: | Project Inbox <rap-inbox> |
| Status: | RESOLVED FIXED | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | ||
| Version: | 2.0 | ||
| Target Milestone: | 2.1 M1 | ||
| Hardware: | PC | ||
| OS: | Windows 7 | ||
| Whiteboard: | |||
Currently, Scrollable#computeTrim uses getVScrollBarWidth/getHScrollBarHeight to respect the scrollbars size. These methods check if scrollbar is visible or not in order to return the scrollbar size or 0. In your snippet, when you call computeTrim the horizontal scrollbar is not visible and it's size is not taken into the calculation. Later, when you add a table collumn, the horizontal scrollbar is visible and computeTrim respects it's size. Probably moving the table size code calculation after the creation of the table column will fix the problem. But this could be consider as a workaround. I've checked in SWT and Scrollable#computeTrim always add scrollbars size if they are not null regardless their visibility. Hi Ivan, Absolutely correct - moving the Add Column logic above the calc adjust logic works perfectly. This is ok for an isolated example like this, but unfortunately I may not be able to employ this workaround in some of my runtime code where column information is not available until much later, or where column layout changes throughout the life of the table. I suppose I should be able to recalc ecah time the layout changes though. One interesting behaviour is that the calc is still correct with the add column logic above the calc adjust logic, even if the columns are narrower than the table width i.e. columns fit on without needing an hscroll bar. Surprised me, but perhaps I can use that fact to my advantage. I'll use the workaround in the meantime, but will still appreciate the RAP logic being brought in-line with SWT at some point. Many thanks, John Fixed in master with commit 40632ef71e681e658a9b3d7b19fed671eb37454e. Now Scrollable#computeTrim always add scrollbars size if they are not null regardless their visibility. |
The size of a RAP Table appears to be calculated incorrectly - all RAP Tables appear to be 10 pixels too tall, which happens to also be the height of the horizontal scroll bar in the default theme. Using RAP 2.0 M4 with some Nightlies, but don't think this has changed for a while. Example snippet below, but here's a summary... let's say I want a Table whose overall size is 200x200, so I use table.ComputeTrim(0,0,200,200) to work out what actual size I'll end up with. Under RAP with default theme I'm getting 212x202, so I adjust the size I request with my FormData object i.e. 188x198. However, on doing this the overall size always ends up 10 pixels too tall, as if it is not talking into account the height of the hscrollbar. Whether the hscrollbar exists or not is irrelevant - it still appears to use its height in the calculation somehow. Here's an example, which happens to have a header and hscrollbar, but these can be removed and the effect is the same... package bug.snippet; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.layout.FormData; import org.eclipse.swt.layout.FormLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.ScrollBar; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; public class Bugsy { private static Display display; private static Shell shell; private static Table tab; private static Button but; private static TableColumn col; public static void main(String args[]) { System.out.println("BugSnippy Starting..."); // create Shell1 display = new Display(); shell = new Shell(display, SWT.TITLE|SWT.MAX|SWT.MIN|SWT.RESIZE|SWT.CLOSE); shell.setText("Shell"); shell.setSize(300, 300); shell.setLocation(20, 20); shell.setBackground(new Color(null, new RGB(255,128,128))); FormLayout layout = new FormLayout(); shell.setLayout(layout); //create the table tab = new Table(shell, SWT.FULL_SELECTION|SWT.BORDER); tab.setHeaderVisible(true); tab.setLinesVisible(true); int myTableHeight = 200; int myTableWidth = 200; System.out.println("Desired overall table size = " + myTableWidth + " x " + myTableHeight); Rectangle trimRect = tab.computeTrim(0, 0, myTableWidth, myTableHeight); System.out.println("TrimRect if I simlpy used that size = " + trimRect.width + " x " + trimRect.height); myTableWidth -= trimRect.width - myTableWidth; myTableHeight -= trimRect.height - myTableHeight; System.out.println("Size needs to be (adjusted by trim minus desired) = " + myTableWidth + " x " + myTableHeight); col = new TableColumn(tab, SWT.NONE); col.setResizable(true); col.setWidth(500); col.setText("My Column"); ScrollBar hScrollBar = tab.getHorizontalBar(); //set table's position FormData fd = new FormData(); fd.left = new FormAttachment(0, 5); fd.top = new FormAttachment(0, 5); fd.width = myTableWidth; fd.height = myTableHeight; tab.setLayoutData(fd); // add a button just below the lower edge of where the table should end but = new Button(shell, SWT.BORDER|SWT.PUSH); but.setText("Below Table Button"); fd = new FormData(); fd.left = new FormAttachment(0, 5); fd.top = new FormAttachment(0, 205); fd.width = 200; fd.height = 24; but.setLayoutData(fd); shell.open(); System.out.println("Actual Table size = " + tab.getSize().x + " x " + tab.getSize().y); if (hScrollBar != null) { System.out.println("HScrollBar height = " + hScrollBar.getSize().y); } while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); System.out.println("BugSnippy Done!"); } } This technique to adjust the Table size based on ComputeTrim() works perfectly under SWT - I get my Button placed immediately below the bottom edge of the Table, but under RAP the Table covers the top 10 pixels of the Button. RAP EntryPoint is a simple one like this: package bug.snippet; import org.eclipse.rap.rwt.application.EntryPoint; public class RAPEntryPoint_BugSnip implements EntryPoint { @Override public int createUI() { System.out.println("Starting RAP"); Bugsy.main(null); System.out.println("RAP Done"); return(0); } }