I try to create a selectbox that adapts its width to its content. The JavaDoc states: The preferred size of the select box is determined by the maximum text bounds of the items and the size of the SelectBox.SelectBoxStyle.background., so it should happen automatically.
If I add the selectbox it doesn't show any content and has only the minimal size of the 9Patch used for the background. The text is only visible if I set the width manually.
Do I have to enable this functionality somehow?
I solved it.
After adding the items you have to call pack()
SelectBox<String> sb = new SelectBox<>(skin);
sb.setItems("Hello World", "FooBarBaz", "FizzBuzz");
sb.pack();
stage.addActor(sb);
Related
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.
I have a simple bitmap image 3px wide and 150px high included as the top banner in my layout.
<s:BitmapImage id="blueBanner" source="{this.bmpimg}" width="100%"/>
The rest of the content is centered below this.
When the page opens no matter the size of the browser window, the image always fills the width available.
I have a browser window resize handler that resets my main content below the banner to the center of the new window size and this works perfectly.
But no matter how many times the browser is resized, the BitmapImage will never stretch wider than the original window width.
I have tried every property and method of BitmapImage that I think could affect this in the resize handler but nothing I can find has any effect at all.
I cannot understand how it remembers the original stage width to begin with.
Its parent containers are all set to 100% width and there are no unusual skins or any other reference to this object in the whole project except in a function where it can be included in the layout or not, but this function is never called in this case.
Can anyone offer any clue as to why it won't stretch automatically?
Doug
Simple , just set the width to screen.width and you are good to go.
<s:BitmapImage id="blueBanner" source="{this.bmpimg}" width="{screen.width}"/>
Thanks for all the responses. In fact I solved the problem by adding the BitmapImage line to the Application Skin. Once it's here as well as in the layout it works. I have no idea why it needs to be in both places, but once it's set up like this everything works correctly.
Setting ScaleMode makes no difference and setting screen.width either in the blueBanner tag or later in the resizeHandler (because not always available when the tag is run) also makes no difference in my layout.
Doug
I have a QTextBrowser object in my dialog which will have HTML written to it. It is in a vertical layout with several other objects. I have the vertical size policy currently set to MinimumExpanding for this QTextbrowser. The problem is if the HTML written to the browser ends up taller than the QTextBrowser's minimum set height, its height stays the same and it instead makes me scroll down through the browser to see all the data, where I would like it instead to show all the data at once. I have tried changing around the size policies for the QTextBrowser and the layout it is in, but nothing I have tried has worked. Is there a way to do this that I am overlooking?
QTextBrowser *m_text=new QTextBrowser;
m_text->setFixedHeight(m_text->document()->size().height());
wish to help you.
If you know how many lines you are going to add then you can work out a height and then set that height.
int number_of_lines; // If you can get this value from somewhere this should work
// Get the height of the font being used
QFontMetrics font_metrics(ui->text_browser->font());
int font_height = font_metrics.height();
// Get the height by multiplying number of lines by font height, Maybe add to this a bit for a slight margin?
int height = font_height * number_of_lines;
// Set the height to the text broswer
ui->text_browser->setMinimumHeight(height);
ui->text_browser->setMaximumHeight(height);
Maybe I am wrong, I learn Easeljs for a week only.
The Container has no width and height to set the size.
I have 2 questions:
1. is the size of Container, dynamically change with the child.
2. if question 1 answer is yes, can I add a big bitmap or shape to it, eg. a background image...etc. to control the size of Container?
Consider a container as a group of objects, not a physical container. Containers give you the ability to transform, translate, cache, and otherwise control multiple items as a single item. They do not really have a physical size, except that of their collective children.
There is no width or height mainly due to the cost of calculating the size, especially considering transformations, sub-containers, etc. There may be support added in the future for width/height, but for now its not available.
[UPDATE]: Containers do have bounds, based on the bounds of children (retrieved using container.getBounds() (docs) that have bounds. For example, a Container that has Sprite, Bitmap, Text, objects with manually set bounds, or cached DisplayObjects will report bounds using those children. Shapes do not have auto-calculated bounds currently, so will not contribute to container bounds.
This is a very bad hack, but if you absolutely must fix the size of the container, you can use something like this:
var blank = new createjs.Shape();
var width = 1;
var height = 400;
blank.setBounds(0, 0, width, height);
container.addChild(blank);
This will set the size of container to the blank image and now any background you draw on it will be visible.
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.