Window

Window UI component that extends UIComponent class. For more methods for this component check UIComponent class.

Constructor

new Window(textopt, owner_windowopt)

Window constructor.

Parameters:
NameTypeAttributesDescription
textstring<optional>

Text displayed in Window title bar and in task bar button.

owner_windowWindow<optional>

Enables modal mode. This new Window will always be on top of the owner Window until it is closed.

Example
<h2>To create a new custom window class (recommended way for main window):</h2>
class MyWindow extends Window
{
     constructor()
     {
         super("My New Application");
     }
}

// appWindow1 will be accessible globally.
globalThis.appWindow1 = new MyWindow();

Classes

Window

Members

(readonly) CloseOperation :number

Represents the behavior when a close button is clicked or close() method is called. Applies to Window and InternalWindow components.

Type:
  • number
Properties
NameTypeDescription
Nothingnumber

Do nothing; the close button has no effect.

Hidenumber

Hide the window instead of closing it.

Disposenumber

Release window resources and remove it from display.

Exitnumber

Terminate the entire application.

Example
window.closeOperation(Window.CloseOperation.Exit); // setting most common window close operation

(readonly) State :number

Different states that a Window can be in. Used with state() method for Window.

Type:
  • number
Properties
NameTypeDescription
Normalnumber

The window is in its normal, restored state (not minimized or maximized).

Minimizednumber

The window is minimized to the taskbar or dock.

Maximizednumber

The window is maximized to fill the screen.

MaximizedHorizontallynumber

The window is maximized horizontally but not vertically. Doesn't apply to InternalWindow component.

MaximizedVerticallynumber

The window is maximized vertically but not horizontally. Doesn't apply to InternalWindow component.

Example
window.state(Window.State.Maximized);

(readonly) Type :number

Represents the type of the window. Used when creating or modifying a window's appearance or behavior.

Type:
  • number
Properties
NameTypeDescription
Normalnumber

A standard, resizable window.

Utilitynumber

A smaller utility window, typically used for tools or palettes.

Popupnumber

A popup window, usually without a title bar, borders, and other window decorations.

Example
window.type(Window.Type.Utility);

(readonly) innerOffset :Object

Returns an offset of each side of content pane of the Window relative to Window's edges. See example below:

Type:
  • Object
Example
// Returned object format:
{
    top: number,
    right: number,
    bottom: number,
    left: number
}

(readonly) owner :Window|null

Returns Window component that is set as an owner of this Window, or null if owner Window was not set.

Type:

(readonly) screenSize :Object

Returns the size of the screen that the Window occupies. If the Window is not on any screen, then returns default screen's size.

Type:
  • Object

(readonly) shapeCount :number

Returns amount of shapes added to this Window.

Type:
  • number

(readonly) shapes :Array.<Shape>

Returns an array of shapes added to this Window.

Type:

Methods

addShape(shape, index) → {Window}

Adds a Shape to be drawn on the panel.

Parameters:
NameTypeDescription
shapeShape

Shape to be added

indexnumber

Set only if you want to insert the Shape at a specific index

Returns:

Returns this Window

Type: 
Window

alwaysOnTop(valueopt) → {Window|boolean}

Sets or gets whether window should always stay on top of other windows.

Parameters:
NameTypeAttributesDescription
valueboolean<optional>

Set Window to be on top or not

Returns:

Returns this Window if arguments are supplied, otherwise returns boolean value.

Type: 
Window | boolean

chooseColor(titleopt, initial_coloropt) → {string|null}

Opens color chooser dialog window.

Parameters:
NameTypeAttributesDefaultDescription
titlestring<optional>
Choose Color

Dialog window title text

initial_colorstring<optional>
#000000

Default color to show in dialog window before a new one is chosen.

Returns:

Returns a string of a chosen color.

Type: 
string | null

chooseFile(options) → {string|Array.<string>|null}

Opens file/directory chooser dialog window. Check example for all possible options.

Parameters:
NameTypeDescription
optionsObject

JSON Object with valid options. See example for full list of options.

Returns:

Returns string path if multiple option is false, string[] if multiple option is true, or null if file chooser was closed without making a selection.

