5

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

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

初始状态

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

初始期望状态

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

调整所需状态的大小

这是我尝试过的代码:

| 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

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

4

2 回答 2

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
于 2013-01-29T11:04:39.540 回答
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。

于 2013-01-24T20:27:47.173 回答