Constructor
new Window(textopt, owner_windowopt)
Window constructor.
| Name | Type | Attributes | Description |
|---|---|---|---|
text | string | <optional> | Text displayed in Window title bar and in task bar button. |
owner_window | Window | <optional> | Enables modal mode. This new Window will always be on top of the owner Window until it is closed. |
<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
Members
(readonly) CloseOperation :number
Represents the behavior when a close button is clicked or close() method is called. Applies to Window and InternalWindow components.
- number
| Name | Type | Description |
|---|---|---|
Nothing | number | Do nothing; the close button has no effect. |
Hide | number | Hide the window instead of closing it. |
Dispose | number | Release window resources and remove it from display. |
Exit | number | Terminate the entire application. |
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.
- number
| Name | Type | Description |
|---|---|---|
Normal | number | The window is in its normal, restored state (not minimized or maximized). |
Minimized | number | The window is minimized to the taskbar or dock. |
Maximized | number | The window is maximized to fill the screen. |
MaximizedHorizontally | number | The window is maximized horizontally but not vertically. Doesn't apply to InternalWindow component. |
MaximizedVertically | number | The window is maximized vertically but not horizontally. Doesn't apply to InternalWindow component. |
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.
- number
| Name | Type | Description |
|---|---|---|
Normal | number | A standard, resizable window. |
Utility | number | A smaller utility window, typically used for tools or palettes. |
Popup | number | A popup window, usually without a title bar, borders, and other window decorations. |
- See
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:
- Object
// 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.
- Window |
null
(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.
- Object
(readonly) shapeCount :number
Returns amount of shapes added to this Window.
- number
(readonly) shapes :Array.<Shape>
Returns an array of shapes added to this Window.
- Array.<Shape>
Methods
addShape(shape, index) → {Window}
Adds a Shape to be drawn on the panel.
| Name | Type | Description |
|---|---|---|
shape | Shape | Shape to be added |
index | number | Set only if you want to insert the Shape at a specific index |
Returns this Window
- Type:
- Window
alwaysOnTop(valueopt) → {Window|boolean}
Sets or gets whether window should always stay on top of other windows.
| Name | Type | Attributes | Description |
|---|---|---|---|
value | boolean | <optional> | Set Window to be on top or not |
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.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
title | string | <optional> | Choose Color | Dialog window title text |
initial_color | string | <optional> | #000000 | Default color to show in dialog window before a new one is chosen. |
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.
| Name | Type | Description |
|---|---|---|
options | Object | JSON Object with valid options. See example for full list of options. |
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
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.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
title | string | <optional> | Choose Font | Dialog window title text |
initial_font | Object | <optional> | Pre-fills dialog window with specified font properties. |
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 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.
| Name | Type | Attributes | Description |
|---|---|---|---|
operation | Window. | <optional> | One of Window.CloseOperation enum values. |
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.
| Name | Type | Description |
|---|---|---|
message | string | Message to show in dialog window. |
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.
| Name | Type | Description |
|---|---|---|
button | Button | The button that should be default on this Window. Only last assigned button gets to be default. |
- 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".
| Name | Type | Attributes | Description |
|---|---|---|---|
value | boolean | <optional> | Set to |
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.
| Name | Type | Description |
|---|---|---|
shape | Shape | Shape object in question |
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).
| Name | Type | Description |
|---|---|---|
width_or_sizeObject | Object | | Width integer or size object {width:number, height:number} |
height | number | Height of the content container. |
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 this Window.
- Type:
- Window
menuBar(baropt) → {Window|MenuBar|undefined}
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.
| Name | Type | Attributes | Description |
|---|---|---|---|
bar | MenuBar | <optional> | The |
Returns the Window instance when setting a menu bar; otherwise, returns the currently set MenuBar, or undefined if none is set.
minimize() → {Window}
Convenience method to minimize the Window by setting Window state to Window.State.Minimized.
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.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
callback | function | <optional> | Event handler callback function that accepts an event Object | |
remove | boolean | <optional> | false | Set to |
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.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
callback | function | <optional> | The event handler function. Receives an event object. | |
remove | boolean | <optional> | false | Set to |
- See
- Type:
- this
// 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.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
callback | function | <optional> | The event handler function. Receives an event object. | |
remove | boolean | <optional> | false | Set to |
- Type:
- this
// 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.
| Name | Type | Description |
|---|---|---|
index | number | | Shape or index of the Shape to be removed |
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.
| Name | Type | Attributes | Description |
|---|---|---|---|
value | boolean | <optional> | Enables/disables resizing |
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 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
| Name | Type | Description |
|---|---|---|
i | number | Index of the shape (integer) |
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]
| Name | Type | Attributes | Description |
|---|---|---|---|
state | Window. | <optional> | Setting new window state |
- See
Returns this Window if argument is provided, otherwise returns current state.
- Type:
- Window.
State |Window
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".
| Name | Type | Attributes | Description |
|---|---|---|---|
type | Window. | <optional> | Window type: Window.Type.Normal, Window.Type.Utility, Window.Type.Popup |
When called without parameters, this Windows instance is returned; otherwise current type is returned.
- Type:
- Window.
Type |Window