Changing size of UI Instance shown over sheets - google-apps-script

I am showing a Modal Dialog on the screen and I can set its size in units of pixels, however, people use different resolutions, so it might cut off on some computers. What I want to do is have the UI be full screen, in essence 100% x 100%. I am wondering if there is a way to do that.
function test() {
//I can set size in units of pixels here
var app = UiApp.createApplication().setHeight(700).setWidth(1500);
var label = app.createLabel("Hi").setId("label");
app.add(label);
SpreadsheetApp.getUi().showModalDialog(app, 'Test');
}
Thank you in advance

UiApp has no way to know the size of the browser view port, this can't be done.

Related

How can I make it so Edit2D lines do not resize when viewer is zoomed in and out?

Long story short: I want to set Edit2D polyline tool's line width to 6" based on calibration sizing and have it stay that size in the viewer no matter the camera zoom.
I'm using the edit2d library to allow drawing. I need to be able to set the line width for the polyline tool and have it stay at that width similar to how markups stay a set size when drawn. The default functionality of the edit2d polyline tool is for the line to be resized on camera changes and so it grows and shrinks depending on zoom.
I tried setting edit2DTools.polylineTool.style.isScreenSpace = false; which works, however, trying to set the specific size is difficult as it ends up being a decimal less then 1 and I can't find a correlation from the calibration, page size, etc. to allow me to dynamically set the size the same on different models.
I also found this in the Edit2D Snapper's code, but I can't figure out what's happening here to replicate it on the polyline tool. It seems to be doing what I want to do.
Any help or ideas at all would be greatly appreciated!
This code seems to be working for me:
async function setLineWidth(viewer) {
let mt = await viewer.loadExtension("Autodesk.Measure");
if (!mt.sharedMeasureConfig.calibrationFactor) {
console.log("Has not been calibrated yet");
return;
}
let edit2d = viewer.getExtension('Autodesk.Edit2D');
let pt1 = {x:0, y:0, z:0}, pt2 = {x:6, y:0, z:0};
viewer.model.pageToModel(pt1, pt2, 0 /*viewport id*/, true /*reverse*/);
let style = edit2d.defaultTools.polylineTool.style;
style.lineWidth = (pt2.x - pt1.x) / mt.calibration.scaleFactor;
}
Here is a video showing it in action: https://youtu.be/DIaKugvQdm4
As you can see first the lineWidth of the polylineTool is not what you want, but after setting what 6" should be in the drawing, I can set it to the same width and all is fine.
Here is a zip file with the html including the JavaScript code and the test PDFs I used: https://github.com/adamenagy/Container/blob/master/Edit2dTest.zip

How to Scale my Sprites up/down depends on screen resolution in cocos2dx?

I'm having problem working with multi screen solution. I've done the search around but still couldn't find the solution since those answer were oudated / using deprecated method or unclear to me. After 3 hours of searching and tried many different advices, I still couldn't get it done and I got confused so I have to create this topic. Your attention and help is very much appreciated.
My situation: I'm working with designResolutionSize = cocos2d::Size(1280, 720);. It works fine on my PC monitor (with screen solution 1600x900) but when I install my app on a set-top box and run it on a 30 inch or 40 inch TV. My sprites don't scale up to fit the TV screen, they looks too tiny.
My question How should I make my App scale up/down depends on the device resolution to fit the screen?
My AppDelegate.cpp:
static cocos2d::Size designResolutionSize = cocos2d::Size(1280, 720);
bool AppDelegate::applicationDidFinishLaunching(){
// Get the Director instance
auto mDirector = Director::getInstance();
// Get the GL View Container
auto mGLView = mDirector->getOpenGLView();
//Set up View Container if there's no available one
if (!mGLView)
{
mGLView = GLViewImpl::create("NGTV Launcher");
/*mGLView->setFrameSize(1280, 720);*/
mGLView->setFrameSize(1600, 900);
/*mGLView->setFrameSize(1920, 1080);*/
mDirector->setOpenGLView(mGLView);
}
mGLView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::EXACT_FIT);
// Innitialize a Scene with createScene()
auto mScene = HelloWorld::createScene();
// Run the scenee
mDirector->runWithScene(mScene);
return true;
}
I guess what you need is GLView::setDesignResolutionSize() and Director::setContentScaleFactor().
http://www.cocos2d-x.org/wiki/Multi_resolution_support

