Morphic:自动调整滚动窗格中包含的组框的大小?

时间:2013-01-24 13:50:19

标签: smalltalk pharo squeak morphic

使用Pharo 1.4夏季进行测试。我认为最好使用截图进行解释,代码如下。

这是我的初始状态(我现在用我的代码得到的):

Initial State

我希望组合框变形在打开时水平填充,如下所示:

Initial Desired State

调整大小后,我希望组框变形以保持边界,即:

Resize Desired State

这是我尝试过的代码:

| 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

容器必须是ScrollPane。

我已经修改了Bert的代码,不使用Polymorph UIBuilder,导致:

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

但也不起作用,因为内部蓝色变形重叠并且未填充指定的帧。我尝试了很多使用框架的组合但到目前为止没有任你知道我错过了吗?

2 个答案:

答案 0 :(得分:3)

使用UIBuilder,您无需手动创建滚动条。通过调整大小来检查以下脚本,直到自动显示垂直或水平滚动条。

| 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

答案 1 :(得分:2)

你错过了ProportionalLayout没有使用#spaceFill等所以要么使用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

或具有偏移的ProportionalLayout,这是您可以混合固定宽度和相对尺寸的方法:

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

我在没有UITheme的Squeak中试过这个,所以这是直接使用Morphs。