From a4809baee8ceca83d06bff7dbe9ec9390ec4c3dc Mon Sep 17 00:00:00 2001 From: thinknathan Date: Fri, 15 Mar 2024 18:01:19 -0700 Subject: [PATCH 1/9] Add druid --- packages/druid/druid-0.11.0.d.ts | 15 + packages/druid/druid.druid.d.ts | 395 ++++++++++++++++++ packages/druid/druid.extended.checkbox.d.ts | 33 ++ .../druid/druid.extended.checkbox_group.d.ts | 26 ++ packages/druid/druid.extended.data_list.d.ts | 45 ++ .../druid/druid.extended.dynamic_grid.d.ts | 61 +++ packages/druid/druid.extended.hotkey.d.ts | 28 ++ packages/druid/druid.extended.input.d.ts | 50 +++ packages/druid/druid.extended.lang_text.d.ts | 42 ++ packages/druid/druid.extended.layout.d.ts | 43 ++ packages/druid/druid.extended.progress.d.ts | 43 ++ .../druid/druid.extended.radio_group.d.ts | 26 ++ packages/druid/druid.extended.slider.d.ts | 30 ++ packages/druid/druid.extended.swipe.d.ts | 32 ++ packages/druid/druid.extended.timer.d.ts | 35 ++ packages/druid/library.json | 4 + 16 files changed, 908 insertions(+) create mode 100644 packages/druid/druid-0.11.0.d.ts create mode 100644 packages/druid/druid.druid.d.ts create mode 100644 packages/druid/druid.extended.checkbox.d.ts create mode 100644 packages/druid/druid.extended.checkbox_group.d.ts create mode 100644 packages/druid/druid.extended.data_list.d.ts create mode 100644 packages/druid/druid.extended.dynamic_grid.d.ts create mode 100644 packages/druid/druid.extended.hotkey.d.ts create mode 100644 packages/druid/druid.extended.input.d.ts create mode 100644 packages/druid/druid.extended.lang_text.d.ts create mode 100644 packages/druid/druid.extended.layout.d.ts create mode 100644 packages/druid/druid.extended.progress.d.ts create mode 100644 packages/druid/druid.extended.radio_group.d.ts create mode 100644 packages/druid/druid.extended.slider.d.ts create mode 100644 packages/druid/druid.extended.swipe.d.ts create mode 100644 packages/druid/druid.extended.timer.d.ts create mode 100644 packages/druid/library.json diff --git a/packages/druid/druid-0.11.0.d.ts b/packages/druid/druid-0.11.0.d.ts new file mode 100644 index 0000000..bfe2bcd --- /dev/null +++ b/packages/druid/druid-0.11.0.d.ts @@ -0,0 +1,15 @@ +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// diff --git a/packages/druid/druid.druid.d.ts b/packages/druid/druid.druid.d.ts new file mode 100644 index 0000000..5a3adc7 --- /dev/null +++ b/packages/druid/druid.druid.d.ts @@ -0,0 +1,395 @@ +type Component = {}; + +/** + * This is a definition stub with incomplete or untested signatures. + * Contributions are welcome to improve the accuracy of these types. + * @url https://github.com/ts-defold/library + * @url https://insality.github.io/druid/modules/Druid.html + * @noResolution + */ +declare module 'druid.druid' { + // Built-in Modules + class BackHandler { + on_back: DruidEvent; + params: any[]; + } + class Blocker { + init(this: Blocker, node: node): void; + is_enabled(this: Blocker): boolean; + set_enabled(this: Blocker, state: boolean): void; + node: node; + } + class Button { + get_key_trigger(this: Button): hash; + init( + this: Button, + node: node | string, + callback: Function, + custom_args?: any, + anim_node?: node | string, + ): void; + is_enabled(this: Button): boolean; + set_check_function( + this: Button, + check_function?: Function, + failure_callback?: Function, + ): Button; + set_click_zone(this: Button, zone: node): Button; + set_enabled(this: Button, state: boolean): Button; + set_key_trigger(this: Button, key: hash): Button; + set_web_user_interaction(this: Button, is_web_mode?: boolean): Button; + + style: { + LONGTAP_TIME: number; + AUTOHOLD_TRIGGER: number; + DOUBLETAP_TIME: number; + on_click: Function; + on_click_disabled: Function; + on_hover: Function; + on_mouse_hover: Function; + on_set_enabled: Function; + }; + anim_node: node; + click_zone?: node; + hover: Hover; + node: node; + node_id: hash; + on_click: DruidEvent; + on_click_outside: DruidEvent; + on_double_click: DruidEvent; + on_hold_callback: DruidEvent; + on_long_click: DruidEvent; + on_pressed: DruidEvent; + on_repeated_click: DruidEvent; + params: any[]; + } + class Drag { + init(this: Drag, node: node, on_drag_callback: Function): void; + is_enabled(this: Drag): boolean; + set_click_zone(this: Drag, node: node): void; + set_enabled(this: Drag, is_enabled: boolean): void; + + style: { + DRAG_DEADZONE: number; + NO_USE_SCREEN_KOEF: boolean; + }; + can_x: boolean; + can_y: boolean; + is_drag: boolean; + is_touch: boolean; + on_drag: DruidEvent; + on_drag_end: DruidEvent; + on_drag_start: DruidEvent; + on_touch_end: DruidEvent; + on_touch_start: DruidEvent; + touch_start_pos: vmath.vector3; + x: number; + y: number; + } + class DruidEvent { + clear(this: DruidEvent): void; + initialize(this: DruidEvent, initial_callback?: Function): void; + is_exist(this: DruidEvent): boolean; + subscribe(this: DruidEvent, callback: Function, context?: any): void; + trigger(this: DruidEvent, ...args: any[]): void; + unsubscribe(this: DruidEvent, callback: Function, context?: any): void; + } + class Hover { + init(this: Hover, node: node, on_hover_callback: Function): void; + is_enabled(this: Hover): boolean; + is_hovered(this: Hover): boolean; + is_mouse_hovered(this: Hover): boolean; + set_click_zone(this: Hover, zone: node): void; + set_enabled(this: Hover, state: boolean): void; + set_hover(this: Hover, state: boolean): void; + set_mouse_hover(this: Hover, state: boolean): void; + + on_hover: (this: Hover, state: boolean, hover_instance: any) => void; + on_mouse_hover: (this: Hover, state: boolean, hover_instance: any) => void; + } + class RichText { + clear(): void; + get_line_metric(): {}; + get_words(): {}; + init(this: RichText, template: string, nodes: node[]): void; + set_text( + this: RichText, + text: string, + ): { + words: {}; + line_metrics: {}; + }; + tagged(tag: string): {}; + + style: { + COLORS: {}; + ADJUST_STEPS: number; + ADJUST_SCALE_DELTA: number; + }; + } + class Scroll { + bind_grid(grid: DynamicGrid | StaticGrid): this; + get_percent(): vmath.vector3; + get_scroll_size(): vmath.vector3; + init(view_node: node | string, content_node: node | string): void; + is_inert(): boolean; + is_node_in_view(node: node): boolean; + scroll_to(point: vmath.vector3, is_instant?: boolean): void; + scroll_to_index(index: number, skip_cb?: boolean): void; + scroll_to_percent(percent: vmath.vector3, is_instant?: boolean): void; + set_click_zone(node: node): void; + set_extra_stretch_size(stretch_size?: number): this; + set_horizontal_scroll(state: boolean): this; + set_inert(state: boolean): this; + set_points(points: vmath.vector3[]): this; + set_size(size: vmath.vector3, offset: vmath.vector3): this; + set_vertical_scroll(state: boolean): this; + + style: { + FRICT: number; + FRICT_HOLD: number; + INERT_THRESHOLD: number; + INERT_SPEED: number; + POINTS_DEADZONE: number; + BACK_SPEED: number; + ANIM_SPEED: number; + EXTRA_STRETCH_SIZE: number; + SMALL_CONTENT_SCROLL: boolean; + WHEEL_SCROLL_SPEED: number; + WHEEL_SCROLL_INVERTED: boolean; + WHEEL_SCROLL_BY_INERTION: boolean; + }; + available_pos: vmath.vector4; + available_size: vmath.vector3; + content_node: node; + drag: Drag; + inertion: vmath.vector3; + is_animate: boolean; + // is_inert: boolean; + on_point_scroll: DruidEvent; + on_scroll: DruidEvent; + on_scroll_to: DruidEvent; + position: vmath.vector3; + selected: number; + target_position: vmath.vector3; + view_node: node; + } + class StaticGrid { + add( + this: StaticGrid, + item: node, + index?: number, + shift_policy?: number, + is_instant?: boolean, + ): void; + clear(this: StaticGrid): StaticGrid; + get_all_pos(this: StaticGrid): vmath.vector3[]; + get_borders(this: StaticGrid): vmath.vector3; + get_index(this: StaticGrid, pos: vmath.vector3): number; + get_index_by_node(this: StaticGrid, node: node): number; + get_offset(this: StaticGrid): vmath.vector3; + get_pos(this: StaticGrid, index: number): vmath.vector3; + get_size(this: StaticGrid): vmath.vector3; + init( + this: StaticGrid, + parent: node | string, + element: node, + in_row?: number, + ): void; + remove( + this: StaticGrid, + index: number, + shift_policy?: number, + is_instant?: boolean, + ): node; + set_anchor(this: StaticGrid, anchor: vmath.vector3): void; + set_in_row(this: StaticGrid, in_row: number): StaticGrid; + set_position_function(this: StaticGrid, callback: Function): StaticGrid; + + style: { + IS_DYNAMIC_NODE_POSES: boolean; + IS_ALIGN_LAST_ROW: boolean; + }; + anchor: vmath.vector3; + border: vmath.vector4; + first_index: number; + last_index: number; + node_size: vmath.vector3; + nodes: node[]; + on_add_item: DruidEvent; + on_change_items: DruidEvent; + on_clear: DruidEvent; + on_remove_item: DruidEvent; + on_update_positions: DruidEvent; + parent: node; + pivot: vmath.vector3; + } + class Text { + get_text_adjust(this: Text, adjust_type: any): number; + get_text_size(this: Text, text?: string): [number, number]; + init( + this: Text, + node: node | string, + value?: string, + adjust_type?: string, + ): void; + is_multiline(this: Text): boolean; + set_alpha(this: Text, alpha: number): Text; + set_color(this: Text, color: vmath.vector4): Text; + set_minimal_scale(this: Text, minimal_scale: number): Text; + set_pivot(this: Text, pivot: any): Text; + set_scale(this: Text, scale: vmath.vector3): Text; + set_text_adjust( + this: Text, + adjust_type?: number, + minimal_scale?: number, + ): Text; + set_to(this: Text, set_to: string): Text; + + style: { + TRIM_POSTFIX: string; + DEFAULT_ADJUST: string; + }; + adjust_type: number; + color: vmath.vector3; + node: node; + node_id: hash; + on_set_pivot: DruidEvent; + on_set_text: DruidEvent; + on_update_text_scale: DruidEvent; + pos: vmath.vector3; + scale: vmath.vector3; + start_scale: vmath.vector3; + start_size: vmath.vector3; + text_area: vmath.vector3; + } + export { type BackHandler }; + export { type Blocker }; + export { type Button }; + export { type Drag }; + export { type DruidEvent }; + export { type Hover }; + export { type RichText }; + export { type Scroll }; + export { type StaticGrid }; + export { type Text }; + + type Grid = DynamicGrid | StaticGrid; + + class DruidInstance { + final(): void; + new(component: Component, ...args: any[]): void; + new_back_handler( + callback: (...args: any[]) => void, + params?: any, + ): BackHandler; + new_blocker(node: node): Blocker; + new_button( + node: node, + callback: (...args: any[]) => void, + params?: any[], + anim_node?: node, + ): Button; + new_checkbox( + node: node, + callback: (...args: any[]) => void, + click_node?: node, + initial_state?: boolean, + ): Checkbox; + new_checkbox_group( + nodes: node[], + callback: (...args: any[]) => void, + click_nodes?: node[], + ): CheckboxGroup; + new_data_list( + druid_scroll: Scroll, + druid_grid: Grid, + create_function: ( + data: any, + index: number, + data_list: DataList, + ) => [node, Component], + ): DataList; + new_drag( + node: node, + on_drag_callback: (dx: number, dy: number) => void, + ): Drag; + new_dynamic_grid(parent: node): DynamicGrid; + new_hotkey( + keys_array: string[] | string, + callback: (...args: any[]) => void, + params?: any, + ): Hotkey; + new_hover(node: node, on_hover_callback: (...args: any[]) => void): Hover; + new_input(click_node: node, text_node: node, keyboard_type?: number): Input; + new_lang_text(node: node, locale_id: string, no_adjust: boolean): LangText; + new_layout(node: node | string, mode: string): Layout; + new_progress( + node: node | string, + key: string, + init_value?: number, + ): Progress; + new_radio_group( + nodes: node[], + callback: (...args: any[]) => void, + click_nodes?: node[], + ): RadioGroup; + new_rich_text(template?: string, nodes?: any): RichText; + new_scroll(view_node: node, content_node: node): Scroll; + new_slider( + node: node, + end_pos: vmath.vector3, + callback?: (...args: any[]) => void, + ): Slider; + new_static_grid(parent: node, element: node, in_row?: number): StaticGrid; + new_swipe(node: node, on_swipe_callback: (...args: any[]) => void): Swipe; + new_text(node: node, value?: string, no_adjust?: boolean): Text; + new_timer( + node: node, + seconds_from: number, + seconds_to?: number, + callback?: (...args: any[]) => void, + ): Timer; + on_input(action_id: hash, action: any): boolean; + on_message(message_id: hash, message: any, sender: hash): void; + remove(component: Component): void; + set_blacklist(blacklist_components?: any[] | Component): DruidInstance; + set_whitelist(whitelist_components?: any[] | Component): DruidInstance; + update(dt: number): void; + } + export { type DruidInstance }; + + type DruidExtendedModule = + | Checkbox + | CheckboxGroup + | DataList + | DynamicGrid + | Hotkey + | Input + | LangText + | Layout + | Progress + | RadioGroup + | Slider + | Swipe + | Timer; + + export function on_language_change(this: void): void; + export function on_window_callback(this: void, event: string): void; + export function register( + this: void, + name: string, + module: DruidExtendedModule, + ): void; + export function set_default_style(this: void, style: any): void; + export function set_sound_function( + this: void, + callback: (this: void, sound_id: unknown) => void, + ): void; + export function set_text_function( + this: void, + callback: (this: void, text_id: unknown) => void, + ): void; + function ___new(this: void, context: any, style?: any): DruidInstance; + export { ___new as new }; +} diff --git a/packages/druid/druid.extended.checkbox.d.ts b/packages/druid/druid.extended.checkbox.d.ts new file mode 100644 index 0000000..99fe3f6 --- /dev/null +++ b/packages/druid/druid.extended.checkbox.d.ts @@ -0,0 +1,33 @@ +/** + * This is a definition stub with incomplete or untested signatures. + * Contributions are welcome to improve the accuracy of these types. + * @url https://github.com/ts-defold/library + * @url https://insality.github.io/druid/modules/Druid.html + * @noResolution + */ +declare module 'druid.extended.checkbox' { + export function get_state(this: Checkbox): boolean[]; + export function init( + this: Checkbox, + nodes: node, + callback: (...args: any[]) => any, + click_nodes?: node, + initial_state?: boolean, + ): void; + export function set_state( + this: Checkbox, + state: boolean, + is_silent: boolean, + is_instant: boolean, + ): void; + + export const style: { + on_change_state: (this: Checkbox, node: node, state: boolean) => void; + }; + export const button: typeof import('druid.druid').Button; + export const click_node: node; + export const node: node; + export const on_change_state: typeof import('druid.druid').DruidEvent; +} + +type Checkbox = typeof import('druid.extended.checkbox'); diff --git a/packages/druid/druid.extended.checkbox_group.d.ts b/packages/druid/druid.extended.checkbox_group.d.ts new file mode 100644 index 0000000..002045a --- /dev/null +++ b/packages/druid/druid.extended.checkbox_group.d.ts @@ -0,0 +1,26 @@ +/** + * This is a definition stub with incomplete or untested signatures. + * Contributions are welcome to improve the accuracy of these types. + * @url https://github.com/ts-defold/library + * @url https://insality.github.io/druid/modules/Druid.html + * @noResolution + */ +declare module 'druid.extended.checkbox_group' { + export function get_state(this: CheckboxGroup): boolean[]; + export function init( + this: CheckboxGroup, + nodes: node[], + callback: (...args: any[]) => any, + click_nodes?: node[], + ): void; + export function set_state( + this: CheckboxGroup, + indexes: boolean[], + is_instant: boolean, + ): void; + + export const checkboxes: CheckboxGroup[]; + export const on_checkbox_click: (this: any, index: number) => void; +} + +type CheckboxGroup = typeof import('druid.extended.checkbox_group'); diff --git a/packages/druid/druid.extended.data_list.d.ts b/packages/druid/druid.extended.data_list.d.ts new file mode 100644 index 0000000..f8daefc --- /dev/null +++ b/packages/druid/druid.extended.data_list.d.ts @@ -0,0 +1,45 @@ +/** + * This is a definition stub with incomplete or untested signatures. + * Contributions are welcome to improve the accuracy of these types. + * @url https://github.com/ts-defold/library + * @url https://insality.github.io/druid/modules/Druid.html + * @noResolution + */ +declare module 'druid.extended.data_list' { + export function clear(this: DataList): void; + export function get_created_components(this: DataList): Component[]; + export function get_created_nodes(this: DataList): node[]; + export function get_data(this: DataList): {}; + export function get_first_index(this: DataList): number; + export function get_index(this: DataList, data: {}): number; + export function get_last_index(this: DataList): number; + export function get_length(this: DataList): number; + export function init( + this: DataList, + scroll: typeof import('druid.druid').Scroll, + grid: DynamicGrid | typeof import('druid.druid').StaticGrid, + create_function: Function, + ): void; + export function on_remove(this: DataList): void; + export function scroll_to_index(this: DataList, index: number): void; + export function set_data(this: DataList, data: {}): DataList; + + export const grid: DynamicGrid | typeof import('druid.druid').StaticGrid; + export const last_index: number; + export const on_element_add: ( + this: void, + index: number, + node: node, + instance: any, + ) => void; + export const on_element_remove: (this: void, index: number) => void; + export const on_scroll_progress_change: ( + this: void, + progress_value: number, + ) => void; + export const scroll: typeof import('druid.druid').Scroll; + export const scroll_progress: number; + export const top_index: number; +} + +type DataList = typeof import('druid.extended.data_list'); diff --git a/packages/druid/druid.extended.dynamic_grid.d.ts b/packages/druid/druid.extended.dynamic_grid.d.ts new file mode 100644 index 0000000..4003689 --- /dev/null +++ b/packages/druid/druid.extended.dynamic_grid.d.ts @@ -0,0 +1,61 @@ +/** + * This is a definition stub with incomplete or untested signatures. + * Contributions are welcome to improve the accuracy of these types. + * @url https://github.com/ts-defold/library + * @url https://insality.github.io/druid/modules/Druid.html + * @noResolution + */ +declare module 'druid.extended.dynamic_grid' { + export function _get_side_vector( + this: DynamicGrid, + side: any, + is_forward: any, + ): unknown; + export function add( + this: DynamicGrid, + node: node, + index?: number, + shift_policy?: number, + is_instant?: boolean, + ): void; + export function clear(this: DynamicGrid): DynamicGrid; + export function get_all_pos(this: DynamicGrid): vmath.vector3[]; + export function get_borders(this: DynamicGrid): vmath.vector3; + export function get_index_by_node(this: DynamicGrid, node: node): number; + export function get_offset(this: DynamicGrid): vmath.vector3; + export function get_pos( + this: DynamicGrid, + index: number, + node: node, + origin_index?: number, + ): vmath.vector3; + export function get_size( + this: DynamicGrid, + border: vmath.vector3, + ): vmath.vector3; + export function init(this: DynamicGrid, parent: node): void; + export function remove( + this: DynamicGrid, + index: number, + shift_policy?: number, + is_instant?: boolean, + ): node; + export function set_position_function( + this: DynamicGrid, + callback: Function, + ): DynamicGrid; + + export const border: vmath.vector4; + export const first_index: number; + export const last_index: number; + export const node_size: vmath.vector3; + export const nodes: node[]; + export const on_add_item: typeof import('druid.druid').DruidEvent; + export const on_change_items: typeof import('druid.druid').DruidEvent; + export const on_clear: typeof import('druid.druid').DruidEvent; + export const on_remove_item: typeof import('druid.druid').DruidEvent; + export const on_update_positions: typeof import('druid.druid').DruidEvent; + export const parent: node; +} + +type DynamicGrid = typeof import('druid.extended.dynamic_grid'); diff --git a/packages/druid/druid.extended.hotkey.d.ts b/packages/druid/druid.extended.hotkey.d.ts new file mode 100644 index 0000000..f2c1ec7 --- /dev/null +++ b/packages/druid/druid.extended.hotkey.d.ts @@ -0,0 +1,28 @@ +/** + * This is a definition stub with incomplete or untested signatures. + * Contributions are welcome to improve the accuracy of these types. + * @url https://github.com/ts-defold/library + * @url https://insality.github.io/druid/modules/Druid.html + * @noResolution + */ +declare module 'druid.extended.hotkey' { + export function add_hotkey( + this: Hotkey, + keys: Record | string[] | string, + callback_argument?: any, + ): void; + export function init( + this: Hotkey, + keys: string[] | string, + callback: (...args: any[]) => void, + callback_argument?: any, + ): void; + + export const style: { MODIFICATORS: string[] }; + export const button: import('druid.druid').Button; + export const click_node: node; + export const node: node; + export const on_change_state: typeof import('druid.druid').DruidEvent; +} + +type Hotkey = typeof import('druid.extended.hotkey'); diff --git a/packages/druid/druid.extended.input.d.ts b/packages/druid/druid.extended.input.d.ts new file mode 100644 index 0000000..4635afb --- /dev/null +++ b/packages/druid/druid.extended.input.d.ts @@ -0,0 +1,50 @@ +/** + * This is a definition stub with incomplete or untested signatures. + * Contributions are welcome to improve the accuracy of these types. + * @url https://github.com/ts-defold/library + * @url https://insality.github.io/druid/modules/Druid.html + * @noResolution + */ +declare module 'druid.extended.input' { + export function get_text(this: Input): string; + export function init( + this: Input, + click_node: node, + text_node: node | import('druid.druid').Text, + keyboard_type?: number, + ): void; + export function reset_changes(this: Input): void; + export function select(this: Input): void; + export function set_allowed_characters( + this: Input, + characters: string, + ): Input; + export function set_max_length(this: Input, max_length: number | null): Input; + export function set_text(this: Input, input_text: string): void; + export function unselect(this: Input): void; + export const style: { + IS_LONGTAP_ERASE: boolean; + MASK_DEFAULT_CHAR: string; + IS_UNSELECT_ON_RESELECT: boolean; + NO_CONSUME_INPUT_WHILE_SELECTED: boolean; + on_select: (this: Input, button_node: node) => void; + on_unselect: (this: Input, button_node: node) => void; + on_input_wrong: (this: Input, button_node: node) => void; + button_style: {}; + }; + export const allowerd_characters: string | undefined; + export const button: import('druid.druid').Button; + export const is_empty: boolean; + export const is_selected: boolean; + export const keyboard_type: number; + export const max_length: number | undefined; + export const on_input_empty: import('druid.druid').DruidEvent; + export const on_input_full: import('druid.druid').DruidEvent; + export const on_input_select: import('druid.druid').DruidEvent; + export const on_input_text: import('druid.druid').DruidEvent; + export const on_input_unselect: import('druid.druid').DruidEvent; + export const on_input_wrong: import('druid.druid').DruidEvent; + export const text: import('druid.druid').Text; +} + +type Input = typeof import('druid.extended.input'); diff --git a/packages/druid/druid.extended.lang_text.d.ts b/packages/druid/druid.extended.lang_text.d.ts new file mode 100644 index 0000000..6e70a24 --- /dev/null +++ b/packages/druid/druid.extended.lang_text.d.ts @@ -0,0 +1,42 @@ +/** + * This is a definition stub with incomplete or untested signatures. + * Contributions are welcome to improve the accuracy of these types. + * @url https://github.com/ts-defold/library + * @url https://insality.github.io/druid/modules/Druid.html + * @noResolution + */ +declare module 'druid.extended.lang_text' { + export function format( + this: LangText, + a?: string, + b?: string, + c?: string, + d?: string, + e?: string, + f?: string, + g?: string, + ): LangText; + export function init( + this: LangText, + node: node | string, + locale_id: string, + adjust_type?: string, + ): void; + export function set_to(this: LangText, text: string): LangText; + export function translate( + this: LangText, + locale_id: string, + a?: string, + b?: string, + c?: string, + d?: string, + e?: string, + f?: string, + g?: string, + ): LangText; + + const on_change: import('druid.druid').DruidEvent; + const text: import('druid.druid').Text; +} + +type LangText = typeof import('druid.extended.lang_text'); diff --git a/packages/druid/druid.extended.layout.d.ts b/packages/druid/druid.extended.layout.d.ts new file mode 100644 index 0000000..1a3ec60 --- /dev/null +++ b/packages/druid/druid.extended.layout.d.ts @@ -0,0 +1,43 @@ +/** + * This is a definition stub with incomplete or untested signatures. + * Contributions are welcome to improve the accuracy of these types. + * @url https://github.com/ts-defold/library + * @url https://insality.github.io/druid/modules/Druid.html + * @noResolution + */ +declare module 'druid.extended.layout' { + export function fit_into_node(this: Layout, node?: node): Layout; + export function fit_into_size( + this: Layout, + target_size: vmath.vector3, + ): Layout; + export function fit_into_window(this: Layout): Layout; + export function init( + this: Layout, + node: node, + mode: string, + on_size_changed_callback?: () => void, + ): void; + export function set_max_gui_upscale( + this: Layout, + max_gui_upscale: number, + ): Layout; + export function set_max_size(this: Layout, max_size: vmath.vector3): Layout; + export function set_min_size(this: Layout, min_size: vmath.vector3): Layout; + export function set_origin_position( + this: Layout, + new_origin_position: vmath.vector3, + ): Layout; + export function set_origin_size( + this: Layout, + new_origin_size: vmath.vector3, + ): Layout; + + export const mode: string; + export const node: node; + export const on_size_changed: ( + new_size: import('druid.druid').DruidEvent, + ) => void; +} + +type Layout = typeof import('druid.extended.layout'); diff --git a/packages/druid/druid.extended.progress.d.ts b/packages/druid/druid.extended.progress.d.ts new file mode 100644 index 0000000..14b1cd0 --- /dev/null +++ b/packages/druid/druid.extended.progress.d.ts @@ -0,0 +1,43 @@ +/** + * This is a definition stub with incomplete or untested signatures. + * Contributions are welcome to improve the accuracy of these types. + * @url https://github.com/ts-defold/library + * @url https://insality.github.io/druid/modules/Druid.html + * @noResolution + */ +declare module 'druid.extended.progress' { + export function empty(this: Progress): void; + export function fill(this: Progress): void; + export function get(this: Progress): number; + export function init( + this: Progress, + node: node | string, + key: string, + init_value?: number, + ): void; + export function set_max_size( + this: Progress, + max_size: vmath.vector3, + ): Progress; + export function set_steps( + this: Progress, + steps: number[], + callback: (this: Progress, step: number) => void, + ): void; + export function set_to(this: Progress, to: number): void; + export function to( + this: Progress, + to: number, + callback?: (this: Progress) => void, + ): void; + + export const key: string; + export const max_size: number; + export const node: node; + export const on_change: (this: Progress, new_value: number) => void; + export const scale: vmath.vector3; + export const size: vmath.vector3; + export const slice: vmath.vector4; +} + +type Progress = typeof import('druid.extended.progress'); diff --git a/packages/druid/druid.extended.radio_group.d.ts b/packages/druid/druid.extended.radio_group.d.ts new file mode 100644 index 0000000..c875b05 --- /dev/null +++ b/packages/druid/druid.extended.radio_group.d.ts @@ -0,0 +1,26 @@ +/** + * This is a definition stub with incomplete or untested signatures. + * Contributions are welcome to improve the accuracy of these types. + * @url https://github.com/ts-defold/library + * @url https://insality.github.io/druid/modules/Druid.html + * @noResolution + */ +declare module 'druid.extended.radio_group' { + export function get_state(this: RadioGroup): number; + export function init( + this: RadioGroup, + nodes: node[], + callback: Function, + click_nodes?: node[], + ): void; + export function set_state( + this: RadioGroup, + index: number, + is_instant: boolean, + ): void; + + export const checkboxes: Checkbox[]; + export const on_radio_click: import('druid.druid').DruidEvent; +} + +type RadioGroup = typeof import('druid.extended.radio_group'); diff --git a/packages/druid/druid.extended.slider.d.ts b/packages/druid/druid.extended.slider.d.ts new file mode 100644 index 0000000..22f107b --- /dev/null +++ b/packages/druid/druid.extended.slider.d.ts @@ -0,0 +1,30 @@ +/** + * This is a definition stub with incomplete or untested signatures. + * Contributions are welcome to improve the accuracy of these types. + * @url https://github.com/ts-defold/library + * @url https://insality.github.io/druid/modules/Druid.html + * @noResolution + */ +declare module 'druid.extended.slider' { + export function init( + this: Slider, + node: node, + end_pos: vmath.vector3, + callback?: Function, + ): void; + export function set(this: Slider, value: number, is_silent?: boolean): void; + export function set_input_node(this: Slider, input_node: node): Slider; + export function set_steps(this: Slider, steps: number[]): Slider; + + export const dist: number; + export const end_pos: vmath.vector3; + export const is_drag: boolean; + export const node: node; + export const on_change_value: import('druid.druid').DruidEvent; + export const pos: vmath.vector3; + export const start_pos: vmath.vector3; + export const target_pos: vmath.vector3; + export const value: number; +} + +type Slider = typeof import('druid.extended.slider'); diff --git a/packages/druid/druid.extended.swipe.d.ts b/packages/druid/druid.extended.swipe.d.ts new file mode 100644 index 0000000..04ee282 --- /dev/null +++ b/packages/druid/druid.extended.swipe.d.ts @@ -0,0 +1,32 @@ +/** + * This is a definition stub with incomplete or untested signatures. + * Contributions are welcome to improve the accuracy of these types. + * @url https://github.com/ts-defold/library + * @url https://insality.github.io/druid/modules/Druid.html + * @noResolution + */ +declare module 'druid.extended.swipe' { + export function init( + this: Swipe, + node: node, + on_swipe_callback: (swipe: Swipe) => void, + ): void; + export function set_click_zone(this: Swipe, zone: node): void; + + export const style: { + SWIPE_TIME: number; + SWIPE_THRESHOLD: number; + SWIPE_TRIGGER_ON_MOVE: boolean; + }; + + export const click_zone: node | undefined; + export const node: node; + export const on_swipe: ( + this: Swipe, + swipe_side: string, + dist: number, + delta_time: number, + ) => void; +} + +type Swipe = typeof import('druid.extended.swipe'); diff --git a/packages/druid/druid.extended.timer.d.ts b/packages/druid/druid.extended.timer.d.ts new file mode 100644 index 0000000..2d1ddb8 --- /dev/null +++ b/packages/druid/druid.extended.timer.d.ts @@ -0,0 +1,35 @@ +/** + * This is a definition stub with incomplete or untested signatures. + * Contributions are welcome to improve the accuracy of these types. + * @url https://github.com/ts-defold/library + * @url https://insality.github.io/druid/modules/Druid.html + * @noResolution + */ +declare module 'druid.extended.timer' { + export function init( + this: Timer, + node: node, + seconds_from: number, + seconds_to?: number, + callback?: Function, + ): void; + export function set_interval(this: Timer, from: number, to: number): void; + export function set_state(this: Timer, is_on: boolean): void; + export function set_to(this: Timer, set_to: number): void; + + export const from: number; + export const node: node; + export const on_set_enabled: ( + this: Timer, + is_enabled: import('druid.druid').DruidEvent, + ) => void; + export const on_tick: ( + this: Timer, + value: import('druid.druid').DruidEvent, + ) => void; + export const on_timer_end: (this: Timer) => import('druid.druid').DruidEvent; + export const target: number; + export const value: number; +} + +type Timer = typeof import('druid.extended.timer'); diff --git a/packages/druid/library.json b/packages/druid/library.json new file mode 100644 index 0000000..4cf0d18 --- /dev/null +++ b/packages/druid/library.json @@ -0,0 +1,4 @@ +{ + "name": "druid", + "url": "https://github.com/Insality/druid" +} From f618e01fcfc08101db32eaecabd6a32543a75309 Mon Sep 17 00:00:00 2001 From: thinknathan Date: Thu, 4 Jul 2024 17:17:28 -0700 Subject: [PATCH 2/9] chore: update jsdoc comment style --- packages/druid/druid.druid.d.ts | 4 ++-- packages/druid/druid.extended.checkbox.d.ts | 4 ++-- packages/druid/druid.extended.checkbox_group.d.ts | 4 ++-- packages/druid/druid.extended.data_list.d.ts | 4 ++-- packages/druid/druid.extended.dynamic_grid.d.ts | 4 ++-- packages/druid/druid.extended.hotkey.d.ts | 4 ++-- packages/druid/druid.extended.input.d.ts | 4 ++-- packages/druid/druid.extended.lang_text.d.ts | 4 ++-- packages/druid/druid.extended.layout.d.ts | 4 ++-- packages/druid/druid.extended.progress.d.ts | 4 ++-- packages/druid/druid.extended.radio_group.d.ts | 4 ++-- packages/druid/druid.extended.slider.d.ts | 4 ++-- packages/druid/druid.extended.swipe.d.ts | 4 ++-- packages/druid/druid.extended.timer.d.ts | 4 ++-- 14 files changed, 28 insertions(+), 28 deletions(-) diff --git a/packages/druid/druid.druid.d.ts b/packages/druid/druid.druid.d.ts index 5a3adc7..34419c2 100644 --- a/packages/druid/druid.druid.d.ts +++ b/packages/druid/druid.druid.d.ts @@ -3,8 +3,8 @@ type Component = {}; /** * This is a definition stub with incomplete or untested signatures. * Contributions are welcome to improve the accuracy of these types. - * @url https://github.com/ts-defold/library - * @url https://insality.github.io/druid/modules/Druid.html + * @see {@link https://github.com/ts-defold/library|Github Source} + * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} * @noResolution */ declare module 'druid.druid' { diff --git a/packages/druid/druid.extended.checkbox.d.ts b/packages/druid/druid.extended.checkbox.d.ts index 99fe3f6..c6341e5 100644 --- a/packages/druid/druid.extended.checkbox.d.ts +++ b/packages/druid/druid.extended.checkbox.d.ts @@ -1,8 +1,8 @@ /** * This is a definition stub with incomplete or untested signatures. * Contributions are welcome to improve the accuracy of these types. - * @url https://github.com/ts-defold/library - * @url https://insality.github.io/druid/modules/Druid.html + * @see {@link https://github.com/ts-defold/library|Github Source} + * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} * @noResolution */ declare module 'druid.extended.checkbox' { diff --git a/packages/druid/druid.extended.checkbox_group.d.ts b/packages/druid/druid.extended.checkbox_group.d.ts index 002045a..f3988d2 100644 --- a/packages/druid/druid.extended.checkbox_group.d.ts +++ b/packages/druid/druid.extended.checkbox_group.d.ts @@ -1,8 +1,8 @@ /** * This is a definition stub with incomplete or untested signatures. * Contributions are welcome to improve the accuracy of these types. - * @url https://github.com/ts-defold/library - * @url https://insality.github.io/druid/modules/Druid.html + * @see {@link https://github.com/ts-defold/library|Github Source} + * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} * @noResolution */ declare module 'druid.extended.checkbox_group' { diff --git a/packages/druid/druid.extended.data_list.d.ts b/packages/druid/druid.extended.data_list.d.ts index f8daefc..854b5a7 100644 --- a/packages/druid/druid.extended.data_list.d.ts +++ b/packages/druid/druid.extended.data_list.d.ts @@ -1,8 +1,8 @@ /** * This is a definition stub with incomplete or untested signatures. * Contributions are welcome to improve the accuracy of these types. - * @url https://github.com/ts-defold/library - * @url https://insality.github.io/druid/modules/Druid.html + * @see {@link https://github.com/ts-defold/library|Github Source} + * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} * @noResolution */ declare module 'druid.extended.data_list' { diff --git a/packages/druid/druid.extended.dynamic_grid.d.ts b/packages/druid/druid.extended.dynamic_grid.d.ts index 4003689..07ae188 100644 --- a/packages/druid/druid.extended.dynamic_grid.d.ts +++ b/packages/druid/druid.extended.dynamic_grid.d.ts @@ -1,8 +1,8 @@ /** * This is a definition stub with incomplete or untested signatures. * Contributions are welcome to improve the accuracy of these types. - * @url https://github.com/ts-defold/library - * @url https://insality.github.io/druid/modules/Druid.html + * @see {@link https://github.com/ts-defold/library|Github Source} + * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} * @noResolution */ declare module 'druid.extended.dynamic_grid' { diff --git a/packages/druid/druid.extended.hotkey.d.ts b/packages/druid/druid.extended.hotkey.d.ts index f2c1ec7..11b6a32 100644 --- a/packages/druid/druid.extended.hotkey.d.ts +++ b/packages/druid/druid.extended.hotkey.d.ts @@ -1,8 +1,8 @@ /** * This is a definition stub with incomplete or untested signatures. * Contributions are welcome to improve the accuracy of these types. - * @url https://github.com/ts-defold/library - * @url https://insality.github.io/druid/modules/Druid.html + * @see {@link https://github.com/ts-defold/library|Github Source} + * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} * @noResolution */ declare module 'druid.extended.hotkey' { diff --git a/packages/druid/druid.extended.input.d.ts b/packages/druid/druid.extended.input.d.ts index 4635afb..9d1353d 100644 --- a/packages/druid/druid.extended.input.d.ts +++ b/packages/druid/druid.extended.input.d.ts @@ -1,8 +1,8 @@ /** * This is a definition stub with incomplete or untested signatures. * Contributions are welcome to improve the accuracy of these types. - * @url https://github.com/ts-defold/library - * @url https://insality.github.io/druid/modules/Druid.html + * @see {@link https://github.com/ts-defold/library|Github Source} + * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} * @noResolution */ declare module 'druid.extended.input' { diff --git a/packages/druid/druid.extended.lang_text.d.ts b/packages/druid/druid.extended.lang_text.d.ts index 6e70a24..e14c143 100644 --- a/packages/druid/druid.extended.lang_text.d.ts +++ b/packages/druid/druid.extended.lang_text.d.ts @@ -1,8 +1,8 @@ /** * This is a definition stub with incomplete or untested signatures. * Contributions are welcome to improve the accuracy of these types. - * @url https://github.com/ts-defold/library - * @url https://insality.github.io/druid/modules/Druid.html + * @see {@link https://github.com/ts-defold/library|Github Source} + * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} * @noResolution */ declare module 'druid.extended.lang_text' { diff --git a/packages/druid/druid.extended.layout.d.ts b/packages/druid/druid.extended.layout.d.ts index 1a3ec60..22a9991 100644 --- a/packages/druid/druid.extended.layout.d.ts +++ b/packages/druid/druid.extended.layout.d.ts @@ -1,8 +1,8 @@ /** * This is a definition stub with incomplete or untested signatures. * Contributions are welcome to improve the accuracy of these types. - * @url https://github.com/ts-defold/library - * @url https://insality.github.io/druid/modules/Druid.html + * @see {@link https://github.com/ts-defold/library|Github Source} + * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} * @noResolution */ declare module 'druid.extended.layout' { diff --git a/packages/druid/druid.extended.progress.d.ts b/packages/druid/druid.extended.progress.d.ts index 14b1cd0..ce33ca4 100644 --- a/packages/druid/druid.extended.progress.d.ts +++ b/packages/druid/druid.extended.progress.d.ts @@ -1,8 +1,8 @@ /** * This is a definition stub with incomplete or untested signatures. * Contributions are welcome to improve the accuracy of these types. - * @url https://github.com/ts-defold/library - * @url https://insality.github.io/druid/modules/Druid.html + * @see {@link https://github.com/ts-defold/library|Github Source} + * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} * @noResolution */ declare module 'druid.extended.progress' { diff --git a/packages/druid/druid.extended.radio_group.d.ts b/packages/druid/druid.extended.radio_group.d.ts index c875b05..139eb17 100644 --- a/packages/druid/druid.extended.radio_group.d.ts +++ b/packages/druid/druid.extended.radio_group.d.ts @@ -1,8 +1,8 @@ /** * This is a definition stub with incomplete or untested signatures. * Contributions are welcome to improve the accuracy of these types. - * @url https://github.com/ts-defold/library - * @url https://insality.github.io/druid/modules/Druid.html + * @see {@link https://github.com/ts-defold/library|Github Source} + * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} * @noResolution */ declare module 'druid.extended.radio_group' { diff --git a/packages/druid/druid.extended.slider.d.ts b/packages/druid/druid.extended.slider.d.ts index 22f107b..c2b8b42 100644 --- a/packages/druid/druid.extended.slider.d.ts +++ b/packages/druid/druid.extended.slider.d.ts @@ -1,8 +1,8 @@ /** * This is a definition stub with incomplete or untested signatures. * Contributions are welcome to improve the accuracy of these types. - * @url https://github.com/ts-defold/library - * @url https://insality.github.io/druid/modules/Druid.html + * @see {@link https://github.com/ts-defold/library|Github Source} + * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} * @noResolution */ declare module 'druid.extended.slider' { diff --git a/packages/druid/druid.extended.swipe.d.ts b/packages/druid/druid.extended.swipe.d.ts index 04ee282..fcc8b5a 100644 --- a/packages/druid/druid.extended.swipe.d.ts +++ b/packages/druid/druid.extended.swipe.d.ts @@ -1,8 +1,8 @@ /** * This is a definition stub with incomplete or untested signatures. * Contributions are welcome to improve the accuracy of these types. - * @url https://github.com/ts-defold/library - * @url https://insality.github.io/druid/modules/Druid.html + * @see {@link https://github.com/ts-defold/library|Github Source} + * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} * @noResolution */ declare module 'druid.extended.swipe' { diff --git a/packages/druid/druid.extended.timer.d.ts b/packages/druid/druid.extended.timer.d.ts index 2d1ddb8..a84320a 100644 --- a/packages/druid/druid.extended.timer.d.ts +++ b/packages/druid/druid.extended.timer.d.ts @@ -1,8 +1,8 @@ /** * This is a definition stub with incomplete or untested signatures. * Contributions are welcome to improve the accuracy of these types. - * @url https://github.com/ts-defold/library - * @url https://insality.github.io/druid/modules/Druid.html + * @see {@link https://github.com/ts-defold/library|Github Source} + * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} * @noResolution */ declare module 'druid.extended.timer' { From b31eef52ac2e30a068c86bfe9fa3b81a5c7410a1 Mon Sep 17 00:00:00 2001 From: thinknathan Date: Fri, 19 Jul 2024 18:17:29 -0700 Subject: [PATCH 3/9] fix: add missing multi return --- packages/druid/druid.druid.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/druid/druid.druid.d.ts b/packages/druid/druid.druid.d.ts index 34419c2..3f819ab 100644 --- a/packages/druid/druid.druid.d.ts +++ b/packages/druid/druid.druid.d.ts @@ -226,7 +226,7 @@ declare module 'druid.druid' { } class Text { get_text_adjust(this: Text, adjust_type: any): number; - get_text_size(this: Text, text?: string): [number, number]; + get_text_size(this: Text, text?: string): LuaMultiReturn<[number, number]>; init( this: Text, node: node | string, @@ -308,7 +308,7 @@ declare module 'druid.druid' { data: any, index: number, data_list: DataList, - ) => [node, Component], + ) => LuaMultiReturn<[node, Component | undefined]>, ): DataList; new_drag( node: node, From 7e8e86d572a72af2244d1e553256e7d8bc7302ae Mon Sep 17 00:00:00 2001 From: thinknathan Date: Fri, 19 Jul 2024 18:55:28 -0700 Subject: [PATCH 4/9] feat: add druid const and helper --- packages/druid/druid-0.11.0.d.ts | 2 + packages/druid/druid.const.d.ts | 103 +++++++++++++++++++++++++++++++ packages/druid/druid.helper.d.ts | 69 +++++++++++++++++++++ 3 files changed, 174 insertions(+) create mode 100644 packages/druid/druid.const.d.ts create mode 100644 packages/druid/druid.helper.d.ts diff --git a/packages/druid/druid-0.11.0.d.ts b/packages/druid/druid-0.11.0.d.ts index bfe2bcd..6523239 100644 --- a/packages/druid/druid-0.11.0.d.ts +++ b/packages/druid/druid-0.11.0.d.ts @@ -1,4 +1,5 @@ /// +/// /// /// /// @@ -13,3 +14,4 @@ /// /// /// +/// diff --git a/packages/druid/druid.const.d.ts b/packages/druid/druid.const.d.ts new file mode 100644 index 0000000..03404b9 --- /dev/null +++ b/packages/druid/druid.const.d.ts @@ -0,0 +1,103 @@ +/** + * This is a definition stub with incomplete or untested signatures. + * Contributions are welcome to improve the accuracy of these types. + * @see {@link https://github.com/ts-defold/library|Github Source} + * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} + * @noResolution + */ +declare module 'druid.const' { + type PivotKey = + | typeof gui.PIVOT_CENTER + | typeof gui.PIVOT_E + | typeof gui.PIVOT_N + | typeof gui.PIVOT_NE + | typeof gui.PIVOT_NW + | typeof gui.PIVOT_S + | typeof gui.PIVOT_SE + | typeof gui.PIVOT_SW + | typeof gui.PIVOT_W; + + export const ACTION_TEXT: hash; + export const ACTION_TOUCH: hash; + export const ACTION_MARKED_TEXT: hash; + export const ACTION_ESC: hash; + export const ACTION_BACK: hash; + export const ACTION_ENTER: hash; + export const ACTION_MULTITOUCH: hash; + export const ACTION_BACKSPACE: hash; + export const ACTION_SCROLL_UP: hash; + export const ACTION_SCROLL_DOWN: hash; + export const IS_STENCIL_CHECK: boolean; + export const ON_INPUT: string; + export const ON_UPDATE: string; + export const ON_MESSAGE: string; + export const ON_LATE_INIT: string; + export const ON_FOCUS_LOST: string; + export const ON_FOCUS_GAINED: string; + export const ON_LAYOUT_CHANGE: string; + export const ON_MESSAGE_INPUT: string; + export const ON_WINDOW_RESIZED: string; + export const ON_LANGUAGE_CHANGE: string; + export const PRIORITY_INPUT: number; + export const PRIORITY_INPUT_HIGH: number; + export const PRIORITY_INPUT_MAX: number; + export const MESSAGE_INPUT: { + BUTTON_CLICK: string; + BUTTON_LONG_CLICK: string; + BUTTON_DOUBLE_CLICK: string; + BUTTON_REPEATED_CLICK: string; + TEXT_SET: string; + }; + export const PIVOTS: { + [key: PivotKey]: vmath.vector3; + }; + export const REVERSE_PIVOTS: { + [key: PivotKey]: string; + }; + export const LAYOUT_MODE: { + STRETCH_X: string; + STRETCH_Y: string; + ZOOM_MIN: string; + ZOOM_MAX: string; + FIT: typeof gui.ADJUST_FIT; + STRETCH: typeof gui.ADJUST_STRETCH; + }; + export const VECTOR_ZERO: vmath.vector3; + export const SYS_INFO: ReturnType; + export const CURRENT_SYSTEM_NAME: string; + export const OS: { + ANDROID: string; + IOS: string; + MAC: string; + LINUX: string; + WINDOWS: string; + BROWSER: string; + }; + export const SHIFT: { + NO_SHIFT: number; + LEFT: number; + RIGHT: number; + }; + export const TEXT_ADJUST: { + DOWNSCALE: string; + TRIM: string; + NO_ADJUST: string; + DOWNSCALE_LIMITED: string; + SCROLL: string; + SCALE_THEN_SCROLL: string; + }; + export const SIDE: { + X: string; + Y: string; + }; + export const SWIPE: { + UP: string; + DOWN: string; + LEFT: string; + RIGHT: string; + }; + export const ERRORS: { + GRID_DYNAMIC_ANCHOR: string; + }; + export const EMPTY_FUNCTION: () => void; +} diff --git a/packages/druid/druid.helper.d.ts b/packages/druid/druid.helper.d.ts new file mode 100644 index 0000000..fe80a66 --- /dev/null +++ b/packages/druid/druid.helper.d.ts @@ -0,0 +1,69 @@ +/** + * This is a definition stub with incomplete or untested signatures. + * Contributions are welcome to improve the accuracy of these types. + * @see {@link https://github.com/ts-defold/library|Github Source} + * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} + * @noResolution + */ +declare module 'druid.helper' { + type Pivot = + | typeof gui.PIVOT_CENTER + | typeof gui.PIVOT_E + | typeof gui.PIVOT_N + | typeof gui.PIVOT_NE + | typeof gui.PIVOT_NW + | typeof gui.PIVOT_S + | typeof gui.PIVOT_SE + | typeof gui.PIVOT_SW + | typeof gui.PIVOT_W; + + export function add_array(target: T1[], source?: T2[]): (T1 | T2)[]; + export function centrate_nodes(margin?: number, ...nodes: node[]): void; + export function clamp(a: number, min: number, max: number): number; + export function contains(t: any[], value: any): number | undefined; + export function deepcopy(orig_table: T): T; + export function distance( + x1: number, + y1: number, + x2: number, + y2: number, + ): number; + export function get_border(node: node, offset?: vmath.vector3): vmath.vector4; + export function get_closest_stencil_node(node: node): node | undefined; + export function get_gui_scale(): LuaMultiReturn<[number, number]>; + export function get_pivot_offset(pivot: Pivot): vmath.vector3; + export function get_scaled_size(node: node): vmath.vector3; + export function get_scene_scale( + node: node, + include_passed_node_scale?: boolean, + ): vmath.vector3; + export function get_screen_aspect_koef(): LuaMultiReturn<[number, number]>; + export function get_text_metrics_from_node(text_node: any): GUITextMetrics; + export function insert_with_shift( + array: any[], + item: T, + index?: number, + shift_policy?: keyof typeof import('druid.const').SHIFT, + ): T; + export function is_mobile(): boolean; + export function is_web(): boolean; + export function lerp(a: number, b: number, t: number): number; + export function remove_with_shift( + array: T[], + index?: number, + shift_policy?: keyof typeof import('druid.const').SHIFT, + ): T; + export function round(num: number, num_decimal_places?: number): number; + export function sign(val: number): -1 | 0 | 1; + export function step(current: number, target: number, step: number): number; + export function table_to_string( + t: any[] | LuaMap | LuaSet | LuaTable | object, + ): string; + + interface GUITextMetrics { + width: number; + height: number; + max_ascent: number; + max_descent: number; + } +} From 5f426627a0c1586a6e3cb0b87287b38704134652 Mon Sep 17 00:00:00 2001 From: thinknathan Date: Tue, 4 Feb 2025 18:11:51 -0800 Subject: [PATCH 5/9] update: defos for v1.0 --- .../{druid-0.11.0.d.ts => druid-1.0.0.d.ts} | 9 +- packages/druid/druid.const.d.ts | 22 +- .../druid.custom.rich_input.rich_input.d.ts | 33 ++ .../druid.custom.rich_text.rich_text.d.ts | 35 ++ packages/druid/druid.druid.d.ts | 361 +++++++++++------- packages/druid/druid.extended.checkbox.d.ts | 33 -- .../druid/druid.extended.checkbox_group.d.ts | 26 -- packages/druid/druid.extended.data_list.d.ts | 59 +-- .../druid/druid.extended.dynamic_grid.d.ts | 61 --- packages/druid/druid.extended.hotkey.d.ts | 13 +- packages/druid/druid.extended.input.d.ts | 35 +- packages/druid/druid.extended.lang_text.d.ts | 17 +- packages/druid/druid.extended.layout.d.ts | 81 ++-- packages/druid/druid.extended.progress.d.ts | 20 +- .../druid/druid.extended.radio_group.d.ts | 26 -- packages/druid/druid.extended.slider.d.ts | 16 +- packages/druid/druid.extended.swipe.d.ts | 32 +- packages/druid/druid.extended.timer.d.ts | 26 +- packages/druid/druid.helper.d.ts | 28 +- 19 files changed, 500 insertions(+), 433 deletions(-) rename packages/druid/{druid-0.11.0.d.ts => druid-1.0.0.d.ts} (64%) create mode 100644 packages/druid/druid.custom.rich_input.rich_input.d.ts create mode 100644 packages/druid/druid.custom.rich_text.rich_text.d.ts delete mode 100644 packages/druid/druid.extended.checkbox.d.ts delete mode 100644 packages/druid/druid.extended.checkbox_group.d.ts delete mode 100644 packages/druid/druid.extended.dynamic_grid.d.ts delete mode 100644 packages/druid/druid.extended.radio_group.d.ts diff --git a/packages/druid/druid-0.11.0.d.ts b/packages/druid/druid-1.0.0.d.ts similarity index 64% rename from packages/druid/druid-0.11.0.d.ts rename to packages/druid/druid-1.0.0.d.ts index 6523239..e10c467 100644 --- a/packages/druid/druid-0.11.0.d.ts +++ b/packages/druid/druid-1.0.0.d.ts @@ -1,17 +1,16 @@ -/// +/// /// /// -/// -/// /// -/// /// /// /// /// /// -/// /// /// /// +/// +/// +/// /// diff --git a/packages/druid/druid.const.d.ts b/packages/druid/druid.const.d.ts index 03404b9..5f2ba1c 100644 --- a/packages/druid/druid.const.d.ts +++ b/packages/druid/druid.const.d.ts @@ -27,7 +27,14 @@ declare module 'druid.const' { export const ACTION_BACKSPACE: hash; export const ACTION_SCROLL_UP: hash; export const ACTION_SCROLL_DOWN: hash; + export const ACTION_LEFT: hash; + export const ACTION_RIGHT: hash; + export const ACTION_LSHIFT: hash; + export const ACTION_LCTRL: hash; + export const ACTION_LCMD: hash; + export const IS_STENCIL_CHECK: boolean; + export const ON_INPUT: string; export const ON_UPDATE: string; export const ON_MESSAGE: string; @@ -38,9 +45,11 @@ declare module 'druid.const' { export const ON_MESSAGE_INPUT: string; export const ON_WINDOW_RESIZED: string; export const ON_LANGUAGE_CHANGE: string; + export const PRIORITY_INPUT: number; export const PRIORITY_INPUT_HIGH: number; export const PRIORITY_INPUT_MAX: number; + export const MESSAGE_INPUT: { BUTTON_CLICK: string; BUTTON_LONG_CLICK: string; @@ -48,12 +57,15 @@ declare module 'druid.const' { BUTTON_REPEATED_CLICK: string; TEXT_SET: string; }; + export const PIVOTS: { [key: PivotKey]: vmath.vector3; }; + export const REVERSE_PIVOTS: { - [key: PivotKey]: string; + [key: PivotKey]: PivotKey; }; + export const LAYOUT_MODE: { STRETCH_X: string; STRETCH_Y: string; @@ -62,9 +74,11 @@ declare module 'druid.const' { FIT: typeof gui.ADJUST_FIT; STRETCH: typeof gui.ADJUST_STRETCH; }; + export const VECTOR_ZERO: vmath.vector3; export const SYS_INFO: ReturnType; export const CURRENT_SYSTEM_NAME: string; + export const OS: { ANDROID: string; IOS: string; @@ -73,11 +87,13 @@ declare module 'druid.const' { WINDOWS: string; BROWSER: string; }; + export const SHIFT: { NO_SHIFT: number; LEFT: number; RIGHT: number; }; + export const TEXT_ADJUST: { DOWNSCALE: string; TRIM: string; @@ -86,18 +102,22 @@ declare module 'druid.const' { SCROLL: string; SCALE_THEN_SCROLL: string; }; + export const SIDE: { X: string; Y: string; }; + export const SWIPE: { UP: string; DOWN: string; LEFT: string; RIGHT: string; }; + export const ERRORS: { GRID_DYNAMIC_ANCHOR: string; }; + export const EMPTY_FUNCTION: () => void; } diff --git a/packages/druid/druid.custom.rich_input.rich_input.d.ts b/packages/druid/druid.custom.rich_input.rich_input.d.ts new file mode 100644 index 0000000..0e7c8e1 --- /dev/null +++ b/packages/druid/druid.custom.rich_input.rich_input.d.ts @@ -0,0 +1,33 @@ +/** + * @see {@link https://github.com/ts-defold/library|Github Source} + * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} + * @noResolution + */ +declare module 'druid.custom.rich_input.rich_input' { + type RichInput = typeof import('druid.custom.rich_input.rich_input'); + + export function get_text(this: RichInput): void; // TO-DO: is this return value right?? + export function init(this: RichInput, template: string, nodes: node[]): void; + export function select(this: RichInput): void; + export function set_allowed_characters( + this: RichInput, + characters: string, + ): RichInput; + export function set_font(this: RichInput, font: hash): RichInput; + export function set_placeholder( + this: RichInput, + placeholder_text: string, + ): void; + export function set_text(this: RichInput, text: string): RichInput; + + export const cursor: node; + export const cursor_position: vmath.vector3; + export const cursor_text: node; + export const drag: typeof import('druid.druid').Drag; + export const druid: typeof import('druid.druid').DruidInstance; + export const input: typeof import('druid.extended.input'); + export const input_text: typeof import('druid.druid').Text; + export const placeholder: typeof import('druid.druid').Text; + export const root: node; + export const text_position: vmath.vector3; +} diff --git a/packages/druid/druid.custom.rich_text.rich_text.d.ts b/packages/druid/druid.custom.rich_text.rich_text.d.ts new file mode 100644 index 0000000..6d7333a --- /dev/null +++ b/packages/druid/druid.custom.rich_text.rich_text.d.ts @@ -0,0 +1,35 @@ +/** + * @see {@link https://github.com/ts-defold/library|Github Source} + * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} + * @noResolution + */ +declare module 'druid.custom.rich_text.rich_text' { + type RichText = typeof import('druid.custom.rich_text.rich_text'); + type Word = {}; // TO-DO + type LineMetrics = {}; // TO-DO + + export function characters(this: RichText, word: Word): Word[]; + export function clear(this: RichText): void; + export function get_line_metric(this: RichText): LineMetrics; + export function get_text(this: RichText): string; + export function get_words(this: RichText): Word[]; + export function init( + this: RichText, + text_node: node | string, + value?: string | undefined, + ): void; + export function set_text( + this: RichText, + text: string | undefined, + ): LuaMultiReturn<[Word[], LineMetrics]>; + export function tagged(this: RichText, tag: string): Word[]; + + export const style: { + COLORS: {} | undefined; + ADJUST_STEPS: number | undefined; + ADJUST_SCALE_DELTA: number | undefined; + }; + export const druid: typeof import('druid.druid').DruidInstance; + export const root: node; + export const text_prefab: node; +} diff --git a/packages/druid/druid.druid.d.ts b/packages/druid/druid.druid.d.ts index 3f819ab..8acfcf6 100644 --- a/packages/druid/druid.druid.d.ts +++ b/packages/druid/druid.druid.d.ts @@ -1,22 +1,56 @@ -type Component = {}; - /** - * This is a definition stub with incomplete or untested signatures. - * Contributions are welcome to improve the accuracy of these types. * @see {@link https://github.com/ts-defold/library|Github Source} * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} * @noResolution */ declare module 'druid.druid' { - // Built-in Modules - class BackHandler { + type Pivot = + | typeof gui.PIVOT_CENTER + | typeof gui.PIVOT_E + | typeof gui.PIVOT_N + | typeof gui.PIVOT_NE + | typeof gui.PIVOT_NW + | typeof gui.PIVOT_S + | typeof gui.PIVOT_SE + | typeof gui.PIVOT_SW + | typeof gui.PIVOT_W; + export type Component = {}; // TO-DO + type TEXT_ADJUST = + (typeof import('druid.const').TEXT_ADJUST)[keyof typeof import('druid.const').TEXT_ADJUST]; + // Built-in Modules --------------------------------------------- + class BaseComponent { + /** @returns Array of children of the Druid component instance */ + get_children: (this: BaseComponent) => node[]; + /** @returns BaseComponent context */ + get_context: (this: BaseComponent) => {}; + get_druid( + this: BaseComponent, + template: string, + nodes: node[], + ): BaseComponent; + get_input_priority: (this: BaseComponent) => number; + get_name: (this: BaseComponent) => string; + get_node: (this: BaseComponent, node_or_name: node | string) => node; + get_parent_component: (this: BaseComponent) => BaseComponent | undefined; + get_parent_name: (this: BaseComponent) => string | undefined; + get_template: (this: BaseComponent) => string; + get_uid: (this: BaseComponent) => number; + reset_input_priority: (this: BaseComponent) => number; + set_input_enabled: (this: BaseComponent, state?: boolean) => BaseComponent; + set_input_priority: ( + this: BaseComponent, + value: number, + is_temporary?: boolean, + ) => number; + } + class BackHandler extends BaseComponent { on_back: DruidEvent; - params: any[]; + params?: any[]; } - class Blocker { + class Blocker extends BaseComponent { init(this: Blocker, node: node): void; is_enabled(this: Blocker): boolean; - set_enabled(this: Blocker, state: boolean): void; + set_enabled(this: Blocker, state?: boolean): void; node: node; } class Button { @@ -24,33 +58,33 @@ declare module 'druid.druid' { init( this: Button, node: node | string, - callback: Function, + callback: Function, // TO-DO custom_args?: any, anim_node?: node | string, ): void; is_enabled(this: Button): boolean; set_check_function( this: Button, - check_function?: Function, - failure_callback?: Function, + check_function?: Function, // TO-DO + failure_callback?: Function, // TO-DO ): Button; - set_click_zone(this: Button, zone: node): Button; - set_enabled(this: Button, state: boolean): Button; - set_key_trigger(this: Button, key: hash): Button; + set_click_zone(this: Button, zone?: node | string): Button; + set_enabled(this: Button, state?: boolean): Button; + set_key_trigger(this: Button, key: hash | string): Button; set_web_user_interaction(this: Button, is_web_mode?: boolean): Button; style: { - LONGTAP_TIME: number; - AUTOHOLD_TRIGGER: number; - DOUBLETAP_TIME: number; - on_click: Function; - on_click_disabled: Function; - on_hover: Function; - on_mouse_hover: Function; - on_set_enabled: Function; + LONGTAP_TIME: number | undefined; + AUTOHOLD_TRIGGER: number | undefined; + DOUBLETAP_TIME: number | undefined; + on_click: Function; // TO-DO + on_click_disabled: Function; // TO-DO + on_hover: Function; // TO-DO + on_mouse_hover: Function; // TO-DO + on_set_enabled: Function; // TO-DO }; - anim_node: node; - click_zone?: node; + anim_node: node | undefined; + click_zone: node | undefined; hover: Hover; node: node; node_id: hash; @@ -61,17 +95,17 @@ declare module 'druid.druid' { on_long_click: DruidEvent; on_pressed: DruidEvent; on_repeated_click: DruidEvent; - params: any[]; + params: any[] | undefined; } class Drag { - init(this: Drag, node: node, on_drag_callback: Function): void; + init(this: Drag, node: node, on_drag_callback: Function): void; // TO-DO is_enabled(this: Drag): boolean; - set_click_zone(this: Drag, node: node): void; - set_enabled(this: Drag, is_enabled: boolean): void; + set_click_zone(this: Drag, node?: node | string): void; + set_enabled(this: Drag, is_enabled?: boolean): void; style: { - DRAG_DEADZONE: number; - NO_USE_SCREEN_KOEF: boolean; + DRAG_DEADZONE: number | undefined; + NO_USE_SCREEN_KOEF: boolean | undefined; }; can_x: boolean; can_y: boolean; @@ -82,97 +116,115 @@ declare module 'druid.druid' { on_drag_start: DruidEvent; on_touch_end: DruidEvent; on_touch_start: DruidEvent; + screen_x: number; + screen_y: number; touch_start_pos: vmath.vector3; x: number; y: number; } class DruidEvent { clear(this: DruidEvent): void; - initialize(this: DruidEvent, initial_callback?: Function): void; + create(this: DruidEvent, callback_context?: any): void; + is_empty(this: DruidEvent): boolean; is_exist(this: DruidEvent): boolean; - subscribe(this: DruidEvent, callback: Function, context?: any): void; + is_subscribed( + this: DruidEvent, + callback: Function, + callback_context?: any, + ): boolean; // TO-DO + subscribe( + this: DruidEvent, + callback: Function, + callback_context?: any, + ): void; // TO-DO trigger(this: DruidEvent, ...args: any[]): void; - unsubscribe(this: DruidEvent, callback: Function, context?: any): void; + unsubscribe( + this: DruidEvent, + callback: Function, + callback_context?: any, + ): void; } class Hover { - init(this: Hover, node: node, on_hover_callback: Function): void; + init( + this: Hover, + node: node, + on_hover_callback: Function, + on_mouse_hover: Function, + ): void; // TO-DO is_enabled(this: Hover): boolean; is_hovered(this: Hover): boolean; is_mouse_hovered(this: Hover): boolean; - set_click_zone(this: Hover, zone: node): void; - set_enabled(this: Hover, state: boolean): void; - set_hover(this: Hover, state: boolean): void; - set_mouse_hover(this: Hover, state: boolean): void; - - on_hover: (this: Hover, state: boolean, hover_instance: any) => void; - on_mouse_hover: (this: Hover, state: boolean, hover_instance: any) => void; - } - class RichText { - clear(): void; - get_line_metric(): {}; - get_words(): {}; - init(this: RichText, template: string, nodes: node[]): void; - set_text( - this: RichText, - text: string, - ): { - words: {}; - line_metrics: {}; - }; - tagged(tag: string): {}; + set_click_zone(this: Hover, zone?: node | string): void; + set_enabled(this: Hover, state?: boolean): void; + set_hover(this: Hover, state?: boolean): void; + set_mouse_hover(this: Hover, state?: boolean): void; style: { - COLORS: {}; - ADJUST_STEPS: number; - ADJUST_SCALE_DELTA: number; + ON_HOVER_CURSOR: string | undefined; + ON_MOUSE_HOVER_CURSOR: string | undefined; }; + node: node; + on_hover: (this: Hover, state: boolean, hover_instance: any) => void; + on_mouse_hover: (this: Hover, state: boolean, hover_instance: any) => void; } class Scroll { - bind_grid(grid: DynamicGrid | StaticGrid): this; - get_percent(): vmath.vector3; - get_scroll_size(): vmath.vector3; - init(view_node: node | string, content_node: node | string): void; - is_inert(): boolean; - is_node_in_view(node: node): boolean; - scroll_to(point: vmath.vector3, is_instant?: boolean): void; - scroll_to_index(index: number, skip_cb?: boolean): void; - scroll_to_percent(percent: vmath.vector3, is_instant?: boolean): void; - set_click_zone(node: node): void; - set_extra_stretch_size(stretch_size?: number): this; - set_horizontal_scroll(state: boolean): this; - set_inert(state: boolean): this; - set_points(points: vmath.vector3[]): this; - set_size(size: vmath.vector3, offset: vmath.vector3): this; - set_vertical_scroll(state: boolean): this; + bind_grid(this: Scroll, grid: StaticGrid): Scroll; + get_percent(this: Scroll): vmath.vector3; + get_scroll_size(this: Scroll): vmath.vector3; + init( + this: Scroll, + view_node: node | string, + content_node: node | string, + ): void; + is_inert(this: Scroll): boolean; + is_node_in_view(this: Scroll, node: node): boolean; + scroll_to(this: Scroll, point: vmath.vector3, is_instant?: boolean): void; + scroll_to_index(this: Scroll, index: number, skip_cb?: boolean): void; + scroll_to_percent( + this: Scroll, + percent: vmath.vector3, + is_instant?: boolean, + ): void; + set_click_zone(this: Scroll, node: node | string): void; + set_extra_stretch_size(this: Scroll, stretch_size?: number): Scroll; + set_horizontal_scroll(this: Scroll, state?: boolean): Scroll; + set_inert(this: Scroll, state: boolean): Scroll; + set_points(this: Scroll, points: vmath.vector3[]): Scroll; + set_size(this: Scroll, size: vmath.vector3, offset?: vmath.vector3): Scroll; + set_vertical_scroll(this: Scroll, state?: boolean): Scroll; + set_view_size(this: Scroll, size: vmath.vector3): Scroll; + update_view_size(this: Scroll): void; style: { - FRICT: number; - FRICT_HOLD: number; - INERT_THRESHOLD: number; - INERT_SPEED: number; - POINTS_DEADZONE: number; - BACK_SPEED: number; - ANIM_SPEED: number; - EXTRA_STRETCH_SIZE: number; - SMALL_CONTENT_SCROLL: boolean; - WHEEL_SCROLL_SPEED: number; - WHEEL_SCROLL_INVERTED: boolean; - WHEEL_SCROLL_BY_INERTION: boolean; + FRICT: number | undefined; + FRICT_HOLD: number | undefined; + INERT_THRESHOLD: number | undefined; + INERT_SPEED: number | undefined; + POINTS_DEADZONE: number | undefined; + BACK_SPEED: number | undefined; + ANIM_SPEED: number | undefined; + EXTRA_STRETCH_SIZE: number | undefined; + SMALL_CONTENT_SCROLL: boolean | undefined; + WHEEL_SCROLL_SPEED: number | undefined; + WHEEL_SCROLL_INVERTED: boolean | undefined; + WHEEL_SCROLL_BY_INERTION: boolean | undefined; }; + _is_inert: boolean; + /** min_x, max_y, max_x, min_y */ available_pos: vmath.vector4; available_size: vmath.vector3; content_node: node; drag: Drag; inertion: vmath.vector3; is_animate: boolean; - // is_inert: boolean; on_point_scroll: DruidEvent; on_scroll: DruidEvent; on_scroll_to: DruidEvent; position: vmath.vector3; - selected: number; + selected: number | undefined; target_position: vmath.vector3; view_node: node; + view_size: vmath.vector3; } class StaticGrid { add( @@ -196,6 +248,7 @@ declare module 'druid.druid' { element: node, in_row?: number, ): void; + refresh(this: StaticGrid): void; remove( this: StaticGrid, index: number, @@ -204,11 +257,22 @@ declare module 'druid.druid' { ): node; set_anchor(this: StaticGrid, anchor: vmath.vector3): void; set_in_row(this: StaticGrid, in_row: number): StaticGrid; - set_position_function(this: StaticGrid, callback: Function): StaticGrid; + + set_item_size( + this: StaticGrid, + width?: number, + height?: number, + ): StaticGrid; + set_items(this: StaticGrid, nodes: node[], is_instant?: boolean): void; + set_position_function(this: StaticGrid, callback: Function): StaticGrid; // TO-DO + sort_nodes( + this: StaticGrid, + comparator: (a: any, b: any) => boolean, + ): StaticGrid; style: { - IS_DYNAMIC_NODE_POSES: boolean; - IS_ALIGN_LAST_ROW: boolean; + IS_DYNAMIC_NODE_POSES: boolean | undefined; + IS_ALIGN_LAST_ROW: boolean | undefined; }; anchor: vmath.vector3; border: vmath.vector4; @@ -225,33 +289,39 @@ declare module 'druid.druid' { pivot: vmath.vector3; } class Text { - get_text_adjust(this: Text, adjust_type: any): number; + get_text_adjust(this: Text, adjust_type: TEXT_ADJUST): number; + get_text_index_by_width(this: Text, width: number): number; + /** @returns width, height */ get_text_size(this: Text, text?: string): LuaMultiReturn<[number, number]>; init( this: Text, node: node | string, value?: string, - adjust_type?: string, + adjust_type?: TEXT_ADJUST, ): void; is_multiline(this: Text): boolean; set_alpha(this: Text, alpha: number): Text; set_color(this: Text, color: vmath.vector4): Text; - set_minimal_scale(this: Text, minimal_scale: number): Text; - set_pivot(this: Text, pivot: any): Text; + set_minimal_scale(this: Text, minimal_scale?: number): Text; + set_pivot(this: Text, pivot: Pivot): Text; set_scale(this: Text, scale: vmath.vector3): Text; + set_size(this: Text, size: vmath.vector3): Text; set_text_adjust( this: Text, - adjust_type?: number, + adjust_type?: TEXT_ADJUST, minimal_scale?: number, ): Text; set_to(this: Text, set_to: string): Text; style: { - TRIM_POSTFIX: string; - DEFAULT_ADJUST: string; + TRIM_POSTFIX: string | undefined; + DEFAULT_ADJUST: string | undefined; + ADJUST_STEPS: number | undefined; + ADJUST_SCALE_DELTA: number | undefined; }; adjust_type: number; color: vmath.vector3; + last_value: string; node: node; node_id: hash; on_set_pivot: DruidEvent; @@ -263,18 +333,28 @@ declare module 'druid.druid' { start_size: vmath.vector3; text_area: vmath.vector3; } + export { type BackHandler }; + export { type BaseComponent }; export { type Blocker }; export { type Button }; export { type Drag }; export { type DruidEvent }; export { type Hover }; - export { type RichText }; export { type Scroll }; export { type StaticGrid }; export { type Text }; - type Grid = DynamicGrid | StaticGrid; + export type DruidExtendedModule = + | typeof import('druid.extended.data_list') + | typeof import('druid.extended.hotkey') + | typeof import('druid.extended.input') + | typeof import('druid.extended.lang_text') + | typeof import('druid.extended.layout') + | typeof import('druid.extended.progress') + | typeof import('druid.extended.slider') + | typeof import('druid.extended.swipe') + | typeof import('druid.extended.timer'); class DruidInstance { final(): void; @@ -290,66 +370,64 @@ declare module 'druid.druid' { params?: any[], anim_node?: node, ): Button; - new_checkbox( - node: node, - callback: (...args: any[]) => void, - click_node?: node, - initial_state?: boolean, - ): Checkbox; - new_checkbox_group( - nodes: node[], - callback: (...args: any[]) => void, - click_nodes?: node[], - ): CheckboxGroup; new_data_list( druid_scroll: Scroll, - druid_grid: Grid, + druid_grid: StaticGrid, create_function: ( data: any, index: number, - data_list: DataList, + data_list: typeof import('druid.extended.data_list'), ) => LuaMultiReturn<[node, Component | undefined]>, - ): DataList; + ): typeof import('druid.extended.data_list'); new_drag( node: node, on_drag_callback: (dx: number, dy: number) => void, ): Drag; - new_dynamic_grid(parent: node): DynamicGrid; + // new_dynamic_grid(parent: node): DynamicGrid; new_hotkey( keys_array: string[] | string, callback: (...args: any[]) => void, params?: any, - ): Hotkey; + ): typeof import('druid.extended.hotkey'); new_hover(node: node, on_hover_callback: (...args: any[]) => void): Hover; - new_input(click_node: node, text_node: node, keyboard_type?: number): Input; - new_lang_text(node: node, locale_id: string, no_adjust: boolean): LangText; - new_layout(node: node | string, mode: string): Layout; + new_input( + click_node: node, + text_node: node, + keyboard_type?: number, + ): typeof import('druid.extended.input'); + new_lang_text( + node: node, + locale_id: string, + no_adjust: boolean, + ): typeof import('druid.extended.lang_text'); + new_layout( + node: node | string, + mode: string, + ): typeof import('druid.extended.layout'); new_progress( node: node | string, key: string, init_value?: number, - ): Progress; - new_radio_group( - nodes: node[], - callback: (...args: any[]) => void, - click_nodes?: node[], - ): RadioGroup; - new_rich_text(template?: string, nodes?: any): RichText; + ): typeof import('druid.extended.progress'); + // new_rich_text(template?: string, nodes?: any): RichText; new_scroll(view_node: node, content_node: node): Scroll; new_slider( node: node, end_pos: vmath.vector3, callback?: (...args: any[]) => void, - ): Slider; + ): typeof import('druid.extended.slider'); new_static_grid(parent: node, element: node, in_row?: number): StaticGrid; - new_swipe(node: node, on_swipe_callback: (...args: any[]) => void): Swipe; + new_swipe( + node: node, + on_swipe_callback: (...args: any[]) => void, + ): typeof import('druid.extended.swipe'); new_text(node: node, value?: string, no_adjust?: boolean): Text; new_timer( node: node, seconds_from: number, seconds_to?: number, callback?: (...args: any[]) => void, - ): Timer; + ): typeof import('druid.extended.timer'); on_input(action_id: hash, action: any): boolean; on_message(message_id: hash, message: any, sender: hash): void; remove(component: Component): void; @@ -359,29 +437,18 @@ declare module 'druid.druid' { } export { type DruidInstance }; - type DruidExtendedModule = - | Checkbox - | CheckboxGroup - | DataList - | DynamicGrid - | Hotkey - | Input - | LangText - | Layout - | Progress - | RadioGroup - | Slider - | Swipe - | Timer; + export type DruidStyle = {}; // TO-DO + function ___new(this: void, context: any, style?: DruidStyle): DruidInstance; + export { ___new as new }; export function on_language_change(this: void): void; export function on_window_callback(this: void, event: string): void; export function register( this: void, name: string, - module: DruidExtendedModule, + module: DruidExtendedModule, // TO-DO ): void; - export function set_default_style(this: void, style: any): void; + export function set_default_style(this: void, style: DruidStyle): void; export function set_sound_function( this: void, callback: (this: void, sound_id: unknown) => void, @@ -390,6 +457,4 @@ declare module 'druid.druid' { this: void, callback: (this: void, text_id: unknown) => void, ): void; - function ___new(this: void, context: any, style?: any): DruidInstance; - export { ___new as new }; } diff --git a/packages/druid/druid.extended.checkbox.d.ts b/packages/druid/druid.extended.checkbox.d.ts deleted file mode 100644 index c6341e5..0000000 --- a/packages/druid/druid.extended.checkbox.d.ts +++ /dev/null @@ -1,33 +0,0 @@ -/** - * This is a definition stub with incomplete or untested signatures. - * Contributions are welcome to improve the accuracy of these types. - * @see {@link https://github.com/ts-defold/library|Github Source} - * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} - * @noResolution - */ -declare module 'druid.extended.checkbox' { - export function get_state(this: Checkbox): boolean[]; - export function init( - this: Checkbox, - nodes: node, - callback: (...args: any[]) => any, - click_nodes?: node, - initial_state?: boolean, - ): void; - export function set_state( - this: Checkbox, - state: boolean, - is_silent: boolean, - is_instant: boolean, - ): void; - - export const style: { - on_change_state: (this: Checkbox, node: node, state: boolean) => void; - }; - export const button: typeof import('druid.druid').Button; - export const click_node: node; - export const node: node; - export const on_change_state: typeof import('druid.druid').DruidEvent; -} - -type Checkbox = typeof import('druid.extended.checkbox'); diff --git a/packages/druid/druid.extended.checkbox_group.d.ts b/packages/druid/druid.extended.checkbox_group.d.ts deleted file mode 100644 index f3988d2..0000000 --- a/packages/druid/druid.extended.checkbox_group.d.ts +++ /dev/null @@ -1,26 +0,0 @@ -/** - * This is a definition stub with incomplete or untested signatures. - * Contributions are welcome to improve the accuracy of these types. - * @see {@link https://github.com/ts-defold/library|Github Source} - * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} - * @noResolution - */ -declare module 'druid.extended.checkbox_group' { - export function get_state(this: CheckboxGroup): boolean[]; - export function init( - this: CheckboxGroup, - nodes: node[], - callback: (...args: any[]) => any, - click_nodes?: node[], - ): void; - export function set_state( - this: CheckboxGroup, - indexes: boolean[], - is_instant: boolean, - ): void; - - export const checkboxes: CheckboxGroup[]; - export const on_checkbox_click: (this: any, index: number) => void; -} - -type CheckboxGroup = typeof import('druid.extended.checkbox_group'); diff --git a/packages/druid/druid.extended.data_list.d.ts b/packages/druid/druid.extended.data_list.d.ts index 854b5a7..1dd1b28 100644 --- a/packages/druid/druid.extended.data_list.d.ts +++ b/packages/druid/druid.extended.data_list.d.ts @@ -1,45 +1,56 @@ /** - * This is a definition stub with incomplete or untested signatures. - * Contributions are welcome to improve the accuracy of these types. * @see {@link https://github.com/ts-defold/library|Github Source} * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} * @noResolution */ declare module 'druid.extended.data_list' { + type DataList = typeof import('druid.extended.data_list'); + type SHIFT_POLICY = keyof typeof import('druid.const').SHIFT; + + export function add( + this: DataList, + data: {}, + index?: number, + shift_policy?: SHIFT_POLICY, + ): void; export function clear(this: DataList): void; - export function get_created_components(this: DataList): Component[]; + export function get_created_components( + this: DataList, + ): import('druid.druid').Component[]; export function get_created_nodes(this: DataList): node[]; export function get_data(this: DataList): {}; - export function get_first_index(this: DataList): number; - export function get_index(this: DataList, data: {}): number; - export function get_last_index(this: DataList): number; - export function get_length(this: DataList): number; + export function get_index(this: DataList, data: {}): number; // TO-DO export function init( this: DataList, scroll: typeof import('druid.druid').Scroll, - grid: DynamicGrid | typeof import('druid.druid').StaticGrid, - create_function: Function, + grid: typeof import('druid.druid').StaticGrid, + // The create function callback(self, data, index, data_list). Function should return (node, [component]) + create_function: Function, // TO-DO ): void; export function on_remove(this: DataList): void; + export function remove( + this: DataList, + index: number | undefined, + shift_policy?: SHIFT_POLICY, + ): void; + export function remove_by_data( + this: DataList, + data: {}, + shift_policy?: SHIFT_POLICY, + ): void; export function scroll_to_index(this: DataList, index: number): void; - export function set_data(this: DataList, data: {}): DataList; + export function set_data(this: DataList, data: {}): DataList; // TO-DO + export function set_use_cache( + this: DataList, + is_use_cache: boolean, + ): DataList; - export const grid: DynamicGrid | typeof import('druid.druid').StaticGrid; + export const grid: typeof import('druid.druid').StaticGrid; export const last_index: number; - export const on_element_add: ( - this: void, - index: number, - node: node, - instance: any, - ) => void; - export const on_element_remove: (this: void, index: number) => void; - export const on_scroll_progress_change: ( - this: void, - progress_value: number, - ) => void; + export const on_element_add: typeof import('druid.druid').DruidEvent; + export const on_element_remove: typeof import('druid.druid').DruidEvent; + export const on_scroll_progress_change: typeof import('druid.druid').DruidEvent; export const scroll: typeof import('druid.druid').Scroll; export const scroll_progress: number; export const top_index: number; } - -type DataList = typeof import('druid.extended.data_list'); diff --git a/packages/druid/druid.extended.dynamic_grid.d.ts b/packages/druid/druid.extended.dynamic_grid.d.ts deleted file mode 100644 index 07ae188..0000000 --- a/packages/druid/druid.extended.dynamic_grid.d.ts +++ /dev/null @@ -1,61 +0,0 @@ -/** - * This is a definition stub with incomplete or untested signatures. - * Contributions are welcome to improve the accuracy of these types. - * @see {@link https://github.com/ts-defold/library|Github Source} - * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} - * @noResolution - */ -declare module 'druid.extended.dynamic_grid' { - export function _get_side_vector( - this: DynamicGrid, - side: any, - is_forward: any, - ): unknown; - export function add( - this: DynamicGrid, - node: node, - index?: number, - shift_policy?: number, - is_instant?: boolean, - ): void; - export function clear(this: DynamicGrid): DynamicGrid; - export function get_all_pos(this: DynamicGrid): vmath.vector3[]; - export function get_borders(this: DynamicGrid): vmath.vector3; - export function get_index_by_node(this: DynamicGrid, node: node): number; - export function get_offset(this: DynamicGrid): vmath.vector3; - export function get_pos( - this: DynamicGrid, - index: number, - node: node, - origin_index?: number, - ): vmath.vector3; - export function get_size( - this: DynamicGrid, - border: vmath.vector3, - ): vmath.vector3; - export function init(this: DynamicGrid, parent: node): void; - export function remove( - this: DynamicGrid, - index: number, - shift_policy?: number, - is_instant?: boolean, - ): node; - export function set_position_function( - this: DynamicGrid, - callback: Function, - ): DynamicGrid; - - export const border: vmath.vector4; - export const first_index: number; - export const last_index: number; - export const node_size: vmath.vector3; - export const nodes: node[]; - export const on_add_item: typeof import('druid.druid').DruidEvent; - export const on_change_items: typeof import('druid.druid').DruidEvent; - export const on_clear: typeof import('druid.druid').DruidEvent; - export const on_remove_item: typeof import('druid.druid').DruidEvent; - export const on_update_positions: typeof import('druid.druid').DruidEvent; - export const parent: node; -} - -type DynamicGrid = typeof import('druid.extended.dynamic_grid'); diff --git a/packages/druid/druid.extended.hotkey.d.ts b/packages/druid/druid.extended.hotkey.d.ts index 11b6a32..30ad368 100644 --- a/packages/druid/druid.extended.hotkey.d.ts +++ b/packages/druid/druid.extended.hotkey.d.ts @@ -1,14 +1,14 @@ /** - * This is a definition stub with incomplete or untested signatures. - * Contributions are welcome to improve the accuracy of these types. * @see {@link https://github.com/ts-defold/library|Github Source} * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} * @noResolution */ declare module 'druid.extended.hotkey' { + type Hotkey = typeof import('druid.extended.hotkey'); + export function add_hotkey( this: Hotkey, - keys: Record | string[] | string, + keys: hash[] | string[] | string | hash, callback_argument?: any, ): void; export function init( @@ -17,12 +17,15 @@ declare module 'druid.extended.hotkey' { callback: (...args: any[]) => void, callback_argument?: any, ): void; + export function set_repeat( + this: Hotkey, + is_enabled_repeated: boolean, + ): Hotkey; export const style: { MODIFICATORS: string[] }; export const button: import('druid.druid').Button; export const click_node: node; export const node: node; + export const on_hotkey_pressed: typeof import('druid.druid').DruidEvent; export const on_change_state: typeof import('druid.druid').DruidEvent; } - -type Hotkey = typeof import('druid.extended.hotkey'); diff --git a/packages/druid/druid.extended.input.d.ts b/packages/druid/druid.extended.input.d.ts index 9d1353d..f570aed 100644 --- a/packages/druid/druid.extended.input.d.ts +++ b/packages/druid/druid.extended.input.d.ts @@ -1,42 +1,60 @@ /** - * This is a definition stub with incomplete or untested signatures. - * Contributions are welcome to improve the accuracy of these types. * @see {@link https://github.com/ts-defold/library|Github Source} * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} * @noResolution */ declare module 'druid.extended.input' { + type Input = typeof import('druid.extended.input'); + export function get_text(this: Input): string; + export function get_text_selected_replaced(this: Input, text: string): string; export function init( this: Input, click_node: node, text_node: node | import('druid.druid').Text, keyboard_type?: number, ): void; + export function move_selection( + this: Input, + delta: number, + is_add_to_selection: boolean, + is_move_to_end: boolean, + ): void; export function reset_changes(this: Input): void; export function select(this: Input): void; + export function select_cursor( + this: Input, + cursor_index: number | undefined, + start_index: number | undefined, + end_index: number | undefined, + ): Input; export function set_allowed_characters( this: Input, characters: string, ): Input; - export function set_max_length(this: Input, max_length: number | null): Input; + export function set_max_length(this: Input, max_length: number): Input; export function set_text(this: Input, input_text: string): void; export function unselect(this: Input): void; export const style: { IS_LONGTAP_ERASE: boolean; MASK_DEFAULT_CHAR: string; IS_UNSELECT_ON_RESELECT: boolean; - NO_CONSUME_INPUT_WHILE_SELECTED: boolean; + // NO_CONSUME_INPUT_WHILE_SELECTED: boolean; on_select: (this: Input, button_node: node) => void; on_unselect: (this: Input, button_node: node) => void; on_input_wrong: (this: Input, button_node: node) => void; - button_style: {}; + // button_style: {}; }; export const allowerd_characters: string | undefined; export const button: import('druid.druid').Button; + export const current_value: string; + export const cursor_index: number; + export const end_index: number; export const is_empty: boolean; export const is_selected: boolean; export const keyboard_type: number; + export const marked_text_width: number; + export const marked_value: string; export const max_length: number | undefined; export const on_input_empty: import('druid.druid').DruidEvent; export const on_input_full: import('druid.druid').DruidEvent; @@ -44,7 +62,10 @@ declare module 'druid.extended.input' { export const on_input_text: import('druid.druid').DruidEvent; export const on_input_unselect: import('druid.druid').DruidEvent; export const on_input_wrong: import('druid.druid').DruidEvent; + export const on_select_cursor_change: import('druid.druid').DruidEvent; + export const previous_value: string; + export const start_index: number; export const text: import('druid.druid').Text; + export const text_width: number; + export const value: string; } - -type Input = typeof import('druid.extended.input'); diff --git a/packages/druid/druid.extended.lang_text.d.ts b/packages/druid/druid.extended.lang_text.d.ts index e14c143..13238f1 100644 --- a/packages/druid/druid.extended.lang_text.d.ts +++ b/packages/druid/druid.extended.lang_text.d.ts @@ -1,11 +1,13 @@ /** - * This is a definition stub with incomplete or untested signatures. - * Contributions are welcome to improve the accuracy of these types. * @see {@link https://github.com/ts-defold/library|Github Source} * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} * @noResolution */ declare module 'druid.extended.lang_text' { + type LangText = typeof import('druid.extended.lang_text'); + type TEXT_ADJUST = + (typeof import('druid.const').TEXT_ADJUST)[keyof typeof import('druid.const').TEXT_ADJUST]; + export function format( this: LangText, a?: string, @@ -19,8 +21,8 @@ declare module 'druid.extended.lang_text' { export function init( this: LangText, node: node | string, - locale_id: string, - adjust_type?: string, + locale_id: string | undefined, + adjust_type?: TEXT_ADJUST | undefined, ): void; export function set_to(this: LangText, text: string): LangText; export function translate( @@ -35,8 +37,7 @@ declare module 'druid.extended.lang_text' { g?: string, ): LangText; - const on_change: import('druid.druid').DruidEvent; - const text: import('druid.druid').Text; + export const node: node; + export const on_change: import('druid.druid').DruidEvent; + export const text: import('druid.druid').Text; } - -type LangText = typeof import('druid.extended.lang_text'); diff --git a/packages/druid/druid.extended.layout.d.ts b/packages/druid/druid.extended.layout.d.ts index 22a9991..c81a0f8 100644 --- a/packages/druid/druid.extended.layout.d.ts +++ b/packages/druid/druid.extended.layout.d.ts @@ -1,43 +1,72 @@ /** - * This is a definition stub with incomplete or untested signatures. - * Contributions are welcome to improve the accuracy of these types. * @see {@link https://github.com/ts-defold/library|Github Source} * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} * @noResolution */ declare module 'druid.extended.layout' { - export function fit_into_node(this: Layout, node?: node): Layout; - export function fit_into_size( - this: Layout, - target_size: vmath.vector3, - ): Layout; - export function fit_into_window(this: Layout): Layout; + // TO-DO + type Layout = typeof import('druid.extended.layout'); + + interface RowData { + width: number; + height: number; + count: number; + } + + interface RowsData { + total_width: number; + total_height: number; + nodes_width: LuaMap; + nodes_height: LuaMap; + rows: RowData[]; + } + export function init( this: Layout, node: node, - mode: string, - on_size_changed_callback?: () => void, - ): void; - export function set_max_gui_upscale( - this: Layout, - max_gui_upscale: number, + layout_type: string, + on_size_changed_callback?: Function, // TO-DO ): Layout; - export function set_max_size(this: Layout, max_size: vmath.vector3): Layout; - export function set_min_size(this: Layout, min_size: vmath.vector3): Layout; - export function set_origin_position( + export function update(this: Layout): void; + export function set_margin( this: Layout, - new_origin_position: vmath.vector3, + margin_x: number, + margin_y: number, ): Layout; - export function set_origin_size( + export function set_padding(this: Layout, padding: vmath.vector4): Layout; + export function set_dirty(this: Layout): Layout; + export function set_justify(this: Layout, is_justify: boolean): Layout; + export function set_type(this: Layout, type: string): Layout; + + export function set_hug_content( this: Layout, - new_origin_size: vmath.vector3, + is_hug_width: boolean, + is_hug_height: boolean, ): Layout; + export function add(this: Layout, node_or_node_id: node | string): Layout; + export function refresh_layout(this: Layout): Layout; + export function clear_layout(this: Layout): Layout; - export const mode: string; + export function get_node_size( + this: Layout, + node: node, + ): LuaMultiReturn<[number, number]>; + export function calculate_rows_data(this: Layout): RowsData; + export function set_node_position( + this: Layout, + node: node, + x: number, + y: number, + ): node; + + export const mode: string; // TO-DO is this real? export const node: node; - export const on_size_changed: ( - new_size: import('druid.druid').DruidEvent, - ) => void; + export const type: string; + export const margin: { x: number; y: number }; + export const padding: ReturnType; + export const isDirty: boolean; + export const entities: node[]; + export const isJustify: boolean; + export const isResizeWidth: boolean; + export const isResizeHeight: boolean; } - -type Layout = typeof import('druid.extended.layout'); diff --git a/packages/druid/druid.extended.progress.d.ts b/packages/druid/druid.extended.progress.d.ts index ce33ca4..727351f 100644 --- a/packages/druid/druid.extended.progress.d.ts +++ b/packages/druid/druid.extended.progress.d.ts @@ -1,11 +1,11 @@ /** - * This is a definition stub with incomplete or untested signatures. - * Contributions are welcome to improve the accuracy of these types. * @see {@link https://github.com/ts-defold/library|Github Source} * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} * @noResolution */ declare module 'druid.extended.progress' { + type Progress = typeof import('druid.extended.progress'); + export function empty(this: Progress): void; export function fill(this: Progress): void; export function get(this: Progress): number; @@ -24,20 +24,18 @@ declare module 'druid.extended.progress' { steps: number[], callback: (this: Progress, step: number) => void, ): void; - export function set_to(this: Progress, to: number): void; - export function to( - this: Progress, - to: number, - callback?: (this: Progress) => void, - ): void; + export function set_to(this: Progress, to: number, callback?: Function): void; // TO-DO + export function to(this: Progress, to: number, callback?: Function): void; // TO-DO + export const style: { + SPEED: number | undefined; + MIN_DELTA: number | undefined; + }; export const key: string; export const max_size: number; export const node: node; - export const on_change: (this: Progress, new_value: number) => void; + export const on_change: import('druid.druid').DruidEvent; export const scale: vmath.vector3; export const size: vmath.vector3; export const slice: vmath.vector4; } - -type Progress = typeof import('druid.extended.progress'); diff --git a/packages/druid/druid.extended.radio_group.d.ts b/packages/druid/druid.extended.radio_group.d.ts deleted file mode 100644 index 139eb17..0000000 --- a/packages/druid/druid.extended.radio_group.d.ts +++ /dev/null @@ -1,26 +0,0 @@ -/** - * This is a definition stub with incomplete or untested signatures. - * Contributions are welcome to improve the accuracy of these types. - * @see {@link https://github.com/ts-defold/library|Github Source} - * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} - * @noResolution - */ -declare module 'druid.extended.radio_group' { - export function get_state(this: RadioGroup): number; - export function init( - this: RadioGroup, - nodes: node[], - callback: Function, - click_nodes?: node[], - ): void; - export function set_state( - this: RadioGroup, - index: number, - is_instant: boolean, - ): void; - - export const checkboxes: Checkbox[]; - export const on_radio_click: import('druid.druid').DruidEvent; -} - -type RadioGroup = typeof import('druid.extended.radio_group'); diff --git a/packages/druid/druid.extended.slider.d.ts b/packages/druid/druid.extended.slider.d.ts index c2b8b42..66dbe63 100644 --- a/packages/druid/druid.extended.slider.d.ts +++ b/packages/druid/druid.extended.slider.d.ts @@ -1,22 +1,26 @@ /** - * This is a definition stub with incomplete or untested signatures. - * Contributions are welcome to improve the accuracy of these types. * @see {@link https://github.com/ts-defold/library|Github Source} * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} * @noResolution */ declare module 'druid.extended.slider' { + type Slider = typeof import('druid.extended.slider'); export function init( this: Slider, node: node, end_pos: vmath.vector3, - callback?: Function, + callback?: Function, // TO-DO ): void; + export function is_enabled(this: Slider): boolean; export function set(this: Slider, value: number, is_silent?: boolean): void; - export function set_input_node(this: Slider, input_node: node): Slider; + export function set_enabled(this: Slider, is_enabled: boolean): void; + export function set_input_node( + this: Slider, + input_node: node | string | undefined, + ): Slider; export function set_steps(this: Slider, steps: number[]): Slider; - export const dist: number; + export const dist: vmath.vector3; export const end_pos: vmath.vector3; export const is_drag: boolean; export const node: node; @@ -26,5 +30,3 @@ declare module 'druid.extended.slider' { export const target_pos: vmath.vector3; export const value: number; } - -type Slider = typeof import('druid.extended.slider'); diff --git a/packages/druid/druid.extended.swipe.d.ts b/packages/druid/druid.extended.swipe.d.ts index fcc8b5a..c981ade 100644 --- a/packages/druid/druid.extended.swipe.d.ts +++ b/packages/druid/druid.extended.swipe.d.ts @@ -1,32 +1,32 @@ /** - * This is a definition stub with incomplete or untested signatures. - * Contributions are welcome to improve the accuracy of these types. * @see {@link https://github.com/ts-defold/library|Github Source} * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} * @noResolution */ declare module 'druid.extended.swipe' { + type Swipe = typeof import('druid.extended.swipe'); + export function init( this: Swipe, node: node, - on_swipe_callback: (swipe: Swipe) => void, + on_swipe_callback: ( + this: Swipe, + swipe_side: string, + dist: number, + delta_time: number, + ) => void, + ): void; + export function set_click_zone( + this: Swipe, + zone: node | string | undefined, ): void; - export function set_click_zone(this: Swipe, zone: node): void; export const style: { - SWIPE_TIME: number; - SWIPE_THRESHOLD: number; - SWIPE_TRIGGER_ON_MOVE: boolean; + SWIPE_TIME: number | undefined; + SWIPE_THRESHOLD: number | undefined; + SWIPE_TRIGGER_ON_MOVE: boolean | undefined; }; - export const click_zone: node | undefined; export const node: node; - export const on_swipe: ( - this: Swipe, - swipe_side: string, - dist: number, - delta_time: number, - ) => void; + export const on_swipe: import('druid.druid').DruidEvent; } - -type Swipe = typeof import('druid.extended.swipe'); diff --git a/packages/druid/druid.extended.timer.d.ts b/packages/druid/druid.extended.timer.d.ts index a84320a..fe451d1 100644 --- a/packages/druid/druid.extended.timer.d.ts +++ b/packages/druid/druid.extended.timer.d.ts @@ -1,35 +1,27 @@ /** - * This is a definition stub with incomplete or untested signatures. - * Contributions are welcome to improve the accuracy of these types. * @see {@link https://github.com/ts-defold/library|Github Source} * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} * @noResolution */ declare module 'druid.extended.timer' { + type Timer = typeof import('druid.extended.timer'); + export function init( this: Timer, node: node, - seconds_from: number, - seconds_to?: number, - callback?: Function, + seconds_from: number | undefined, + seconds_to?: number | undefined, + callback?: Function | undefined, ): void; export function set_interval(this: Timer, from: number, to: number): void; - export function set_state(this: Timer, is_on: boolean): void; + export function set_state(this: Timer, is_on: boolean | undefined): void; export function set_to(this: Timer, set_to: number): void; export const from: number; export const node: node; - export const on_set_enabled: ( - this: Timer, - is_enabled: import('druid.druid').DruidEvent, - ) => void; - export const on_tick: ( - this: Timer, - value: import('druid.druid').DruidEvent, - ) => void; - export const on_timer_end: (this: Timer) => import('druid.druid').DruidEvent; + export const on_set_enabled: import('druid.druid').DruidEvent; + export const on_tick: import('druid.druid').DruidEvent; + export const on_timer_end: import('druid.druid').DruidEvent; export const target: number; export const value: number; } - -type Timer = typeof import('druid.extended.timer'); diff --git a/packages/druid/druid.helper.d.ts b/packages/druid/druid.helper.d.ts index fe80a66..666e85d 100644 --- a/packages/druid/druid.helper.d.ts +++ b/packages/druid/druid.helper.d.ts @@ -1,6 +1,4 @@ /** - * This is a definition stub with incomplete or untested signatures. - * Contributions are welcome to improve the accuracy of these types. * @see {@link https://github.com/ts-defold/library|Github Source} * @see {@link https://insality.github.io/druid/modules/Druid.html|Documentation} * @noResolution @@ -16,10 +14,18 @@ declare module 'druid.helper' { | typeof gui.PIVOT_SE | typeof gui.PIVOT_SW | typeof gui.PIVOT_W; + type GUITextMetrics = { + width: number; + height: number; + max_ascent: number; + max_descent: number; + }; + type SHIFT_POLICY = keyof typeof import('druid.const').SHIFT; - export function add_array(target: T1[], source?: T2[]): (T1 | T2)[]; + export function add_array(target: T1[], source: T2[]): (T1 | T2)[]; export function centrate_nodes(margin?: number, ...nodes: node[]): void; export function clamp(a: number, min: number, max: number): number; + /** @returns Index of value or undefined */ export function contains(t: any[], value: any): number | undefined; export function deepcopy(orig_table: T): T; export function distance( @@ -28,8 +34,10 @@ declare module 'druid.helper' { x2: number, y2: number, ): number; + /** @returns border values (left, top, right, down) */ export function get_border(node: node, offset?: vmath.vector3): vmath.vector4; export function get_closest_stencil_node(node: node): node | undefined; + /** @returns scale_x, scale_y */ export function get_gui_scale(): LuaMultiReturn<[number, number]>; export function get_pivot_offset(pivot: Pivot): vmath.vector3; export function get_scaled_size(node: node): vmath.vector3; @@ -37,21 +45,24 @@ declare module 'druid.helper' { node: node, include_passed_node_scale?: boolean, ): vmath.vector3; + /** @returns stretch_x, stretch_y */ export function get_screen_aspect_koef(): LuaMultiReturn<[number, number]>; export function get_text_metrics_from_node(text_node: any): GUITextMetrics; export function insert_with_shift( array: any[], item: T, index?: number, - shift_policy?: keyof typeof import('druid.const').SHIFT, + shift_policy?: SHIFT_POLICY, ): T; export function is_mobile(): boolean; + export function is_multitouch_supported(): boolean; export function is_web(): boolean; + export function is_web_mobile(): boolean; export function lerp(a: number, b: number, t: number): number; export function remove_with_shift( array: T[], index?: number, - shift_policy?: keyof typeof import('druid.const').SHIFT, + shift_policy?: SHIFT_POLICY, ): T; export function round(num: number, num_decimal_places?: number): number; export function sign(val: number): -1 | 0 | 1; @@ -59,11 +70,4 @@ declare module 'druid.helper' { export function table_to_string( t: any[] | LuaMap | LuaSet | LuaTable | object, ): string; - - interface GUITextMetrics { - width: number; - height: number; - max_ascent: number; - max_descent: number; - } } From 2c1f77e110d69e4a1ee0f411a0bfd8a9d5e23664 Mon Sep 17 00:00:00 2001 From: thinknathan Date: Tue, 4 Feb 2025 18:12:19 -0800 Subject: [PATCH 6/9] fix: shift policy signature --- packages/druid/druid.extended.data_list.d.ts | 3 ++- packages/druid/druid.helper.d.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/druid/druid.extended.data_list.d.ts b/packages/druid/druid.extended.data_list.d.ts index 1dd1b28..fd97684 100644 --- a/packages/druid/druid.extended.data_list.d.ts +++ b/packages/druid/druid.extended.data_list.d.ts @@ -5,7 +5,8 @@ */ declare module 'druid.extended.data_list' { type DataList = typeof import('druid.extended.data_list'); - type SHIFT_POLICY = keyof typeof import('druid.const').SHIFT; + type SHIFT_POLICY = + (typeof import('druid.const').SHIFT)[keyof typeof import('druid.const').SHIFT]; export function add( this: DataList, diff --git a/packages/druid/druid.helper.d.ts b/packages/druid/druid.helper.d.ts index 666e85d..3cf3ae0 100644 --- a/packages/druid/druid.helper.d.ts +++ b/packages/druid/druid.helper.d.ts @@ -20,7 +20,8 @@ declare module 'druid.helper' { max_ascent: number; max_descent: number; }; - type SHIFT_POLICY = keyof typeof import('druid.const').SHIFT; + type SHIFT_POLICY = + (typeof import('druid.const').SHIFT)[keyof typeof import('druid.const').SHIFT]; export function add_array(target: T1[], source: T2[]): (T1 | T2)[]; export function centrate_nodes(margin?: number, ...nodes: node[]): void; From 128a2013707750548275deb41e954f012566a5c7 Mon Sep 17 00:00:00 2001 From: thinknathan Date: Tue, 4 Feb 2025 21:14:14 -0800 Subject: [PATCH 7/9] chore: update druid instance signature --- packages/druid/druid.druid.d.ts | 107 +++++++++++++++++++++++--------- 1 file changed, 79 insertions(+), 28 deletions(-) diff --git a/packages/druid/druid.druid.d.ts b/packages/druid/druid.druid.d.ts index 8acfcf6..4f9c969 100644 --- a/packages/druid/druid.druid.d.ts +++ b/packages/druid/druid.druid.d.ts @@ -357,83 +357,134 @@ declare module 'druid.druid' { | typeof import('druid.extended.timer'); class DruidInstance { - final(): void; - new(component: Component, ...args: any[]): void; + final(this: DruidInstance): void; new_back_handler( + this: DruidInstance, callback: (...args: any[]) => void, params?: any, ): BackHandler; - new_blocker(node: node): Blocker; + new_blocker(this: DruidInstance, node: node | string): Blocker; new_button( - node: node, + this: DruidInstance, + node: node | string, callback: (...args: any[]) => void, params?: any[], - anim_node?: node, + anim_node?: node | string, ): Button; new_data_list( + this: DruidInstance, druid_scroll: Scroll, druid_grid: StaticGrid, create_function: ( + this: DruidInstance, data: any, index: number, data_list: typeof import('druid.extended.data_list'), ) => LuaMultiReturn<[node, Component | undefined]>, ): typeof import('druid.extended.data_list'); new_drag( - node: node, + this: DruidInstance, + node: node | string, on_drag_callback: (dx: number, dy: number) => void, ): Drag; - // new_dynamic_grid(parent: node): DynamicGrid; new_hotkey( + this: DruidInstance, keys_array: string[] | string, callback: (...args: any[]) => void, - params?: any, + callback_argument?: any, ): typeof import('druid.extended.hotkey'); - new_hover(node: node, on_hover_callback: (...args: any[]) => void): Hover; + new_hover( + this: DruidInstance, + node: node | string, + on_hover_callback: (...args: any[]) => void, + on_mouse_hover_callback: (...args: any[]) => void, + ): Hover; new_input( - click_node: node, - text_node: node, + this: DruidInstance, + click_node: node | string, + text_node: node | string | Text, keyboard_type?: number, ): typeof import('druid.extended.input'); new_lang_text( - node: node, - locale_id: string, - no_adjust: boolean, + this: DruidInstance, + node: node | string, + locale_id?: string, + adjust_type?: TEXT_ADJUST, ): typeof import('druid.extended.lang_text'); new_layout( + this: DruidInstance, node: node | string, mode: string, ): typeof import('druid.extended.layout'); new_progress( + this: DruidInstance, node: node | string, - key: string, + key: (typeof import('druid.const').SIDE)[keyof typeof import('druid.const').SIDE], init_value?: number, ): typeof import('druid.extended.progress'); - // new_rich_text(template?: string, nodes?: any): RichText; - new_scroll(view_node: node, content_node: node): Scroll; + new_rich_input( + this: DruidInstance, + template: string, + nodes: ReturnType, + ): typeof import('druid.custom.rich_input.rich_input'); + new_rich_text( + this: DruidInstance, + text_node: node | string, + value?: string, + ): typeof import('druid.custom.rich_text.rich_text'); + new_scroll( + this: DruidInstance, + view_node: node | string, + content_node: node | string, + ): Scroll; new_slider( - node: node, + this: DruidInstance, + node: node | string, end_pos: vmath.vector3, callback?: (...args: any[]) => void, ): typeof import('druid.extended.slider'); - new_static_grid(parent: node, element: node, in_row?: number): StaticGrid; + new_static_grid( + this: DruidInstance, + parent_node: node | string, + item: node | string, + in_row?: number, + ): StaticGrid; new_swipe( - node: node, + this: DruidInstance, + node: node | string, on_swipe_callback: (...args: any[]) => void, ): typeof import('druid.extended.swipe'); - new_text(node: node, value?: string, no_adjust?: boolean): Text; + new_text( + this: DruidInstance, + node: node | string, + value?: string, + no_adjust?: boolean, + ): Text; new_timer( - node: node, + this: DruidInstance, + node: node | string, seconds_from: number, seconds_to?: number, callback?: (...args: any[]) => void, ): typeof import('druid.extended.timer'); - on_input(action_id: hash, action: any): boolean; - on_message(message_id: hash, message: any, sender: hash): void; - remove(component: Component): void; - set_blacklist(blacklist_components?: any[] | Component): DruidInstance; - set_whitelist(whitelist_components?: any[] | Component): DruidInstance; - update(dt: number): void; + on_input(this: DruidInstance, action_id: hash, action: any): boolean; // TO-DO: action type is `input_message` table from GO/GUI + on_message( + this: DruidInstance, + message_id: hash, + message: any, + sender: url, + ): void; + /** @returns True if component was removed */ + remove(this: DruidInstance, component: Component): boolean; + set_blacklist( + this: DruidInstance, + blacklist_components?: any[] | Component, + ): DruidInstance; + set_whitelist( + this: DruidInstance, + whitelist_components?: any[] | Component, + ): DruidInstance; + update(this: DruidInstance, dt: number): void; } export { type DruidInstance }; From e8edc51b83174855f876fd6d46c2b56be810818d Mon Sep 17 00:00:00 2001 From: thinknathan Date: Wed, 5 Feb 2025 21:23:01 -0800 Subject: [PATCH 8/9] update: better rich_text and druidinstance types --- .../druid.custom.rich_text.rich_text.d.ts | 52 +++++++++++++++++-- packages/druid/druid.druid.d.ts | 5 +- 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/packages/druid/druid.custom.rich_text.rich_text.d.ts b/packages/druid/druid.custom.rich_text.rich_text.d.ts index 6d7333a..365fb92 100644 --- a/packages/druid/druid.custom.rich_text.rich_text.d.ts +++ b/packages/druid/druid.custom.rich_text.rich_text.d.ts @@ -5,8 +5,52 @@ */ declare module 'druid.custom.rich_text.rich_text' { type RichText = typeof import('druid.custom.rich_text.rich_text'); - type Word = {}; // TO-DO - type LineMetrics = {}; // TO-DO + type Word = { + node: node; + relative_scale: number; + color: vmath.vector4; + position: vmath.vector3; + offset: vmath.vector3; + scale: vmath.vector3; + size: vmath.vector3; + metrics: Metrics; + pivot: Pivot; + text: string; + shadow: vmath.vector4; + outline: vmath.vector4; + font: string; + image: Image; + br: boolean; + nobr: boolean; + }; + type LineMetrics = { + text_width: number; + text_height: number; + lines: Record; + }; + type Metrics = { + width: number; + height: number; + offset_x?: number; + offset_y?: number; + node_size?: vmath.vector3; + }; + type Image = { + texture: string; + anim: string; + width: number; + height: number; + }; + type Pivot = + | typeof gui.PIVOT_CENTER + | typeof gui.PIVOT_E + | typeof gui.PIVOT_N + | typeof gui.PIVOT_NE + | typeof gui.PIVOT_NW + | typeof gui.PIVOT_S + | typeof gui.PIVOT_SE + | typeof gui.PIVOT_SW + | typeof gui.PIVOT_W; export function characters(this: RichText, word: Word): Word[]; export function clear(this: RichText): void; @@ -16,7 +60,7 @@ declare module 'druid.custom.rich_text.rich_text' { export function init( this: RichText, text_node: node | string, - value?: string | undefined, + value?: string, ): void; export function set_text( this: RichText, @@ -25,7 +69,7 @@ declare module 'druid.custom.rich_text.rich_text' { export function tagged(this: RichText, tag: string): Word[]; export const style: { - COLORS: {} | undefined; + COLORS: Record | undefined; ADJUST_STEPS: number | undefined; ADJUST_SCALE_DELTA: number | undefined; }; diff --git a/packages/druid/druid.druid.d.ts b/packages/druid/druid.druid.d.ts index 4f9c969..f70e2e1 100644 --- a/packages/druid/druid.druid.d.ts +++ b/packages/druid/druid.druid.d.ts @@ -402,7 +402,7 @@ declare module 'druid.druid' { new_input( this: DruidInstance, click_node: node | string, - text_node: node | string | Text, + text_node: node | Text | string, keyboard_type?: number, ): typeof import('druid.extended.input'); new_lang_text( @@ -485,6 +485,7 @@ declare module 'druid.druid' { whitelist_components?: any[] | Component, ): DruidInstance; update(this: DruidInstance, dt: number): void; + new: (this: DruidInstance, module: T, name: string) => T; } export { type DruidInstance }; @@ -497,7 +498,7 @@ declare module 'druid.druid' { export function register( this: void, name: string, - module: DruidExtendedModule, // TO-DO + module: DruidExtendedModule | BaseComponent, // TO-DO ): void; export function set_default_style(this: void, style: DruidStyle): void; export function set_sound_function( From cb1504a38703ced62e01c67e4243a3d3838ca1a0 Mon Sep 17 00:00:00 2001 From: thinknathan Date: Sat, 8 Feb 2025 20:51:19 -0800 Subject: [PATCH 9/9] fix: add missing function signature to lang --- packages/defold-lang/lang.lang.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/defold-lang/lang.lang.d.ts b/packages/defold-lang/lang.lang.d.ts index 660ab9e..2a0f1b4 100644 --- a/packages/defold-lang/lang.lang.d.ts +++ b/packages/defold-lang/lang.lang.d.ts @@ -22,6 +22,7 @@ declare module 'lang.lang' { export function get_lang(): string; export function get_langs(): string[]; export function set_next_lang(): void; + export function get_next_lang(): string; export function is_exist(text_id: string): boolean; export function txt(text_id: string): string; export function txp(text_id: string, ...params: any[]): string;