Hi Cris,
You are right. The examples you provide are a bit hacky. The standard way in Roassal is to use composite shapes.
Try this: -=-=-=-=-=-=-=-=-=-=-=-= v := RTView new.
boxShape := RTBox new color: Color veryLightGray. labelShape := RTLabel new text: #name. composite := RTCompositeShape new. composite add: boxShape. composite add: labelShape. composite allOfSameSizeWithPadding.
elements := composite elementsOn: (Collection withAllSubclasses copyFrom: 1 to: 5). v addAll: elements.
elements when: TRMouseClick do: [ :evt | evt element model: Collection withAllSubclasses atRandom. evt element update. RTGridLayout on: elements. ].
RTGridLayout on: elements. v -=-=-=-=-=-=-=-=-=-=-=-=
The code I provide defines a callback that changes the label. You can see how to adapt it.
Let us know how it goes.
Cheers, Alexandre
On Sep 15, 2016, at 12:10 PM, Cris Fuhrman fuhrmanator@gmail.com wrote:
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 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.png>
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.png>
I'd love to get some feedback on these approaches. Maybe there's a simpler robust way? Thanks! _______________________________________________ Moose-dev mailing list Moose-dev@list.inf.unibe.ch https://www.list.inf.unibe.ch/listinfo/moose-dev