Hello,
I'd like to visualize a graph where the nodes are boxes and they have text
inside. The boxes should grow or shrink horizontally so the text doesn't go
outside the box.
I saw the answer at
http://forum.world.st/Roassal2-Label-width-td4847887.html which led me to a
solution. However, I've commented the "not robust" part below, since
it's
passing by "lbl" which I suspect could change.
~~~~~~~~~~~~~~~~
| b label el |
b := RTView new.
el := RTBox new elementOn: 'hello world'.
label := RTLabeled new center.
b add: el.
el @ label.
"not robust"
el width: label lbl width.
el height: label lbl height.
b
~~~~~~~~~~~~~~~~~~~~~~
[image: Inline image 1]
I found the unit tests for RTLabel (RTLabelTest) and I found another
solution, but maybe it's equally fragile?
~~~~~~~~~~~~~~~~~~~~~~~~~
| text b lblBox lblForCalc dummyElement |
text := 'Text inside the box'.
b := RTView new.
lblBox := (RTBox new elementOn: text) + RTLabel.
lblForCalc := RTLabel new text: text.
dummyElement := RTElement new.
lblBox height: (lblForCalc heightFor: dummyElement).
lblBox width: (lblForCalc widthFor: dummyElement).
b add: lblBox.
b
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[image: Inline image 2]
I'd love to get some feedback on these approaches. Maybe there's a simpler
robust way? Thanks!