@gtkx/ffi 0.3.4 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -17
- package/dist/native.d.ts +8 -0
- package/dist/native.js +16 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -41,7 +41,14 @@ Edit your code and see changes instantly—no restart needed.
|
|
|
41
41
|
### Example
|
|
42
42
|
|
|
43
43
|
```tsx
|
|
44
|
-
import {
|
|
44
|
+
import {
|
|
45
|
+
render,
|
|
46
|
+
ApplicationWindow,
|
|
47
|
+
Box,
|
|
48
|
+
Button,
|
|
49
|
+
Label,
|
|
50
|
+
quit,
|
|
51
|
+
} from "@gtkx/react";
|
|
45
52
|
import { Orientation } from "@gtkx/ffi/gtk";
|
|
46
53
|
import { useState } from "react";
|
|
47
54
|
|
|
@@ -74,7 +81,7 @@ const primary = css`
|
|
|
74
81
|
color: white;
|
|
75
82
|
`;
|
|
76
83
|
|
|
77
|
-
<Button label="Click me" cssClasses={[primary]}
|
|
84
|
+
<Button label="Click me" cssClasses={[primary]} />;
|
|
78
85
|
```
|
|
79
86
|
|
|
80
87
|
GTK also provides built-in classes like `suggested-action`, `destructive-action`, `card`, and `heading`.
|
|
@@ -90,7 +97,9 @@ afterEach(() => cleanup());
|
|
|
90
97
|
test("increments count", async () => {
|
|
91
98
|
await render(<App />);
|
|
92
99
|
|
|
93
|
-
const button = await screen.findByRole(AccessibleRole.BUTTON, {
|
|
100
|
+
const button = await screen.findByRole(AccessibleRole.BUTTON, {
|
|
101
|
+
name: "Increment",
|
|
102
|
+
});
|
|
94
103
|
await userEvent.click(button);
|
|
95
104
|
|
|
96
105
|
await screen.findByText("Count: 1");
|
|
@@ -103,10 +112,10 @@ User events: `click`, `dblClick`, `type`, `clear`, `tab`, `selectOptions`
|
|
|
103
112
|
|
|
104
113
|
## Examples
|
|
105
114
|
|
|
106
|
-
| Example
|
|
107
|
-
|
|
|
108
|
-
| [gtk4-demo](examples/gtk4-demo) | Widget showcase
|
|
109
|
-
| [todo](examples/todo)
|
|
115
|
+
| Example | Description |
|
|
116
|
+
| ------------------------------- | ------------------- |
|
|
117
|
+
| [gtk4-demo](examples/gtk4-demo) | Widget showcase |
|
|
118
|
+
| [todo](examples/todo) | Todo app with tests |
|
|
110
119
|
|
|
111
120
|
```bash
|
|
112
121
|
cd examples/gtk4-demo && pnpm dev
|
|
@@ -114,15 +123,15 @@ cd examples/gtk4-demo && pnpm dev
|
|
|
114
123
|
|
|
115
124
|
## Packages
|
|
116
125
|
|
|
117
|
-
| Package
|
|
118
|
-
|
|
|
119
|
-
| [@gtkx/cli](packages/cli)
|
|
120
|
-
| [@gtkx/react](packages/react)
|
|
121
|
-
| [@gtkx/ffi](packages/ffi)
|
|
122
|
-
| [@gtkx/native](packages/native)
|
|
123
|
-
| [@gtkx/css](packages/css)
|
|
124
|
-
| [@gtkx/testing](packages/testing) | Testing utilities
|
|
125
|
-
| [@gtkx/gir](packages/gir)
|
|
126
|
+
| Package | Description |
|
|
127
|
+
| --------------------------------- | ------------------------------------- |
|
|
128
|
+
| [@gtkx/cli](packages/cli) | CLI with HMR dev server |
|
|
129
|
+
| [@gtkx/react](packages/react) | React reconciler and JSX components |
|
|
130
|
+
| [@gtkx/ffi](packages/ffi) | TypeScript bindings for GTK4/GLib/GIO |
|
|
131
|
+
| [@gtkx/native](packages/native) | Rust native module (libffi bridge) |
|
|
132
|
+
| [@gtkx/css](packages/css) | CSS-in-JS styling |
|
|
133
|
+
| [@gtkx/testing](packages/testing) | Testing utilities |
|
|
134
|
+
| [@gtkx/gir](packages/gir) | GObject Introspection parser |
|
|
126
135
|
|
|
127
136
|
## Requirements
|
|
128
137
|
|
|
@@ -136,7 +145,6 @@ We welcome contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
|
136
145
|
|
|
137
146
|
- [Report a bug](https://github.com/eugeniodepalo/gtkx/issues/new?template=bug_report.md)
|
|
138
147
|
- [Request a feature](https://github.com/eugeniodepalo/gtkx/issues/new?template=feature_request.md)
|
|
139
|
-
- [Read the Code of Conduct](CODE_OF_CONDUCT.md)
|
|
140
148
|
|
|
141
149
|
## License
|
|
142
150
|
|
package/dist/native.d.ts
CHANGED
|
@@ -35,6 +35,14 @@ type TypeWithGlibTypeName<T extends NativeObject> = {
|
|
|
35
35
|
* @throws Error if the object does not implement the interface/class
|
|
36
36
|
*/
|
|
37
37
|
export declare const getInterface: <T extends NativeObject>(obj: NativeObject, targetType: TypeWithGlibTypeName<T>) => T;
|
|
38
|
+
/**
|
|
39
|
+
* Attempts to cast an object to a specific interface or class type.
|
|
40
|
+
* Returns null if the object does not implement the requested interface.
|
|
41
|
+
* @param obj - The object to get the interface from
|
|
42
|
+
* @param targetType - The interface or class type to cast to
|
|
43
|
+
* @returns The object typed as the target type, or null if not implemented
|
|
44
|
+
*/
|
|
45
|
+
export declare const tryGetInterface: <T extends NativeObject>(obj: NativeObject, targetType: TypeWithGlibTypeName<T>) => T | null;
|
|
38
46
|
/**
|
|
39
47
|
* Starts the GTK application with the given application ID.
|
|
40
48
|
* Sets up a keep-alive timer to prevent Node.js from exiting.
|
package/dist/native.js
CHANGED
|
@@ -69,6 +69,22 @@ export const getInterface = (obj, targetType) => {
|
|
|
69
69
|
}
|
|
70
70
|
return obj;
|
|
71
71
|
};
|
|
72
|
+
/**
|
|
73
|
+
* Attempts to cast an object to a specific interface or class type.
|
|
74
|
+
* Returns null if the object does not implement the requested interface.
|
|
75
|
+
* @param obj - The object to get the interface from
|
|
76
|
+
* @param targetType - The interface or class type to cast to
|
|
77
|
+
* @returns The object typed as the target type, or null if not implemented
|
|
78
|
+
*/
|
|
79
|
+
export const tryGetInterface = (obj, targetType) => {
|
|
80
|
+
const targetGType = typeFromName(targetType.glibTypeName);
|
|
81
|
+
if (targetGType === 0)
|
|
82
|
+
return null;
|
|
83
|
+
const objId = getObjectId(obj.id);
|
|
84
|
+
if (!typeCheckInstanceIsA(objId, targetGType))
|
|
85
|
+
return null;
|
|
86
|
+
return obj;
|
|
87
|
+
};
|
|
72
88
|
const keepAlive = () => {
|
|
73
89
|
keepAliveTimeout = setTimeout(() => keepAlive(), 2147483647);
|
|
74
90
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gtkx/ffi",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"description": "Generated TypeScript FFI bindings for GTK4 libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"gtk",
|
|
@@ -46,10 +46,10 @@
|
|
|
46
46
|
"dist"
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@gtkx/native": "0.3.
|
|
49
|
+
"@gtkx/native": "0.3.5"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@gtkx/gir": "0.3.
|
|
52
|
+
"@gtkx/gir": "0.3.5"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"build": "tsc -b && cp ../../README.md .",
|