Roassal3 icon indicating copy to clipboard operation
Roassal3 copied to clipboard

Padding between the window border and inner figures (zoomToFit)

Open hernanmd opened this issue 4 years ago • 3 comments

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: Screen_Shot_2021-09-21_at_11 12 02_PM

But a precise fit would produce:

Screen_Shot_2021-09-21_at_11 12 56_PM

hernanmd avatar Sep 22 '21 17:09 hernanmd

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

akevalion avatar Sep 23 '21 13:09 akevalion

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 avatar Sep 26 '21 20:09 hernanmd

@hernanmd is this issue still valid? let me know if I can help you

akevalion avatar May 04 '22 07:05 akevalion

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.
image

akevalion avatar Oct 14 '22 11:10 akevalion