I wanna have a listener ( or something ) to check if the size of the window changes, do something ( like re-rendering entire view page ).
How should I do this?
You can use the resize event like so:
window.on('resize', function () {
var size = window.getSize();
var width = size[0];
var height = size[1];
console.log("width: " + width);
console.log("height: " + height);
});
Docs here
To clarify the above answer. You have to set the resize event on the main window you created. Further, if you want to access the width or height inside another file, you can emit another event and pass the width or height as a parameter. Here is a simple example of what I have done.
mainWindow.on("resize", function () {
var size = mainWindow.getSize();
var width = size[0];
var height = size[1];
mainWindow.webContents.send("resized", height);
console.log(size);
console.log("width: " + width);
console.log("height: " + height);
});
Related
There is another similar question, but that seems to be focused on the js library, not Highsoft.Highcharts (and I'm using v8.1.1.1) I tried some of these solutions, but they didn't seem to work.
Try to use those CSS options:
body, html {
height: 100%;
}
#container {
height: 100%;
}
Not the most elegant when you're working with a .NET wrapper, but this seemed to work (from a colleague of mine). When using the wrapper, "chart" comes from the Id of the Highcharts object. So you will need to change that if you use something else for Id.
var chart = new Highcharts { Id = "chart" };
And then this script in the .cshtml file:
<script>
$(window).load(function () {
// "chart" is the Id of the Highcharts container
var chart = $('#chart').highcharts();
var width = $('#chart').width();
// 100 is an approximation for the hight of the navbar + margin for panel. Removing that from the entire height of the window.
var height = $(window).innerHeight() - 100;
$('panel-body').height = height;
// setsize will trigger the graph redraw
chart.setSize(width, height, false);
});
$(window).resize(function () {
// "chart" is the Id of the Highcharts container
var chart = $('#chart').highcharts();
var width = $('#chart').width();
// 100 is an approximation for the hight of the navbar + margin for panel. Removing that from the entire height of the window.
var height = $(window).innerHeight() - 100;
// setsize will trigger the graph redraw
chart.setSize(width, height, false);
});
</script>
UPDATE: This is an iOS 10 issue. This still works as before in iOS 9.
This is ...interesting.
I just converted my "teaching project" (a "toy" app) to Swift 3.
It has been working for a couple of years under Swift 1.2.
All of a sudden, my UIScrollView is not scrolling, even when I set the contentSize way past its lower boundary.
Here's the relevant code (the displayTags routine is called with an array of images that are displayed centered and slightly vertically offset, leading to a vertical chain):
/*******************************************************************************************/
/**
\brief Displays the tags in the scroll view.
\param inTagImageArray the array of tag images to be displayed.
*/
func displayTags ( inTagImageArray:[UIImage] )
{
self.tagDisplayView!.bounds = self.tagDisplayScroller!.bounds
if ( inTagImageArray.count > 0 ) // We need to have images to display
{
var offset:CGFloat = 0.0 // This will be the vertical offset for each tag.
for tag in inTagImageArray
{
self.displayTag ( inTag: tag, inOffset: &offset )
}
}
}
/*******************************************************************************************/
/**
\brief Displays a single tag in the scroll view.
\param inTag a UIImage of the tag to be displayed.
\param inOffset the vertical offset (from the top of the display view) of the tag to be drawn.
*/
func displayTag ( inTag:UIImage, inOffset:inout CGFloat )
{
let imageView:UIImageView = UIImageView ( image:inTag )
var containerRect:CGRect = self.tagDisplayView!.frame // See what we have to work with.
containerRect.origin = CGPoint.zero
let targetRect:CGRect = CGRect ( x: (containerRect.size.width - inTag.size.width) / 2.0, y: inOffset, width: inTag.size.width, height: inTag.size.height )
imageView.frame = targetRect
containerRect.size.height = max ( (targetRect.origin.y + targetRect.size.height), (containerRect.origin.y + containerRect.size.height) )
self.tagDisplayView!.frame = containerRect
self.tagDisplayView!.addSubview ( imageView )
self.tagDisplayScroller!.contentSize = containerRect.size
print ( "Tag Container Rect: \(containerRect)" )
print ( " Tag ScrollView Bounds: \(self.tagDisplayScroller!.bounds)" )
inOffset = inOffset + (inTag.size.height * 0.31)
}
Note that the scrollView's contentSize is expanded each time a tag is added. I checked (see the print statements), and the value seems to be correct.
The project itself is completely open-source.
This is where this issue manifests (I have other bugs, but I'll get around to fixing them after I nail this one).
I'm sure that I am doing something obvious and boneheaded (usually the case).
Anyone have any ideas?
it will work when you will set contentSize on main thread and put this code in - (void)viewDidLayoutSubviews
- (void)viewDidLayoutSubviews
{
dispatch_async (dispatch_get_main_queue(), ^
{
[self.scrollview setContentSize:CGSizeMake(0, 2100)];
});
}
contentSize should be change in main thread in swift.
DispatchQueue.main.async {
self.scrollView.contentSize = CGSize(width: 2000, height: 2000)
}
This worked for me.
OK. I solved it.
I remove every single auto layout constraint for the internal (scrolled) view at build time.
I assume that iOS 10 is finally honoring the contract by forcing the top of the scrolled view to attach to the top of the scroller, even though the user wants to move it.
I am making an iOS app, one page of my app has a webview and multiple views follows. In this page, the webview should auto expand and the height should fit with the content injected dynamically, because i do not want the webview has scroll. Now, i have a problem, i can't post the exact height of doucment.body to the client to set webview's height, because i can't confirm when the whole content has been render into the document.
i have tried to check the height change of document.body,till the height is not changed, i post '0'. The client get the signal i post through invokeNative('changeHeight', params),when it is 0, the client get the document.body height, but in my test, that is not the exact height of the document. Just part of the content shows.
function reportHeight() {
var preH = document.body.offsetHeight;
var params = {
"heigh": preH
};
invokeNative('changeHeight', params); //the method i communicate with client
var timeId = setInterval(function() {
var height = document.body.offsetHeight;
if((height - preH) == 0) {
invokeNative('changeHeight', {"heigh": 0});
clearInterval(timeId);
setTimeout(function() {
invokeNative('changeHeight', {"heigh": 10});
}, 500)
return false;
}
var params = {
"heigh": (height - preH)
};
preH = height;
invokeNative('changeHeight', params);
}, 30);
}
is there any way to fix this problem?
By the way, the content injected into the page only has css and html tags, and there is no js.
The following code is working for the most part, however sometimes after being changed into a blob, the image view does not display the image.
//store in temp image view, convert to blob
imageViewTemp.image = "imagename.jpg"
blob = imageViewTemp.toBlob();
albumTitle = data[x].name + ' (' + numberPhotos + ')';
var row = Titanium.UI.createTableViewRow({
titleAlb : data[x].name,
width : '100%',
height : 'auto'
});
var image = Titanium.UI.createImageView({
top : 0,
left : 0,
width : '75',
height : '75'
});
var title = Titanium.UI.createLabel({
text : albumTitle,
top : 0,
left : 110,
width : 'auto',
height : 'auto'
});
var width = blob.width;
var height = blob.height;
//crop so it fits in image view
if (width > height) {
image.image = ImageFactory.imageAsCropped(blob, {
width : height,
height : height,
x : 60,
y : 0
});
} else {
image.image = ImageFactory.imageAsCropped(blob, {
width : (width - 1),
height : (width - 1),
x : 60,
y : 0
});
}
row.add(image);
row.add(title);
rows.push(row);
}
In order to change the dimension of the image, I am using a module called image factory. Before I can change it, I have to store the image inside a tempory image view which I then convert into a blob:
blob = imageViewTemp.toBlob();
The problem is after the screen is rendered sometimes this will not work:
image.image = ImageFactory.imageAsCropped(blob, {
width : height,
height : height,
x : 60,
y : 0
});
Othertimes it will.
I have read online that the problem might be linked to the post layout cycle, but I am not sure, or how to proceed
http://developer.appcelerator.com/question/174329/what-are-the-difference-between-toblob--toimage
All help appreciated.
Solved the problem.
You have to download the image first using a REST API method (GET) before placing it into the temporary image view, otherwise the temp image view will be rendered before the file has been fully downloaded (.toImage is an async call back method), making way for a useless blob and no image.
The only problem with this method, is that you are reliant on your REST API calls to not fail.
var width = 400;
var height = 400;
Stage {
style: StageStyle.TRANSPARENT
onClose: function():Void {
System.exit(0);
}
scene: Scene {
content: Scribble {}
width: width
height: bind height
}
}
Why does the width work, but the height not?
And, what can I do to fix this? Netbeans is saying:
height has script only(default) bind access in javafx.scene.Scene
Ok, I figured it out:
var width : Number = 400;
var height : Number = 400;
var stage:Stage = Stage {
width: bind width with inverse
height: bind width with inverse
scene: Scene {
content: Scribble {
canvasWidth: bind stage.scene.width
canvasHeight: bind stage.scene.height
}
}
}
Although, I don't really need to specify the width and height here, because I can access these through the stage variable. The scene width and height updates when the stage width and height changes. I've found that the canvasWidth will update a lot better when bound to the scene width and height rather than to the var width and height (which only update once the resize is complete)
To be more precise on this, the Scene's width and height are declared as "public-init". This means they can only be set at initialization time. The bind on height in the Scene Object literal implies that height will be updated, hence the error. The Stage's width and height are declared as "public" meaning they can be updated.
You should not bind the scene dimensions to anything. Mostly because the scene dimensions will not get updated when the user tries to resize the containing window.