Viewport, large scrollable area and resize question

Hello,

I have a large “canvas” Component derived object that is viewed through a “container” Viewport derived component:

container::container()
{
  setViewedComponent( new canvas(), true);
}

The background of the canvas component is a tiled image that fills up the “infinite” (just really big) space…

canvas::canvas()
{
  setSize(80000,80000);
}
...
canvas::paint(Graphics& g)
{
  g.setTiledImageFill(grid, 0, 0, 0.5f);
  g.fillAll();
}

My viewport is constructed in Main.cpp constructor as

setConentOwned(new container(), true);

The Problem I am having is when I resize the Application window the canvas doesn’t seem to be receiving any news about this change. What that looks like is no tiled background in the newly created area. Setting the bounds of the canvas in container’s resize() is not what I am looking for as that changes the “actual” size of the canvas. repaint() doesn’t force the update either.

Oddly enough, as soon as I drag the canvas around the background fills the available area.

I have followed the calls in Viewport to a setViewPosition call on drag position change but bumping that through on a resize doesn’t work either, as if canvas isn’t aware of the change in size/visibility yet

Does a setViewed component need to be owned by another component to get this to propagate?

Thanks for any advice!

In canvas::resized() set the ViewPort’s new size… and/or update the Viewed area:

/** Changes the position of the viewed component.

    The inner component will be moved so that the pixel at the top left of
    the viewport will be the pixel at the specified coordinates within the
    inner component.

    This will update the scrollbars and might cause a call to visibleAreaChanged().

    @see getViewPositionX, getViewPositionY, setViewPositionProportionately
*/
void setViewPosition (Point<int> newPosition);

Rail

Thanks for the response.

As I stated, the problem is that canvas is not getting resized. It maintains its extra-large, off-screen size. canvas::resized() is flat out not getting called and isn’t really supposed to be…

What I think I am looking for is how to tell the event listener that the object has moved even when it hasn’t (as the alternative alternative to resizing). Is there anyway to send a “moved” flag through that callback circuit?

A kind of hacky work around I have right now is moving the canvas and then moving it back:

container::resized()
{
  if (getViewedComponent() != nullptr) {
    juce::Point<int> p = getViewPosition();
    juce::Point<int> plus(1, 1);
    setViewPosition(p + plus);
    p = getViewPosition();
    juce::Point<int> minus(-1, -1);
    setViewPosition(p + minus);
  }
}

Is there any other way to “move a component without moving it”?

What happens if you don’t implement resized() at all in container?

Thanks reuk, that was what I was looking for. I was trying to figure out a way to call that private method updateVisibleArea() and all I had to do was get OUT of the way. Thanks!