Viewport scrollbar is not showing at the right place

here is how i add tabs to my TabComponent which inherits TabbedComponent and this is the only function in my class this class (and constructor)

void TabComponent::newTab(String tabName, Vector2i cellCount, Vector2i cellSize)
        // tabs is a vector of MyViewport 
	tabs.emplace_back(new MyViewport(cellCount, cellSize));
	std::size_t size = tabs.size() - 1;

	addTab(tabName, Colour(123, 123, 123), tabs[size], false, size);

this is my class where i inherit viewport.

class MyViewport : public Viewport
	MyViewport(Vector2i cellCount, Vector2i cellSize) : viewportContentComponent(cellCount, cellSize) 
                      	setViewedComponent(&viewportContentComponent, true);
	ViewportContentComponent viewportContentComponent;
here is my viewportContentComponent , it is used to be the content component of viewport and it also handles its own child components.

class ViewportContentComponent    : public Component
    ViewportContentComponent(Vector2i cellCount, Vector2i pCellSize) { /* init members, addAndMakeVisible */ }

    void resized() { /* positioning of textbuttons (cells vector) */ }

     std::vector<ScopedPointer<TextButton>> cells;
     Vector2i cellSize;

but when i run with that code, the horizontal scroller only appears when i move the vertical scroller to bottom
and vertical scroller only appears when i move the horizontal scroller to the right.

it looks like the viewport is bigger than the TabComponent ( my class that inherits TabbedComponent ), but i never done anything with its size as you can see in the code.

i tried logging the viewport width and height and it outputs 398x569 while its content component is 4000x4000 so with that output viewport isnt bigger than its content component

The docs for setViewedComponent say:

(Don’t add or remove any child components directly using the normal Component::addChildComponent() methods).

i.e. get rid of addAndMakeVisible.

Hope that helps

yea it works thanks ! you are right. didnt notice the addAndMakeVisible() calls addChildComponent() . thats sneaky ! thanks !

1 Like