getWindowCenter ( )

Function stats

Average user rating
166
427
9999
Support
FileMaker 10.0 +
Date posted
15 February 2020
Version
1
Recursive function
No

Author Info
 Josh Ormond

11 functions

Average Rating None

author_avatar



 

Function overview

Prototype

getWindowCenter  ( height;   width )


Parameters

height  Supply the height of the window, or leave blank to use current window.


width  Supply the width of the window, or leave blank to use current window.


Description

Tags:  window   JSON   center  

Get the top and left coordinates to center a window on the screen, as JSON

If you don't pass in the height or width, the function will use the current window's height and width to calculate the coordinates.

Also, if the input height or width is larger than the desktop dimensions, the function will return the desktop dimension instead.

There are 2 helper functions that will return just the left or top.

Examples

Sample input

getWindowCenter ( 600 ; 800 )


Sample output

{"left":320,"top":115}

 

Function code

/***************************************
*
*    Function Name:        getWindowCenter ( height ; width )
*    Parameters:        @height = Supply the height of the window, or leave blank to use current window.
*                    @width = Supply the width of the window, or leave blank to use current window.
*    Purpose:            Return the top and left coordinates to center a window on the screen as JSON.
*    Notes:            
*    Change log:        2020-01-28 JO - Initial build.
*
*****************************************/


Let (

[

    winHeight =  Case ( IsEmpty ( height ) ; Get ( WindowHeight ) ; height ) ;
    winWidth =  Case ( IsEmpty ( width ) ; Get ( WindowWidth ) ; width ) ;

    maxHeight = Case ( winHeight > Get ( WindowDesktopHeight ) ; Get ( WindowDesktopHeight ) ; winHeight ) ;
    maxWidth = Case ( winWidth > Get ( WindowDesktopWidth ) ; Get ( WindowDesktopWidth ) ; winWidth ) ;

    winTop = Floor ( ( Get ( WindowDesktopHeight ) / 2 ) - ( maxHeight / 2 ) ) ;
    winLeft = Floor ( ( Get ( WindowDesktopWidth ) / 2 ) - ( maxWidth / 2 ) ) ;

    result =
        JSONSetElement (
            "{}" ;
            [ "top" ; winTop ; JSONNumber ] ;
            [ "left" ; winLeft ; JSONNumber ]

        )

];


result

)

// ===================================
/*

    This function is published on FileMaker Custom Functions
    to check for updates and provide feedback and bug reports
    please visit http://www.fmfunctions.com/fid/427

    Prototype: getWindowCenter( height; width )
    Function Author: Josh Ormond (http://www.fmfunctions.com/mid/166)
    Last updated: 15 February 2020
    Version: 1

*/
// ===================================