Как добавить ограничивающую рамку к составной фигуре в Roassal 3?
Я пытаюсь нарисовать ограничительную рамку вокруг группы фигур. Я получаю все в сцене, но не знаю, как правильно выровнять ограничивающую рамку и текст:
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
2 ответа
Решение
Вот как я это сделал. Недостающим ключевым моментом было размещение 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
Вот еще одно решение
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
.