1

我正在尝试围绕一组形状绘制一个边界框。我得到了场景中的所有内容,但我不知道如何使边界框和文本正确对齐:

结果

    c := RSCanvas new.
    text := RSGroup new.
    foo := RSLabel new text: 'foo'.
    bar := RSLabel new text: 'bar'.
    text add: foo; add: bar.
    RSVerticalLineLayout on: text.
    bound := RSShapeFactory box
        model: self;
        border: (RSBorder new width: 1; color: Color black);
        cornerRadius: 5;
        width: text encompassingRectangle width + 15;
        height: text encompassingRectangle height + 10.
    all := RSComposite new shapes: { bound. text asShape }.
    c add: all.
    c  @ RSCanvasController.
    ^ c
4

2 回答 2

3

所以这就是我的做法。缺少的关键点是放置一个 RSLocation。

在此处输入图像描述

    c := RSCanvas new.
    text := RSGroup new.
    foo := RSLabel new text: 'foo'.
    bar := RSLabel new text: 'bar'.
    text add: foo; add: bar.
    RSVerticalLineLayout on: text.
    bound := RSShapeFactory box
        model: self;
        border: (RSBorder new width: 1; color: Color black);
        cornerRadius: 5;
        width: text encompassingRectangle width + 15;
        height: text encompassingRectangle height + 10.
    contents := text asShape.
    all := RSComposite new shapes: { bound. contents }.
    RSLocation new center; outer; stick: contents on: bound.
    c add: all.
    c  @ RSCanvasController.
    ^ c
于 2020-07-10T15:48:47.233 回答
2

这是另一个解决方案

在此处输入图像描述

text := 'Foo
bar'.
label := RSMultilineLabelBuilder new shapeFor: text.
box := RSBox new 
    fromRectangle: label encompassingRectangle;
    cornerRadius: 10;
    noPaint
    withBorder.
box extent: box extent + 15.
all := { box . label} asGroup asShape.

canvas := RSCanvas new.
canvas add: all.
canvas @ RSCanvasController 

也许将来我们可以为字符串添加一个扩展方法'hello world' asRoassalShape

于 2020-07-15T15:19:38.537 回答