Hello,
I started to see how an implementation of a legend can be provided in Roassal 2.
I added this methods in TRCanvas>>addLegend:..
addLegend: aDictionary
| startPos interNodeWidth|
interNodeWidth := 30.
fixedShapes isEmpty ifTrue: [ startPos := self topLeft + (10@20) ] ifFalse: [startPos := self topLeft + (10@40)].
aDictionary associationsDo:
[ :association |
|shape|
self
addFixedShape:
(TRBoxShape new
size: 10;
translateTo: startPos;
color: association value).
shape := (TRLabelShape new
text: association key;
fontSize: 10).
shape translateTo: (shape width /2) + startPos x + 10 @ startPos y.
self
addFixedShape: shape.
startPos := startPos x + shape width + interNodeWidth @ startPos y ].
Usage example:
============================================
| v e1 e2 l |
v := RTView new.
e1 := (RTEllipse new size: 30; color: (Color blue alpha: 0.3)) element.
e2 := (RTEllipse new size: 30; color: (Color yellow alpha: 0.3)) element.
l := (RTLine new attachPoint: RTShorterDistanceAttachPoint new) edgeFrom: e1 to: e2.
e1 @ RTDraggable.
e2 @ RTDraggable.
v canvas addLegend: ({ 'Red' -> Color red. 'very very green' -> Color green.'blue' -> Color blue. 'Cyan' -> Color cyan. 'Cyan2' -> Color cyan}) asDictionary.
v addAll: (Array with: l with: e2 with: e1).
v open
=========================================
Questions for Roassal guys:
- Is TRCanvas the right place to add a legend? I started from here because it allows adding fixed shapes to the view.
- how do I tell the canvas not to draw where meta-items are drawn such as legend(s), menus, etc.
If this is correct, Leo might continue from here on and put this code in a class to add more customizations.
tx,
Usman