Type: 
string | Array.<string> | null
Example
window.chooseFile({
 directory: boolean,          // `true` for Directory selection, `false` for Files.
 save: boolean,               // `true` for `Save` dialog box, `false` for `Open`.
 multiple: boolean,           // [true|false] to be able to select multiple files/folders.
 hidden:boolean,              // [true|false] to show hidden files.
 filter:"Documents:doc,docx,txt,rtf|Music:mp3,m4a,ogg,wma|Images:gif,jpg,jpeg,bmp,webp", // File extension can have multiple "." characters, such as "file.d.ts".
 path:"Initial-Path/file.ext" // Default path to open in the dialog window.
});

chooseFont(titleopt, initial_fontopt) → {Object|null}

Opens font chooser dialog window.

Parameters:
NameTypeAttributesDefaultDescription
titlestring<optional>
Choose Font

Dialog window title text

initial_fontObject<optional>

Pre-fills dialog window with specified font properties.

Returns:

Returns a new chosen font object or null if font was not selected.

Type: 
Object | null

close() → {Window}

Performs previously specified close operation on this Window. To specify what operation should be performed use closeOperation(Window.CloseOperation.[Nothing|Exit|Hide|Dispose])

Returns:

Returns this window component

Type: 
Window

closeOperation(operationopt) → {Window|Window.CloseOperation}

Sets or gets the operation to perform when a Window close button is clicked by a user or a close() method is called on this Window.

Parameters:
NameTypeAttributesDescription
operationWindow.CloseOperation<optional>

One of Window.CloseOperation enum values.

Returns:

Returns this component if argument is provided, otherwise returns value.

Type: 
Window | Window.CloseOperation

confirm(message) → {boolean}

Shows a dialog window asking user to confirm your message. User has an option to press OK or Cancel, which result in returned values true or false respectively.

Parameters:
NameTypeDescription
messagestring

Message to show in dialog window.

Returns:

Returns boolean indicating if user confirmed the message or not.

Type: 
boolean

defaultButton(button) → {Button|undefined}

Sets or gets a default button in this window form. On some systems like Windows OS default button has a different look than other buttons.

Parameters:
NameTypeDescription
buttonButton

The button that should be default on this Window. Only last assigned button gets to be default.

Returns:
Type: 
Button | undefined

hasBorder(valueopt) → {this|boolean}

Removes window border and title bar when set to false, or gets boolean indicating of the Window has border. Doesn't change anything when set to true. It cannot be undone. NOTE: This should only be called before the Window becomes visible, otherwise error occurs: "The window is displayable".

Parameters:
NameTypeAttributesDescription
valueboolean<optional>

Set to false to remove Window border before the Window became visible.

Returns:

If argument is provided, this component is returned, otherwise boolean value is returned.

Type: 
this | boolean

indexOfShape(shape) → {number}

Gets an index of a specified Shape object.

Parameters:
NameTypeDescription
shapeShape

Shape object in question

Returns:

Returns an index of the shape or -1 if the shape is not found.

Type: 
number

innerSize(width_or_sizeObject, height) → {Object}

