// Type definitions for Tabris.js v1.2 // Project: http://tabrisjs.com // Definitions by: Tabris.js team // Definitions: https://github.com/borisyankov/DefinitelyTyped declare module tabris { // Types interface Bounds { /** * the horizontal offset from the parent's left edge in dip */ left: number; /** * the vertical offset from the parent's top edge in dip */ top: number; /** * the width of the widget in dip */ width: number; /** * the height of the widget in dip */ height: number; } interface Transformation { /** * Clock-wise rotation in radians. Defaults to `0`. */ rotation: number; /** * Horizontal scale factor. Defaults to `1`. */ scaleX: number; /* * Vertical scale factor. Defaults to `1`. */ scaleY: number; /** * Horizontal translation (shift) in dip. Defaults to `0`. */ translationX: number; /** * Vertical translation (shift) in dip. Defaults to `0`. */ translationY: number; } // TODO A plain string can be used as a shorthand, e.g. `"image.jpg"` equals `{src: "image.jpg"}`. interface Image { /** * Image path or URL. */ src?: string; /** * Image width, extracted from the image file when missing. */ width?: number; /** * Image height, extracted from the image file when missing. */ height?: number; /** * Image scale factor - the image will be scaled down by this factor. * Ignored when width or height are set. */ scale?: number; } interface CanvasContext { // TODO } // Events /** * Event handling API supported by widgets and various other objects. */ interface EventSupport { /** * Adds the *listener* to the list of functions to be notified when *event* is fired. * In the listener function, `this` will point to the object itself. Supports chaining. * * @param event the name of the event to listen on * @param listener the listener function */ on (event: string, listener: (target: T, ...args: any[]) => any): T; /** * Same as `on`, but removes the listener after it has been invoked by an event. * Supports chaining. * * @param event the name of the event to listen on * @param listener the listener function */ once (event: string, listener: (target: T, ...args: any[]) => any): T; /** * Removes all listeners for all events from this widget. Supports chaining. */ off (): T; /** * Removes all listeners for *event* from this widget. Supports chaining. * * @param event the event name to remove listeners for */ off (event: string): T; /** * Removes all occurrences of *listener* that are bound to *event* from this widget. * Supports chaining. * * @param event the event to remove the listener from * @param listener the listener function to remove */ off (event: string, listener: (target: T, ...args: any[]) => any): T; /** * Triggers an event on this object. Supports chaining. * * @param event the name of the event to trigger * @param args the arguments to pass to the listener functions */ trigger (event: string, ...args: any[]): T; } interface AnimationOptions { /** * The time until the animation starts in ms, defaults to `0`. */ delay?: number; /** * The duration in ms. */ duration: number; /** * One of `linear`, `ease-in`, `ease-out`, `ease-in-out`. */ easing: string; /** * The number of times to repeat the animation, defaults to `0`. */ repeat: number; /** * `true` to alternate the direction of the animation on every repeat. */ reverse: boolean; /** * No effect, but will be given in animation events. */ name: string; } // Widget function create (type: string, properties: WidgetProperties): Widget; /** * API supported by all widgets. */ interface Widget extends EventSupport { // Property Support /** * Gets the current value of the given *property*. * * @param property */ get (property: string): any; /** * Sets the given property. Supports chaining. * * @param property the name of the property to set * @param value the value to set the property to * @param options passed to the change event resulting from this method call */ set (property: string, value: any, options?: Object): T; /** * Sets all key-value pairs in the properties object as widget properties. Supports chaining. * * @param properties the properties to set * @param options passed to the change event resulting from this method call */ set (properties: WidgetProperties, options?: Object): T; /** * Starts an animation that transforms the given properties from their current values to the given ones. * Supported properties are *transform* and *opacity*. * * @param properties The properties and target values to animate. * @param options Configures the animation itself. */ animate (properties: WidgetProperties, options: AnimationOptions): void; /** * Appends this widget to the given parent. * The parent widget must support children (extending *Composite*). * * @param parent the parent widget to append this one to */ appendTo (parent: Composite): T; /** * Applies the given properties to all descendants that match the associated selector(s). * * @param properties an object in the format * `{selector: {property: value, property: value, ... }, selector: ...}` */ apply (properties: Object): T; /** * Returns a (possibly empty) collection of all children of this widget. */ children (): WidgetCollection; /** * Returns a (possibly empty) collection of all children of this widget that match the selector. * * @param selector a selector string to filter children */ children (selector: string): WidgetCollection; /** * Removes this widget from its parent and destroys it. Also disposes of all its children. * Triggers a `remove` event on the parent and a `dispose` event on itself. * The widget can no longer be used. */ dispose (): void; /** * Returns a (possibly empty) collection of all descendants of this widget. */ find (): WidgetCollection /** * Returns a (possibly empty) collection of all descendants of this widget that match the selector. * @param selector */ find (selector: string): WidgetCollection /** * Returns `true` if the widget has been disposed, otherwise `false`. */ isDisposed (): boolean /** * Returns the parent of this widget. */ parent (): T; /** * An application-wide unique identifier automatically assigned to all widgets on creation. * Do not change it. */ cid: string; /** * Direct access to the value of the property of the same name. * May be used instead of `widget.get("id");`. * Do not use this field to change the value, instead use `widget.set("id", id);`. */ id: string; /** * The exact string that was used to create this widget using the `tabris.create` method. */ type: string; } interface WidgetProperties { /** * The background color of the widget. */ background?: string; /** * An image to be displayed on the widget's background. * If the image is smaller than the widget, it will be tiled. */ backgroundImage?: Image; /** * The vertical position of the widget's baseline relative to a sibling widget. */ baseline?: any; /** * The position of the widget's bottom edge relative to the parent or a sibling widget. */ bottom?: any; /** * The actual location and size of the widget, relative to its parent. This property is read-only. */ bounds?: Bounds; /** * The horizontal position of the widget's center relative to the parent's center. */ centerX?: number; /** * The vertical position of the widget's center relative to the parent's center. */ centerY?: number; /** * Whether the widget can be operated. */ enabled?: boolean; /** * The font used for the widget. */ font?: string; /** * The height of the widget. */ height?: number; /** * Whether the entire widget should be highlighted while touched. */ highlightOnTouch?: boolean; /** * A string to identify the widget by using selectors. Id's are optional. * It is strongly recommended that they are unique within a page. */ id?: string; /** * Shorthand for all layout properties. See [Layout](../layout.md). */ layoutData?: Object; /** * The position of the widget's left edge relative to the parent or a sibling widget. */ left?: any; /** * Opacity of the entire widget. Can be used for fade animations. */ opacity?: number; /** * The position of the widget's right edge relative to the parent or a sibling widget. */ right?: any; /** * Text color of the widget. */ textColor?: string; /** * The position of the widget's top edge relative to the parent or a sibling widget. */ top?: any; /** * Modifications to the widget's shape, size, or position. Can be used for animations. * **Note:** In Android, the *transform* property does not affect the *bounds* property, * while it does so in iOS. */ transform?: Transformation; /** * Whether the widget is visible. */ visible?: boolean; /** * The width of the widget. */ width?: number; } // Action function create (type: "Action", properties: ActionProperties): Action; /** * An executable item that is integrated in the application's navigation menu. * Add a listener on *select* to implement the action. */ interface Action extends Widget { set (property: string, value: any, options?: Object): Action; set (properties: ActionProperties, options?: Object): Action; } interface ActionProperties extends WidgetProperties { /** * Icon image for the action. */ image?: Image; /** * Actions with higher placement priority will be placed at a more significant position in the UI, * e.g. low priority actions could go into a menu instead of being included in a toolbar. * Any of `low`, `high`, `normal`. */ placementPriority?: string; /** * The text to be displayed for the action. */ title?: string; } // Button function create (type: "Button", properties: ButtonProperties): Button; /** * A push button. Can contain a text or an image. */ interface Button extends Widget