How to resize an image using Lumia Imaging SDK?

How can I resize an image using the Lumia Imaging SDK? The documentation seems to be very poor and I cannot find any examples/methods to resize (not crop) the image on Windows Phone 8.1.
Which methods can I use?
You should set the Size property on the renderer. That will resize the image to the size you want.
Looking at the JpegRenderer (https://msdn.microsoft.com/en-us/library/lumia.imaging.jpegrenderer_members.aspx) set the Size to what you want the size to be. In addition you can set the OutputOption property (https://msdn.microsoft.com/en-us/library/lumia.imaging.outputoption.aspx) if you want the contents to be Stretched or to preserve aspect ratio instead.
A quick example:
using (var source = ...)
using (var renderer = new JpegRenderer(source))
{
renderer.Size = new Size(800, 600);
renderer.OutputOption = OutputOption.Stretch;
var result = await renderer.RenderAsync();
}
If you are using a BitmapRenderer or a WriteableBitmapRenderer and pass in the (writeable)bitmap the renderer will automatically resize the contents to the size of that image.

How to have an application to automatically scale when launched?

I want my application to automatically scale its size depending on the screen size. I want my application to fit any screen size automatically. I am making my application for mobile devices, how can I do this? I am fairly new at flash so please make it a bit simple!
Yes, there is no simple answer but the basics is:
stage.addEventListener(Event.RESIZE,onStageResize);
function onStageResize(e:Event):void {
// Use stage size for placing elements to their position..
// Position to left top
element1.x = 10;
element1.y = 10;
// Position to right top
element2.x = stage.stageWidth - element2.width - 10;
element2.y = 10;
// Position element to center and make it's width to scale with stage..
element3.width = stage.stageWidth - 20;
element3.x = 10;
element3.y = stage.stageHeight / 2 - element3.height / 2;
}
To scale elements place them inside on Sprite or MovieClip and scale that element like:
element.scaleX = 1.6; // scale 1 = 100% 2 = 200% etc
element.scaleY = element.scaleX;
I usually create public function "resizeElements(e:Event = null):void" for visual subclasses/components and call that from the main thread. In that function the object can resize it self.
In addition to #hardy's answer it's important to set the following variables on the stage:
// disables default 100% scaling of entire swf
stage.scaleMode = StageScaleMode.NO_SCALE;
// disables default align center
stage.align = StageAlign.TOP_LEFT;
Also, since the original question was regarding resize on launch, and this is mobile deployment it's important to call onStageResize(); once manually because the RESIZE event may not be fired initially. This would require changing:
function onStageResize(e:Event):void { ... }
to
function onStageResize(e:Event = null):void { ... }
Saying "automatically scale to screen" is too generic. The requirements this statement imposes is totally different between apps depending on what they need to do. There is no simple answer.
If your app has a main content canvas area, do you want to zoom to the content to fit the area? Do you want to keep the content the same size and show more of it? Maybe both - you could want to show more to a point, and then scale if there is still more room.
What do you want your UI to do? Dialogs could shrink/grow and remain central. Maybe you want to reflow them completely?
Do you have a slick UI? Maybe a menu with a set of buttons. Do the buttons need to be sized proportionally to the screen? What about the gaps between them? What if the screen ratio is different so if you scale them to fit they no longer work?
The point is, there isn't a simple answer. For basic layout there are UI frameworks that can assist you in placement and scaling, but you still need to decide how you want your app to behave. That totally depends on the app and what your intended design is.

CSS Aspect Ratio on Canvas

Recently, Mozilla launched a HTML5 game called Browser Quest. In the game, if you resized the window, the canvas would also resize.
I looked more into and I saw that it was beacuse of usign CSS3 Media Queries found here https://developer.mozilla.org/en/CSS/Media_queries
However, I still don't think I am doing it right. My canvas ID is #canvas. How would I go about putting it for my canvas?
my canvas specific width/height: height:352px; width:512px;
So you don't want to define size of a canvas in CSS since you will only ever be scaling it away from its "true" size. You always want to use the width and height attributes of the Canvas instead.
But that doesn't mean you can't define it's parent's size that way. Wrap the canvas in a div and set the div's CSS width/height to 100% (or whatever you please)
In code during setup you are going to have to do:
// javascript pseudocode
canvas.width = theCanvasParent.clientWidth; // or whatever attribute it is, I'd reccomend putting all of those things in one giant container div
canvas.height = theCanvasParent.clientHeight;
Since most browsers do not fire an event when the parent div changes size, you'll simply have to check, say, every half second with a timer to see if the div has changed size. If it has, then you resize the canvas accordingly.
However there is the onresize event, and depending on how your page is setup this may do the trick.
In Firefox, Opera, Google Chrome and Safari, the onresize event is fired only when the size of the browser window is changed.
In Internet Explorer, the onresize event is fired when the size of the browser window or an element is changed.
So if the only way to change your div's size is by changing the window's size, onresize will do you just fine. Otherwise you'll need a timer that constantly checks to see if the canvas size and div size are different (and if so, to resize the canvas).
A timer that constantly checks is what the Mozilla Bepsin team did (before Bespin became Skywriter and then merged with the Ace project, dropping all Canvas use)
Media queries won't provide you with the functionality you seek. Their purpose is simply to limit when a particular stylesheet is applied to a page.
Furthermore, the CSS width and height properties do not adjust the actual dimensions of canvas elements. Instead, they scale the element to the requested size. In your case, I'm assuming you want the canvas to actually be a different resolution. The resolution of the canvas is specified via the DOM width and height attributes on your <canvas> tag.
In order to handle resizing, you will need to use window.onresize to capture the resize event. Your canvas code will need to then create a new canvas at the desired size and properly copy over everything from the original canvas (when you resize a canvas object its pixel data is cleared).
As was yet pointed by Xenethyl, the most important point is to hook onresize so that you can adapt to your new canvas object size :
adjust the canvas dimensions (the drawing area dimensions) to the canvas rendering area (clientWidth and clientHeight)
take into account the new dimensions of the canvas for your drawing algorithms
redraw the canvas
You don't have to make a new canvas (which would force you to rehook other event handlers).
Most of the canvas in my web applications, in order to be perfectly adjusted to the window, are managed by a dedicated class whose skeleton is here :
function Grapher(options) {
this.graphId = options.canvasId;
this.dimChanged = true; // you may remove that if you want (see above)
};
Grapher.prototype.draw = function() {
if (!this._ensureInit()) return;
// makes all the drawing, depending on the state of the application's model
// uses dimChanged to know if the positions and dimensions of drawed objects have
// to be recomputed due to a change in canvas dimensions
}
Grapher.prototype._ensureInit = function() {
if (this.canvas) return true;
var canvas = document.getElementById(this.graphId);
if (!canvas) {
return false;
}
if (!$('#'+this.graphId).is(':visible')) return false;
this.canvas = canvas;
this.context = this.canvas.getContext("2d");
var _this = this;
var setDim = function() {
_this.w = _this.canvas.clientWidth;
_this.h = _this.canvas.clientHeight;
_this.canvas.width = _this.w;
_this.canvas.height = _this.h;
_this.dimChanged = true;
_this.draw(); // calls the function that draws the content
};
setDim();
$(window).resize(setDim);
// other inits (mouse hover, mouse click, etc.)
return true;
};
In your case I would create a new Grapher({canvasId:'#canvas'}) and the #canvas dimensions are defined in css (and usually adjust in complex ways to the available space).
The most interesting points are in the setDim function.