royibernthal Posted June 2, 2017 Share Posted June 2, 2017 Bug? - Try to resize the window, text is cropped instead of resized: http://www.babylonjs-playground.com/#XCPP9Y#47 Feature suggestion - When idealWidth is present, would it be possible to resize text blocks based on an internal calculation of its dimensions (pixels) at the idealWidth? (or make it optional) That way the width and height of a text block could be defined according to that internal calculation, and since they'll be defined in px with idealWidth present, they'll be resized accordingly. The way things are now we'd have to figure roughly how big the text block is and define it manually in px for it to be resized in proportions to idealWidth. For instance for image we can simply set the width and height of the gui image to that of the dom image in order to automate the calculation, but for text blocks we don't have any way to actually know the width and height of the text. (or do we?) Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 2, 2017 Share Posted June 2, 2017 It is a bug..Will fix it tonight:) For the suggestion, unfortunately this is not possible because I'm using context.measure which only use fontzise Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 2, 2017 Share Posted June 2, 2017 Fixed Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 2, 2017 Share Posted June 2, 2017 Here: http://www.babylonjs-playground.com/#XCPP9Y#48 royibernthal 1 Quote Link to comment Share on other sites More sharing options...
royibernthal Posted June 2, 2017 Author Share Posted June 2, 2017 Thanks for the fix So the way you know for instance how to align text blocks according to their actual size is via context.measure which uses font size? If so, since by design font sizes aren't affected by resolution (correct me if I'm wrong), maybe we could treat the idealWidth as a text block's 100%? Since a text block is rendered at a fixed size according to font size by default regardless of stage size, if that can be calculated (the way you calculate the text block's actual size in order to align it) then resizing according to idealWidth should be possible. Makes sense? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 2, 2017 Share Posted June 2, 2017 11 hours ago, royibernthal said: So the way you know for instance how to align text blocks according to their actual size is via context.measure which uses font size? Correct: https://github.com/BabylonJS/Babylon.js/blob/master/gui/src/controls/textBlock.ts#L112 Not sure to follow you: you want to: - compute text size. Let's say it is 300px with a font size of 50px - scale that 300px according to idealWidth and current resolution. so if idealWidth = 600 and current resolution = 300 then the new text size should be 150px - Revert the measureText to deduce the right font size to produce a text of 150px width? The last step seems complex as I see no other option than brute force Quote Link to comment Share on other sites More sharing options...
royibernthal Posted June 2, 2017 Author Share Posted June 2, 2017 Yes this was pretty match what I meant. Is it needed to deduce the right font size? Why not keep the same font size and simply multiply the values returned from context.measure by the text scale? That way instead of trying to deduce the right font size, you still deal with pixels and the font size remains the same, only the whole thing is scaled. I've never dealt with that low-level api so it's highly likely that I'm missing something. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 3, 2017 Share Posted June 3, 2017 Quote Why not keep the same font size and simply multiply the values returned from context.measure by the text scale? Because I do not decide the size of the text boundaries but I set a fontsize and ask for text rendering Quote Link to comment Share on other sites More sharing options...
royibernthal Posted June 3, 2017 Author Share Posted June 3, 2017 Let's simplify it - At the moment I can see 2 functionalities: 1) Measure text block size (e.g. that's how you align text blocks) 2) Resize text block (e.g. to be dependent on idealWidth) What I'm doing now is setting the text block size in px by eye, and then it is resized according to idealWidth. Why not measure the text block size, and then set its width and height in px according to that? It should really be as simple as that, since the rest of the logic is already there. While we're on the subject - Can you expose a way to get text block ACTUAL width and height in px? Here I don't see anything exposed: https://github.com/BabylonJS/Babylon.js/blob/master/gui/src/controls/textBlock.ts and width and height return 100% (makes sense but doesn't help me) Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 4, 2017 Share Posted June 4, 2017 This is an open source project. Please submit a PR to try what you need. This will be easier and I won't be the only one to contribute Quote Link to comment Share on other sites More sharing options...
royibernthal Posted June 5, 2017 Author Share Posted June 5, 2017 At first it'll be harder, but on the long run it could definitely make things easier, I have no objections GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.