Morphic: auto-resize group box in scrollbar?

Testing over the years Pharo 1.4. I think it’s better to explain this using screenshots, the code below.

This is my initial state (what I am getting now with my code):

Initial state

I want the group field morph to be filled horizontally when opened, for example:

Initial desired state

And after resizing, I want group morphing to keep borders, i.e.:

Resize desired state

This is the code I tried:

| s morph1 morph2 row groupBox scroller |
s := ScrollPane new.
morph1 := BorderedMorph new.
morph2 := BorderedMorph new.
row := UITheme builder newRow: {morph1 . morph2}.
groupBox := UITheme builder newGroupbox: 'Group Box Test' for: row.
    groupBox 
        layoutFrame: (LayoutFrame fractions: (0 @ 0 corner: 1 @ 0.8));
        vResizing: #spaceFill;
        hResizing: #spaceFill;
        layoutChanged.
scroller := s scroller.
scroller 
    addMorph: (groupBox position: 0@0)
    fullFrame: (0 @ 0 corner: 0.8@0.5).
s scroller color: Color white.
s
 extent: 250@150;
 openCenteredInWorld

The container must be a ScrollPane.

I adapted the Bert code to not use the Polymorph UIBuilder, resulting in:

morph1 := Morph new.
morph2 := Morph new.
row := ScrollPane new.
row
    color: Color white; borderColor: Color gray; borderWidth: 1;
    layoutPolicy: ProportionalLayout new.
row scroller
    addMorph: morph1 fullFrame: (LayoutFrame fractions: (0@0 corner: 1@0) offsets: (5@5 corner: -60@45));
    addMorph: morph2 fullFrame: (LayoutFrame fractions: (1@0 corner: 1@0) offsets: (-50@5 corner: -5@45)).
row
    extent: 250@150;
    openInHand

but also does not work, because the inner blue morphs overlap and do not fill the specified frame. I tried many combinations using frames, but so far nothing has worked. Do you know what I am missing?

+5
source share
2 answers

Using UIBuilder, you do not need to manually create a scroller. Check the following script by resizing until vertical or horizontal scrollbars automatically appear.

| dialog morphList row morph1 morph2 morph3 morph4 |

morph1 := BorderedMorph new hResizing: #spaceFill.
morph2 := BorderedMorph new.
morph3 := BorderedMorph new.
morph4 := BorderedMorph new.
row := UITheme builder newRow: {morph1 . morph2 . morph3}.
morphList := UITheme builder 
    newMorphListFor: (ListModel new list: {row . morph4})
    list: #list 
    getSelected: #selectionIndex 
    setSelected: #selectionIndex:
    help: 'This is a morph list'.
dialog := UITheme builder newWindowFor: nil title: 'titleString'.
dialog addMorph: morphList fullFrame: (LayoutFrame fractions: (0@0 corner: 1@0.5)).
dialog openInWorld
+3
source

You are missing the fact that ProportionalLayout does not use #spaceFill, etc. So either use TableLayout:

morph1 := Morph new hResizing: #spaceFill.
morph2 := Morph new.
row := Morph new
    color: Color white; borderColor: Color gray; borderWidth: 1;
    layoutPolicy: TableLayout new;
    layoutInset: 5; cellInset: 5;
    listDirection: #leftToRight;
    addAllMorphs: {morph1. morph2};
    extent: 250@150;
    openInHand

or ProportionalLayout with offsets, which allows you to combine a fixed width and relative dimensions:

morph1 := Morph new.
morph2 := Morph new.
row := Morph new
    color: Color white; borderColor: Color gray; borderWidth: 1;
    layoutPolicy: ProportionalLayout new;
    addMorph: morph1 fullFrame: (LayoutFrame fractions: (0@0 corner: 1@0) offsets: (5@5 corner: -60@45));
    addMorph: morph2 fullFrame: (LayoutFrame fractions: (1@0 corner: 1@0) offsets: (-50@5 corner: -5@45));
    extent: 250@150;
    openInHand

I tried this on Squeak, which does not have a UITheme, so it uses Morphs directly.

+2
source

All Articles