Roassal3
Roassal3 copied to clipboard
Padding between the window border and inner figures (zoomToFit)
Using Pharo 9.0 it seems #zoomToFit does not really zoom to fit inner figures to the window borders. Consider the following code:
| c |
c := RSCanvas new.
blueBox := RSBox new
size: 80;
color: #blue.
redBox := RSBox new
size: 80;
color: #red.
c
add: blueBox;
add: redBox.
blueBox translateBy: 40 @ 20.
c zoomToFit.
c open.
This produces the output:

But a precise fit would produce:

Hi Hernan, zoomToFit uses a the camera's zoomToFit, then you can use:
| c |
c := RSCanvas new.
blueBox := RSBox new
size: 80;
color: #blue.
redBox := RSBox new
size: 80;
color: #red.
c
add: blueBox;
add: redBox.
blueBox translateBy: 40 @ 20.
c when: RSExtentChangedEvent do: [
c camera zoomToFit: c extent.
c signalUpdate. ].
c open.
Use the event to always have the zoomToFit behavior, when the canvas changes its extent
Thanks Milton. I tried and it works for Roassal3 canvas, however it doesn't work when the canvas is inside a Spec2 window, like for example a subclass of SpRoassalPresenter. I will keep trying and let you know if I find something.
@hernanmd is this issue still valid? let me know if I can help you
I have test it with a presenter and it works for me
presenter := SpRoassalPresenter new.
blueBox := RSBox new
size: 80;
color: #blue.
redBox := RSBox new
size: 80;
color: #red.
presenter canvas
add: blueBox;
add: redBox.
blueBox translateBy: 40 @ 20.
presenter canvas when: RSExtentChangedEvent do: [ :evt |
evt camera zoomToFit: evt canvas extent.
evt signalUpdate. ].
presenter open.