209 lines
4.8 KiB
TypeScript
209 lines
4.8 KiB
TypeScript
import { MwCLIPBOARD, MwCOORDINATE } from "./enums";
|
|
import { MwPoint, MwRect } from "./structs";
|
|
|
|
export type MwClass = object & { __brand: "MwClass" };
|
|
|
|
/**
|
|
* `BaseWidget` represents the lowest level form of widgets before the native layer.
|
|
* This class contains the native methods shared by all widgets.
|
|
*/
|
|
export interface BaseWidget {
|
|
area: MwRect;
|
|
isPending: boolean;
|
|
parent: BaseWidget;
|
|
children: BaseWidget[];
|
|
name: string;
|
|
cursorCoord: MwPoint;
|
|
screenSize: MwRect;
|
|
coordinateType: MwCOORDINATE;
|
|
nativeClass: MwClass;
|
|
|
|
/**
|
|
* Sets new position and size to this widget
|
|
* @param area New rect
|
|
*/
|
|
setArea(area: MwRect): this;
|
|
|
|
/**
|
|
* Moves this widget to an absolute position
|
|
* @param x X position
|
|
* @param y Y position
|
|
*/
|
|
move(x: number, y: number): this;
|
|
|
|
/**
|
|
* Changes the size dimension of this widget
|
|
* @param width New width
|
|
* @param height New height
|
|
*/
|
|
resize(width: number, height: number): this;
|
|
|
|
/**
|
|
* Runs a single step through the event loop
|
|
* @returns Wether the step was successful
|
|
*/
|
|
step(): boolean;
|
|
|
|
/**
|
|
* Start the main loop on this widget
|
|
*/
|
|
loop(): this;
|
|
|
|
/**
|
|
* Show/hide this widget
|
|
* @param toggle Wether the widget is shown
|
|
*/
|
|
show(toggle: boolean): this;
|
|
|
|
/**
|
|
* Hides the cursor when being hovered over this widget
|
|
*/
|
|
hideCursor(): this;
|
|
|
|
/**
|
|
* Grabs the pointer and pins it to the center of this widget
|
|
* @param toggle Wether the pointer is grabbed
|
|
*/
|
|
grabPointer(toggle: boolean): this;
|
|
|
|
/**
|
|
* Focus this widget
|
|
*/
|
|
focus(): this;
|
|
|
|
/**
|
|
* Adds this widget to the tick handler list
|
|
*/
|
|
addTickList(): this;
|
|
|
|
/**
|
|
* Forces this widget to render
|
|
*/
|
|
forceRender(): this;
|
|
|
|
/**
|
|
* Reparents this widget to a new parent
|
|
* @param widget New parent
|
|
*/
|
|
reparent(widget: BaseWidget): this;
|
|
|
|
/**
|
|
* Adds another widget as child of this one
|
|
* @param widgets Widgets to add
|
|
*/
|
|
addChild(...widgets: BaseWidget[]): this;
|
|
|
|
/**
|
|
* Destroys this widget
|
|
*/
|
|
destroy(): null;
|
|
|
|
/**
|
|
* Queues this widget to get clipboard content.
|
|
* This is ignored in backends that aren't or X11/Wayland.
|
|
* @param type Clipboard type to get, if you are unsure just use `MwCLIPBOARD_MAIN`
|
|
*/
|
|
getClipboard(type: MwCLIPBOARD): undefined;
|
|
|
|
/**
|
|
* Sets a value to an integer property by its key
|
|
* @param key Prefixed property key
|
|
* @param value Value to assign to property
|
|
*/
|
|
setInteger(key: string, value: number): this;
|
|
|
|
/**
|
|
* Sets a value to a string property by its key
|
|
* @param key Prefixed property key
|
|
* @param value Value to assign to property
|
|
*/
|
|
setString(key: string, value: string): this;
|
|
|
|
/**
|
|
* Sets the value of a void* property by its key.
|
|
* You most likely shouldn't use this unless you are extending BaseWidget
|
|
* @param key Prefixed property key
|
|
*/
|
|
setVoid(key: string, value: unknown): this;
|
|
|
|
/**
|
|
* Gets the value of an integer property by its key
|
|
* @param key Prefixed property key
|
|
*/
|
|
getInteger(key: string): number;
|
|
|
|
/**
|
|
* Gets the value of a string property by its key
|
|
* @param key Prefixed property key
|
|
*/
|
|
getString(key: string): string;
|
|
|
|
/**
|
|
* Gets the value of a void* property by its key.
|
|
* You most likely shouldn't use this unless you are extending BaseWidget
|
|
* @param key Prefixed property key
|
|
*/
|
|
getVoid(key: string): unknown;
|
|
}
|
|
|
|
export interface BaseWidgetConstructor {
|
|
new (cls: MwClass | null, options: WidgetOptions): BaseWidget;
|
|
}
|
|
|
|
export interface MwNativeClasses {
|
|
Box: MwClass;
|
|
Button: MwClass;
|
|
Calendar: MwClass;
|
|
CheckBox: MwClass;
|
|
Entry: MwClass;
|
|
Frame: MwClass;
|
|
Image: MwClass;
|
|
Label: MwClass;
|
|
ListBox: MwClass;
|
|
Menu: MwClass;
|
|
NumberEntry: MwClass;
|
|
ScrollBar: MwClass;
|
|
SubMenu: MwClass;
|
|
SubWindow: MwClass;
|
|
Tab: MwClass;
|
|
Viewport: MwClass;
|
|
Window: MwClass;
|
|
ProgressBar: MwClass;
|
|
RadioBox: MwClass;
|
|
ComboBox: MwClass;
|
|
TreeView: MwClass;
|
|
}
|
|
|
|
export interface Pixmap {
|
|
size: MwRect;
|
|
|
|
/**
|
|
* Get the raw data of this pixmap
|
|
*/
|
|
getRaw(): Buffer;
|
|
|
|
/**
|
|
* Updates this pixmap using raw data
|
|
* @param data Image data to update
|
|
*/
|
|
reloadRaw(data: Buffer | ArrayBuffer): void;
|
|
}
|
|
|
|
export interface PixmapOptions {
|
|
data?: Buffer;
|
|
width?: number;
|
|
height?: number;
|
|
}
|
|
|
|
export interface PixmapConstructor {
|
|
new (widget: BaseWidget, options?: PixmapOptions): Pixmap;
|
|
}
|
|
|
|
export interface WidgetOptions {
|
|
name?: string;
|
|
parent?: BaseWidget;
|
|
x?: number;
|
|
y?: number;
|
|
width?: number;
|
|
height?: number;
|
|
}
|