@gtkx/native 0.1.21 → 0.1.22
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 +208 -0
- package/dist/index.node +0 -0
- package/package.json +4 -5
- package/index.node +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="logo.svg" alt="GTKX Logo" width="128" height="128">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">GTKX</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<strong>Build native GTK4 desktop applications with React and TypeScript</strong>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://eugeniodepalo.github.io/gtkx">Documentation</a> ·
|
|
13
|
+
<a href="#quick-start">Quick Start</a> ·
|
|
14
|
+
<a href="#examples">Examples</a>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
GTKX bridges React's component model with GTK4's native widget system. Write familiar React code and render it as native Linux desktop applications with full access to GTK4 widgets, signals, and styling.
|
|
20
|
+
|
|
21
|
+
## Features
|
|
22
|
+
|
|
23
|
+
- **React Components** — Use React hooks, state, and component patterns you already know
|
|
24
|
+
- **Type-Safe** — Full TypeScript support with auto-generated types from GTK4 introspection data
|
|
25
|
+
- **Native Performance** — Direct FFI bindings to GTK4 via Rust and libffi
|
|
26
|
+
- **CSS-in-JS Styling** — Emotion-style `css` template literals for GTK widgets
|
|
27
|
+
- **Testing Library** — Familiar `screen`, `userEvent`, and query APIs for testing components
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# Install dependencies
|
|
33
|
+
pnpm add @gtkx/react react
|
|
34
|
+
|
|
35
|
+
# For styling (optional)
|
|
36
|
+
pnpm add @gtkx/css
|
|
37
|
+
|
|
38
|
+
# For testing (optional)
|
|
39
|
+
pnpm add -D @gtkx/testing
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Create your first app:
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
// index.tsx
|
|
46
|
+
import { render } from "@gtkx/react";
|
|
47
|
+
import { App } from "./app.js";
|
|
48
|
+
|
|
49
|
+
render(<App />, "org.example.MyApp");
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
// app.tsx
|
|
54
|
+
import { ApplicationWindow, Box, Button, Label, quit } from "@gtkx/react";
|
|
55
|
+
import { Orientation } from "@gtkx/ffi/gtk";
|
|
56
|
+
import { useState } from "react";
|
|
57
|
+
|
|
58
|
+
export const App = () => {
|
|
59
|
+
const [count, setCount] = useState(0);
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<ApplicationWindow
|
|
63
|
+
title="My App"
|
|
64
|
+
defaultWidth={400}
|
|
65
|
+
defaultHeight={300}
|
|
66
|
+
onCloseRequest={quit}
|
|
67
|
+
>
|
|
68
|
+
<Box orientation={Orientation.VERTICAL} spacing={12} margin={20}>
|
|
69
|
+
<Label.Root label={`Count: ${count}`} />
|
|
70
|
+
<Button
|
|
71
|
+
label="Increment"
|
|
72
|
+
onClicked={() => setCount((c) => c + 1)}
|
|
73
|
+
/>
|
|
74
|
+
</Box>
|
|
75
|
+
</ApplicationWindow>
|
|
76
|
+
);
|
|
77
|
+
};
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Run with:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
pnpm tsx index.tsx
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Styling
|
|
87
|
+
|
|
88
|
+
Use `@gtkx/css` for CSS-in-JS styling:
|
|
89
|
+
|
|
90
|
+
```tsx
|
|
91
|
+
import { css } from "@gtkx/css";
|
|
92
|
+
import { Button } from "@gtkx/react";
|
|
93
|
+
|
|
94
|
+
const primaryButton = css`
|
|
95
|
+
padding: 16px 32px;
|
|
96
|
+
border-radius: 24px;
|
|
97
|
+
background: linear-gradient(135deg, #3584e4, #9141ac);
|
|
98
|
+
color: white;
|
|
99
|
+
font-weight: bold;
|
|
100
|
+
`;
|
|
101
|
+
|
|
102
|
+
const MyButton = () => (
|
|
103
|
+
<Button label="Click me" cssClasses={[primaryButton]} />
|
|
104
|
+
);
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
GTK also provides built-in CSS classes like `suggested-action`, `destructive-action`, `card`, and `heading`.
|
|
108
|
+
|
|
109
|
+
## Testing
|
|
110
|
+
|
|
111
|
+
Use `@gtkx/testing` for Testing Library-style component tests:
|
|
112
|
+
|
|
113
|
+
```tsx
|
|
114
|
+
import { cleanup, render, screen, userEvent, fireEvent } from "@gtkx/testing";
|
|
115
|
+
import { AccessibleRole } from "@gtkx/ffi/gtk";
|
|
116
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
117
|
+
import { App } from "./app.js";
|
|
118
|
+
|
|
119
|
+
describe("Counter", () => {
|
|
120
|
+
afterEach(() => cleanup());
|
|
121
|
+
|
|
122
|
+
it("increments count when clicking button", async () => {
|
|
123
|
+
render(<App />);
|
|
124
|
+
|
|
125
|
+
const button = await screen.findByRole(AccessibleRole.BUTTON, {
|
|
126
|
+
name: "Increment",
|
|
127
|
+
});
|
|
128
|
+
await userEvent.click(button);
|
|
129
|
+
|
|
130
|
+
await screen.findByText("Count: 1");
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("can also use fireEvent for synchronous events", async () => {
|
|
134
|
+
render(<App />);
|
|
135
|
+
|
|
136
|
+
const button = await screen.findByRole(AccessibleRole.BUTTON, {
|
|
137
|
+
name: "Increment",
|
|
138
|
+
});
|
|
139
|
+
fireEvent.click(button);
|
|
140
|
+
|
|
141
|
+
await screen.findByText("Count: 1");
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Available APIs
|
|
147
|
+
|
|
148
|
+
**Queries** - Find elements in the rendered tree:
|
|
149
|
+
- `getBy*` / `getAllBy*` - Throws if not found
|
|
150
|
+
- `queryBy*` / `queryAllBy*` - Returns null/empty array if not found
|
|
151
|
+
- `findBy*` / `findAllBy*` - Async, waits for element
|
|
152
|
+
|
|
153
|
+
Query types: `ByRole`, `ByText`, `ByLabelText`, `ByTestId`
|
|
154
|
+
|
|
155
|
+
**User Interactions**:
|
|
156
|
+
- `userEvent.click(element)` - Simulate click
|
|
157
|
+
- `userEvent.dblClick(element)` - Simulate double click
|
|
158
|
+
- `userEvent.type(element, text)` - Type text into input
|
|
159
|
+
- `userEvent.clear(element)` - Clear input text
|
|
160
|
+
- `userEvent.setup()` - Create reusable instance
|
|
161
|
+
|
|
162
|
+
**Low-level Events**:
|
|
163
|
+
- `fireEvent(element, signalName)` - Emit any GTK signal
|
|
164
|
+
- `fireEvent.click(element)` - Emit clicked signal
|
|
165
|
+
- `fireEvent.activate(element)` - Emit activate signal
|
|
166
|
+
|
|
167
|
+
**Utilities**:
|
|
168
|
+
- `waitFor(callback)` - Wait for condition
|
|
169
|
+
- `waitForElementToBeRemoved(element)` - Wait for element removal
|
|
170
|
+
|
|
171
|
+
## Examples
|
|
172
|
+
|
|
173
|
+
### Counter
|
|
174
|
+
|
|
175
|
+
A minimal counter app demonstrating state management:
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
turbo start --filter=counter-example
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### GTK4 Demo
|
|
182
|
+
|
|
183
|
+
A comprehensive showcase of GTK4 widgets and features:
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
turbo start --filter=gtk4-demo
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Packages
|
|
190
|
+
|
|
191
|
+
| Package | Description |
|
|
192
|
+
|---------|-------------|
|
|
193
|
+
| [@gtkx/react](packages/react) | React reconciler and JSX components |
|
|
194
|
+
| [@gtkx/ffi](packages/ffi) | TypeScript FFI bindings for GTK4 |
|
|
195
|
+
| [@gtkx/native](packages/native) | Rust native module for FFI bridge |
|
|
196
|
+
| [@gtkx/css](packages/css) | CSS-in-JS styling for GTK widgets |
|
|
197
|
+
| [@gtkx/testing](packages/testing) | Testing utilities for GTKX components |
|
|
198
|
+
| [@gtkx/gir](packages/gir) | GObject Introspection parser for codegen |
|
|
199
|
+
|
|
200
|
+
## Requirements
|
|
201
|
+
|
|
202
|
+
- Node.js 20+
|
|
203
|
+
- GTK4 development libraries
|
|
204
|
+
- Linux (GTK4 is Linux-native)
|
|
205
|
+
|
|
206
|
+
## License
|
|
207
|
+
|
|
208
|
+
[MPL-2.0](LICENSE)
|
package/dist/index.node
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gtkx/native",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.22",
|
|
4
4
|
"description": "Rust-based native module providing FFI bindings for GTKX",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"gtk",
|
|
@@ -32,15 +32,14 @@
|
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"files": [
|
|
35
|
-
"dist"
|
|
36
|
-
"index.node"
|
|
35
|
+
"dist"
|
|
37
36
|
],
|
|
38
37
|
"devDependencies": {
|
|
39
38
|
"@neon-rs/cli": "0.1.82"
|
|
40
39
|
},
|
|
41
40
|
"scripts": {
|
|
42
|
-
"build": "tsc -b && cp index.node dist/",
|
|
41
|
+
"build": "tsc -b && cp index.node dist/ && cp ../../README.md .",
|
|
43
42
|
"native-build": "cargo build --message-format=json-render-diagnostics --release > cargo.log && neon dist < cargo.log",
|
|
44
|
-
"test": "xvfb-run -a vitest run"
|
|
43
|
+
"test": "GDK_BACKEND=x11 xvfb-run -a vitest run"
|
|
45
44
|
}
|
|
46
45
|
}
|
package/index.node
DELETED
|
Binary file
|