【问题标题】:Spec - horizontal panel with progress bar taking all the space in the middleSpec - 带有进度条的水平面板占据了中间的所有空间
【发布时间】:2022-01-03 14:18:55
【问题描述】:

我想创建一行三个元素,一个标签、一个进度条和一个第二个标签。为此,我使用了以下代码:

(SpBoxLayout newLeftToRight
    spacing: 15;
    add: secondsPassed expand: false;
    add: progressBar withConstraints: [ :constraints | 
        constraints
            height: 10;
            fill: false;
            width: 280 ];
    add: timeRemaining expand: false;
    yourself)

我已经明确设置了宽度限制,但我想做的是让它占据两个标签之间的所有空间,无论行有多宽。
这样它的宽度是灵活的,两个标签是固定的。

【问题讨论】:

    标签: smalltalk pharo


    【解决方案1】:

    基本上,第一个和第三个设置为expand: false,第二个设置为expand: true(这是默认设置)。 对于你想要的,这应该足够了:

    (SpBoxLayout newLeftToRight
        spacing: 15;
        add: secondsPassed expand: false;
        add: progressBar;
        add: timeRemaining expand: false;
        yourself)
    

    如果您删除了应该允许它扩展的宽度约束,因为大小不再固定。另外,考虑到在当前的SpBoxLayout 实现中,宽度和高度不能共存,因为它们适用于不同的布局类型:

    • width 适用于水平(leftToRight)布局
    • height 适用于垂直 (topToBottom) 布局。

    假设你已经安装了 Gtk 后端,这段代码:

    presenter := SpPresenter new.
    presenter application: (SpApplication new useBackend: #Gtk).
    
    presenter layout: (SpBoxLayout newLeftToRight 
        vAlignStart;
        borderWidth: 15;
        spacing: 15;
        add: (presenter newLabel label: 'One') expand: false;
        add: (presenter newProgressBar fixedAt: 50 percent);
        add: (presenter newLabel label: 'Two') expand: false;
        yourself).
        
    presenter openWithSpec title: 'Example of Horizontal Layout'
    

    将产生这个输出:

    【讨论】:

    • 你可以接受你自己的问题:0)。干得好。
    猜你喜欢
    • 2020-11-07
    • 1970-01-01
    • 2017-04-16
    • 1970-01-01
    • 1970-01-01
    • 2014-07-18
    • 2022-01-21
    • 1970-01-01
    • 2011-11-03
    相关资源
    最近更新 更多