Search code examples
rascal

Problems with layouting boxes in Rascal


I have big problems with layouting dynamic generated Figures with figures in figures.

I expect the following:

  • If I specifiy size() for a figure the figure will never get smaller. This is in the contract of size property.
  • if I do pack it will rearrange the figures without making them smaller than specified size(). It will 'rearrange and draw a box arround it' (in terms that it is a new figure)
  • If the whole figure cannot be displayed in the Eclipse window I get automatically (outer)scrollbars.

So if I execute this:

public void tester() { 
  list[Figure] list1 = []; 
   for ( i <- [0..3]) { 
      list[Figure] list2 = [];  
      list2 = list2 + box(size(30,200),fillColor("brown"));
      list2 = list2 + box(size(50,610),fillColor("black"));
      list2 = list2 + box(size(100,310),fillColor("gray"));
      list1 = list1 + pack(list2,gap(10),fillColor("red"));
   };
   render(pack(list1,gap(10),fillColor("blue")));
}

I expect something like this (or layout vertically I do not care), and if there is not enough room I expect scrollbars under and right of the figure:

This is what I expect

However what I get is the following. But this is not what I asked for. I did not ask for individual scrollbars (I want outer scrollbars if needed). Also the blue and red border (because of gap) is not visible.

How do I get this more in line with what I expected, and why is it behaving as it is?

What I get


Solution

  • The critical issue seems to be that a size specification is missing in the inner pack. If you rewrite your code as follows things look much better:

    public void tester() { 
      list[Figure] list1 = []; 
      for ( i <- [0..3]) { 
        list[Figure] list2 = [];  
        list2 = list2 + box(size(30,200),fillColor("brown"));
        list2 = list2 + box(size(50,610),fillColor("black"));
        list2 = list2 + box(size(100,310),fillColor("gray"));
        list1 = list1 + pack(list2,gap(10),size(200,500),fillColor("red"));
     };
     render(pack(list1,gap(10),fillColor("blue")));
    }
    

    The resulting figure is as follows (note that all packs have a scrollbar and the right one has been scrolled down a bit):

    enter image description here

    As a side note: the current handling of sizes and resizing is really confusing and we are working on a better solution.