How to set the scroll position in ui::ScrollView programmatically? - cocos2d-x

Say I have a scrollview whose contentSize is the size of the visible screen
Eg:
Content Size = 320 x 480
InnerContainer = 900 x 480
How can I set the scroll position programmatically ? For example, if there is an object at (400,100), how would I programmatically scroll the view so that the object is visible ?
There seems to be methods for setting the scroll bar position, but I don't think that actually scrolls the view.
I am using cocos2d-x v3.10

Use: setInnerContainerPosition()

Related

How come Window.innerWidth's value changed upon zooming in?

MDN seems to have contradicted itself. Here are a few statements made on the doc:
Definition of a layout viewport:
The area within the innerHeight and innerWidth is generally considered the layout viewport.
Properties of the layout viewport:
When the user pinch-zooms the page, pops open a dynamic keyboard, or when a previously hidden address bar becomes visible, the visual viewport shrinks but the layout viewport is unchanged.
Contradiction:
The viewport was originally 1200 x 800 (window.innerWidth; x window.innerHeight) pixels. Upon zooming in, the viewport became 800 x 533 pixels. This is the layout viewport.
So, they claimed the layout viewport's size cannot change upon zooming. Window.innerWidth is the width of the layout viewport. If Window.innerWidth is the width of the layout viewport, and the size of the layout viewport cannot change, how come Window.innerWidth's value changed upon zooming in?
Well, pinch-zoom on mobile is simply not the same as zooming on desktop. The zooming done via an pinch-gesture does not change the page layout. It performs the magnification effect on the page as is.

How to preserve the size of children movieclips in a fluid scrollPane in AS3?

I'm working on an AIR desktop project.
I have a scrollPane with a container assigned to it...
mainScrollPane.source = mainContainer;
The scrollPane is resized whenever the window is resized, in order to keep things fluid (it fits under a header container, and to the right of a left container)...
mainScrollPane.setSize(Math.round(stageWidth - leftContainer.width), Math.round(stageHeight - headerContainer.height));
mainScrollPane.source = mainContainer;
I'm dynamically creating movieclips and adding each one to the container...
mainContainer.addChild(boxMC);
In my library, boxMC is set to 400 pixels wide, yet I'm finding that each boxMC is displayed much wider than that.
When I resize the window, each boxMC doesn't scale in size (good).
I'm clearly not understanding the process for creating a fluid scrollPane that can be resized while having it's contents remain the size that I've created them at in the library. Can sometime please enlighten me?
Thank you.
The solution was not to give mainContainer width and height settings. So instead of mainContainer.graphics.drawRect(0,0,100,100); mainContainer.width = 500; mainContainer.height = 200; I just made it mainContainer.graphics.drawRect(0,0,100,100); then added movieclip don't scale their size when mainScrollPane is resized.

find out new image width height after browser window resize

i have an image and i have placed markers on it.
problem is that when the browser window resizes, the image size also changes and thus the marker comes to a different position than where it was before.
so, i want to find out the new positions and dimensions of the image after the browser window size changes.
I want to find out the new dimensions of the image, but nothing has worked till now.
i have used clientWidth , offsetWidth, naturalWidth and it all shows the same width before and after the window resize.
(I actually have a zoom property too and it shows the same width even after using zoom), so I am not sure what's wrong?
how do I find out the new image height width and positions after it is zoomed or after the browser window size is changed?
Trigger an event on window resize and find the image height
window.addEventListner("resize",function(){
var img = document.getElementById("img1");
console.log(img.clientWidth);
}

Resizing WKWebView height on zoom iOS

I have a table view where each cell contains a WKWebView of HTML content. Initially the content has its size to fit a prescribed width and height.
What I want to do is allow users to zoom in and out of the WKWebView and while adjusting the height of the cell view.
To give some context what I did was attach a Javascript (WKUserScript) to the WKWebView and in the script it contains
window.onload = function () {
window.webkit.messageHandlers.sizeNotification.postMessage({width:
document.body.scrollWidth, height: document.body.scrollHeight});
}
What this does is when the HTML content is loaded, it will send the message with name "sizeNotification" to a UIViewController conforming to the WKScriptMessageHandler. The message contains the scrollHeight which is what I use to set the frame of the WKWebView by adjusting a height constraint.
I also save that scrollHeight value which will be important later.
After the user zooms in the WKWebView the delegate method scrollViewDidEndZooming gets called which contains the current scaled information of the WKWebView's scrollView. I set the new height constraint constant of the WKWebView's frame by
webViewHeightConstraint.constant = initialHeight * scale
The height of the WKWebView increases and since I used dynamic sizing cells, the table cell height will also adjust accordingly.
That is UNTIL the zoom scale reaches a value close to 1.0
If it gets higher than this value, the content inside the WKWebView/scrollView gets white padding at the bottom.
I suspect that this has to do with the Width/Height ratio of the WebView's frame being changed, since if the initial height of the WebView is greater than content height this will also happen. Another example would be if you open a webpage in Safari that has a content height of 300px but you stretched out the window to have a height of 100px, there would be white space at the bottom (or whatever is set to)
My questions is if there's a fix/workaround for the white bottom padding issue? If you look at an email thread in Mail on iOS you can zoom in and out of the emails and the cell heights adjust accordingly.

resizing widget in pygtk

I have a scrolled window, which contains a drawing area in pygtk. I would like to change the size of the drawing area, and keep the scrolled window as it is. I don't find a function that works on widgets. I can get the size and so on, but I can't set it. Could someone give me a pointer to the solution?
Thanks,
v923z
It sounds like .set_size_request() is what you need. An example would be:
drawingarea.set_size_request(400, 400)
The values are the width and height of the canvas. Assuming you're ScrolledWindow is setup correctly, the scrollbars should adjust automatically to the size of the DrawingArea.