Sets or gets a size of content container of this Window (doesn't include size of window borders and menu bar like size() function would).

Parameters:
NameTypeDescription
width_or_sizeObjectObject | number

Width integer or size object {width:number, height:number}

heightnumber

Height of the content container.

Returns:

Returns this Window if arguments are supplied, otherwise returns the size object.

Type: 
Object

maximize() → {Window}

Convenience method to maximize the Window by setting Window state to Window.State.Maximized.

Returns:

Returns this Window.

Type: 
Window

Sets or gets the main menu bar for the top of the Window. On macOS, this menu bar appears in the system's top menu bar.

Parameters:
NameTypeAttributesDescription
barMenuBar<optional>

The MenuBar to set as the primary menu bar.

Returns:

Returns the Window instance when setting a menu bar; otherwise, returns the currently set MenuBar, or undefined if none is set.

Type: 
Window | MenuBar | undefined

minimize() → {Window}

Convenience method to minimize the Window by setting Window state to Window.State.Minimized.

Returns:

Returns this Window.

Type: 
Window

onShapeEvents(callbackopt, removeopt) → {Window|Array.<function()>}

Gets, registers, and unregisters and event handler for shapes events, when shape is added, removes and pointer interaction with shapes.

Parameters:
NameTypeAttributesDefaultDescription
callbackfunction<optional>

Event handler callback function that accepts an event Object

removeboolean<optional>
false

Set to true to unregister the event handler.

Returns:

Returns an array of previously set handler functions if no arguments are provided, otherwise returns this Window component.

Type: 
Window | Array.<function()>

onStateChange(callbackopt, removeopt) → {this}

Gets, registers or unregisters an event handler for when the state of the Window changes between normal, minimized, maximized.

Parameters:
NameTypeAttributesDefaultDescription
callbackfunction<optional>

The event handler function. Receives an event object.

removeboolean<optional>
false

Set to true to unregister the event handler.

Returns:
Type: 
this
Example
// Example event object:
const e = {
  target: Window,            // The component that triggered the event.
  type: string,              // `change`
  state: Window.State,       // New state
  new_state: Window.State,   // Previous state
  interactive: boolean       // Indicates if the state was changed by user's interaction with window
};

onWindowEvents(callbackopt, removeopt) → {this}

Gets, registers or unregisters an event handler for window events, such as activate, deactivate, closed, etc.

Parameters:
NameTypeAttributesDefaultDescription
callbackfunction<optional>

The event handler function. Receives an event object.

removeboolean<optional>
false

Set to true to unregister the event handler.

Returns:
Type: 
this
Example
// Example event object:
const e = {
  target: Window,            // The component that triggered the event.
  type: string,              // `activate`, `deactivate`, `minimize`, `restore`, `closing`, `close`, `show`
  interactive: boolean       // Indicates if triggered by user's interaction with window
};

removeShape(index) → {Shape|boolean}

Removes a specified Shape.

Parameters:
NameTypeDescription
indexnumber | Shape

Shape or index of the Shape to be removed

Returns:

Returns removed Shape or false in case when index is invalid argument or is outside of bounds.

Type: 
Shape | boolean

resizable(valueopt) → {Window|boolean}

Sets of get whether the window may be resized by end user.

Parameters:
NameTypeAttributesDescription
valueboolean<optional>

Enables/disables resizing

Returns:

Returns this Window if argument is supplied, otherwise returns boolean value.

Type: 
Window | boolean

screen() → {Window|number}

Sets or returns the index or the screen that the Window is on.

Returns:

Returns this Window if argument is provided, otherwise returns index of the screen this Window is on.

Type: 
Window | number

shape(i) → {Shape}

Gets a Shape at specified index

Parameters:
NameTypeDescription
inumber

Index of the shape (integer)

Returns:

Returns a Shape at specified index, or undefined if index is out of bounds.

Type: 
Shape

state(stateopt) → {Window.State|Window}

Sets or get a window state. Use one of these enum values: Window.State.[Normal|Minimized|Maximized|MaximizedHorizontally|MaximizedVertically]

Parameters:
NameTypeAttributesDescription
stateWindow.State<optional>

Setting new window state

Returns:

Returns this Window if argument is provided, otherwise returns current state.

Type: 
Window.State | Window
Example
window.state(Window.State.Maximized);
if(window.state() === Window.State.Maximized) console.log("It works!");

type(typeopt) → {Window.Type|Window}

Sets or get a type of window:

  • Normal - standard, top-level window, appears in the taskbar, can have a minimize, maximize, and close buttons.
  • Utility - utility window, usually does not appear in the taskbar, may lack certain decorations like minimize and maximize buttons, has title bar and close button, useful for tool windows or dialogs.
  • Popup - pop-up window, used for transient, temporary window, may not appear in the taskbar, may lack certain decorations.

NOTE: This should only be called on a Window that has not been visible yet, otherwise error occurs: "The window is displayable".

Parameters:
NameTypeAttributesDescription
typeWindow.Type<optional>

Window type: Window.Type.Normal, Window.Type.Utility, Window.Type.Popup

Returns:

When called without parameters, this Windows instance is returned; otherwise current type is returned.

Type: 
Window.Type | Window