slint-ui 0.3.4 → 1.0.0

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 CHANGED
@@ -1,4 +1,4 @@
1
- # Slint-node
1
+ # Slint-node (Beta)
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/slint-ui)](https://www.npmjs.com/package/slint-ui)
4
4
 
@@ -6,9 +6,12 @@
6
6
  Slint-node is the integration with node.
7
7
 
8
8
  The complete Node documentation can be viewed online at https://slint-ui.com/docs/node/.
9
+ To get started you can use the [Walk-through tutorial](https://slint-ui.com/docs/tutorial/node).
10
+ We also have a [Getting Started Template](https://github.com/slint-ui/slint-nodejs-template) repository with
11
+ the code of a minimal application using Slint that can be used as a starting point to your program.
9
12
 
10
- **Warning: Pre-Alpha**
11
- Slint is still in the early stages of development: APIs will change and important features are still being developed.
13
+ **Warning: Beta**
14
+ Slint-node is still in the early stages of development: APIs will change and important features are still being developed.
12
15
 
13
16
  ## Installing Slint
14
17
 
@@ -18,6 +21,16 @@ Slint is available via NPM, so you can install by running the following command:
18
21
  npm install slint-ui
19
22
  ```
20
23
 
24
+ ### Dependencies
25
+
26
+ You need to install the following components:
27
+
28
+ * **[Node.js](https://nodejs.org/download/release/v16.19.1/)** (v16. Newer versions currently not supported: [#961](https://github.com/slint-ui/slint/issues/961))
29
+ * **[npm](https://www.npmjs.com/)**
30
+ * **[Rust compiler](https://www.rust-lang.org/tools/install)** (1.66 or newer)
31
+
32
+ You will also need a few more dependencies, see <https://github.com/slint-ui/slint/blob/master/docs/building.md#prerequisites>
33
+
21
34
  ## Using Slint
22
35
 
23
36
  To initialize the API, you first need to import the `slint-ui` module in our code:
@@ -144,4 +157,4 @@ component.model = model;
144
157
  model.push(4); // this works
145
158
  // does NOT work, getting the model does not return the right object
146
159
  // component.model.push(5);
147
- ```
160
+ ```
package/cover.md ADDED
@@ -0,0 +1,164 @@
1
+ # Slint-node (Beta)
2
+
3
+ [![npm](https://img.shields.io/npm/v/slint-ui)](https://www.npmjs.com/package/slint-ui)
4
+
5
+ [Slint](https://slint-ui.com/) is a UI toolkit that supports different programming languages.
6
+ Slint-node is the integration with node.
7
+
8
+ To get started you can use the [Walk-through tutorial](https://slint-ui.com/docs/tutorial/node).
9
+ We also have a [Getting Started Template](https://github.com/slint-ui/slint-nodejs-template) repository with
10
+ the code of a minimal application using Slint that can be used as a starting point to your program.
11
+
12
+ **Warning: Beta**
13
+ Slint-node is still in the early stages of development: APIs will change and important features are still being developed.
14
+
15
+ ## Slint Language Manual
16
+
17
+ The [Slint language manual](../slint) covers the Slint UI description language
18
+ in detail.
19
+
20
+ ## Installing Slint
21
+
22
+ Slint is available via NPM, so you can install by running the following command:
23
+
24
+ ```sh
25
+ npm install slint-ui
26
+ ```
27
+
28
+ ### Dependencies
29
+
30
+ You need to install the following components:
31
+
32
+ * **[Node.js](https://nodejs.org/download/release/v16.19.1/)** (v16. Newer versions currently not supported: [#961](https://github.com/slint-ui/slint/issues/961))
33
+ * **[npm](https://www.npmjs.com/)**
34
+ * **[Rust compiler](https://www.rust-lang.org/tools/install)** (1.66 or newer)
35
+
36
+ You will also need a few more dependencies, see <https://github.com/slint-ui/slint/blob/master/docs/building.md#prerequisites>
37
+
38
+ ## Using Slint
39
+
40
+ To initialize the API, you first need to import the `slint-ui` module in our code:
41
+
42
+ ```js
43
+ let slint = require("slint-ui");
44
+ ```
45
+
46
+ This step also installs a hook in NodeJS that allows you to import `.slint` files directly:
47
+
48
+ ```js
49
+ let ui = require("../ui/main.slint");
50
+ ```
51
+
52
+ Combining these two steps leads us to the obligatory "Hello World" example:
53
+
54
+ ```js
55
+ require("slint-ui");
56
+ let ui = require("../ui/main.slint");
57
+ let main = new ui.Main();
58
+ main.run();
59
+ ```
60
+
61
+ See [/examples/todo/node](https://github.com/slint-ui/slint/tree/master/examples/todo/node) for a full example.
62
+
63
+ ## API Overview
64
+
65
+ ### Instantiating a component
66
+
67
+ The exported component is exposed as a type constructor. The type constructor takes as parameter
68
+ an object which allow to initialize the value of public properties or callbacks.
69
+
70
+ ```js
71
+ require("slint-ui");
72
+ // In this example, the main.slint file exports a module which
73
+ // has a counter property and a clicked callback
74
+ let ui = require("ui/main.slint");
75
+ let component = new ui.MainWindow({
76
+ counter: 42,
77
+ clicked: function() { console.log("hello"); }
78
+ });
79
+ ```
80
+
81
+ ### Accessing a property
82
+
83
+ Properties are exposed as properties on the component instance
84
+
85
+ ```js
86
+ component.counter = 42;
87
+ console.log(component.counter);
88
+ ```
89
+
90
+ ### Callbacks
91
+
92
+ The callbacks are also exposed as property that have a setHandler function, and that can can be called.
93
+
94
+ ```js
95
+ // connect to a callback
96
+ component.clicked.setHandler(function() { console.log("hello"); })
97
+ // emit a callback
98
+ component.clicked();
99
+ ```
100
+
101
+ ### Type Mappings
102
+
103
+ | `.slint` Type | JavaScript Type | Notes |
104
+ | --- | --- | --- |
105
+ | `int` | `Number` | |
106
+ | `float` | `Number` | |
107
+ | `string` | `String` | |
108
+ | `color` | `String` | Colors are represented as strings in the form `"#rrggbbaa"`. When setting a color property, any CSS compliant color is accepted as a string. |
109
+ | `length` | `Number` | |
110
+ | `physical_length` | `Number` | |
111
+ | `duration` | `Number` | The number of milliseconds |
112
+ | `angle` | `Number` | The value in degrees |
113
+ | structure | `Object` | Structures are mapped to JavaScrip objects with structure fields mapped to properties. |
114
+ | array | `Array` or Model Object | |
115
+
116
+ ### Models
117
+
118
+ For property of array type, they can either be set using an array.
119
+ In that case, getting the property also return an array.
120
+ If the array was set within the .slint file, the array can be obtained
121
+
122
+ ```js
123
+ component.model = [1, 2, 3];
124
+ // component.model.push(4); // does not work, because it operate on a copy
125
+ // but re-assigning works
126
+ component.model = component.model.concat(4);
127
+ ```
128
+
129
+ Another option is to set a model object. A model object has the following function:
130
+
131
+ * `rowCount()`: returns the number of element in the model.
132
+ * `rowData(index)`: return the row at the given index
133
+ * `setRowData(index, data)`: called when the model need to be changed. `this.notify.rowDataChanged` must be called if successful.
134
+
135
+ When such an object is set to a model property, it gets a new `notify` object with the following function
136
+
137
+ * `rowDataChanged(index)`: notify the view that the row was changed.
138
+ * `rowAdded(index, count)`: notify the view that rows were added.
139
+ * `rowRemoved(index, count)`: notify the view that a row were removed.
140
+ * `reset()`: notify the view that everything may have changed.
141
+
142
+ As an example, here is the implementation of the `ArrayModel` (which is available as `slint.ArrayModel`)
143
+
144
+ ```js
145
+ let array = [1, 2, 3];
146
+ let model = {
147
+ rowCount() { return a.length; },
148
+ rowData(row) { return a[row]; },
149
+ setRowData(row, data) { a[row] = data; this.notify.rowDataChanged(row); },
150
+ push() {
151
+ let size = a.length;
152
+ Array.prototype.push.apply(a, arguments);
153
+ this.notify.rowAdded(size, arguments.length);
154
+ },
155
+ remove(index, size) {
156
+ let r = a.splice(index, size);
157
+ this.notify.rowRemoved(size, arguments.length);
158
+ },
159
+ };
160
+ component.model = model;
161
+ model.push(4); // this works
162
+ // does NOT work, getting the model does not return the right object
163
+ // component.model.push(5);
164
+ ```
package/native/Cargo.toml CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  [package]
5
5
  name = "slint-node"
6
- version = "0.3.4"
6
+ version = "1.0.0"
7
7
  authors = ["Slint Developers <info@slint-ui.com>"]
8
8
  edition = "2021"
9
9
  build = "build.rs"
@@ -20,9 +20,9 @@ crate-type = ["cdylib"]
20
20
  name = "slint_node_native"
21
21
 
22
22
  [dependencies]
23
- i-slint-compiler = { version = "=0.3.4"}
24
- i-slint-core = { version = "=0.3.4"}
25
- slint-interpreter = { version = "=0.3.4", features = ["display-diagnostics"] }
23
+ i-slint-compiler = { version = "=1.0.0"}
24
+ i-slint-core = { version = "=1.0.0"}
25
+ slint-interpreter = { version = "=1.0.0", features = ["display-diagnostics"] }
26
26
 
27
27
  vtable = { version = "0.1.6"}
28
28
 
@@ -34,5 +34,8 @@ rand = "0.8"
34
34
  scoped-tls-hkt = "0.1"
35
35
  spin_on = "0.1" #FIXME: remove and delegate to async JS instead
36
36
 
37
+ # Enable image-rs' default features to make all image formats available for nodejs builds
38
+ image = { version = "0.24.0" }
39
+
37
40
  [build-dependencies]
38
41
  neon-build = "0.8.0"
package/native/lib.rs CHANGED
@@ -111,7 +111,7 @@ fn create<'cx>(
111
111
  cx: &mut CallContext<'cx, impl neon::object::This>,
112
112
  component_type: slint_interpreter::ComponentDefinition,
113
113
  ) -> JsResult<'cx, JsValue> {
114
- let component = component_type.create();
114
+ let component = component_type.create().unwrap();
115
115
  let persistent_context = persistent_context::PersistentContext::new(cx);
116
116
 
117
117
  if let Some(args) = cx.argument_opt(0).and_then(|arg| arg.downcast::<JsObject>().ok()) {
@@ -341,7 +341,7 @@ declare_types! {
341
341
  let component = cx.borrow(&this, |x| x.0.as_ref().map(|c| c.clone_strong()));
342
342
  let component = component.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
343
343
  run_scoped(&mut cx,this.downcast().unwrap(), || {
344
- component.run();
344
+ component.run().unwrap();
345
345
  Ok(())
346
346
  })?;
347
347
  Ok(JsUndefined::new().as_value(&mut cx))
@@ -490,7 +490,7 @@ declare_types! {
490
490
  let this = cx.this();
491
491
  let window = cx.borrow(&this, |x| x.0.as_ref().cloned());
492
492
  let window_adapter = window.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
493
- window_adapter.show();
493
+ window_adapter.show().unwrap();
494
494
  Ok(JsUndefined::new().as_value(&mut cx))
495
495
  }
496
496
 
@@ -498,7 +498,7 @@ declare_types! {
498
498
  let this = cx.this();
499
499
  let window = cx.borrow(&this, |x| x.0.as_ref().cloned());
500
500
  let window_adapter = window.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
501
- window_adapter.hide();
501
+ window_adapter.hide().unwrap();
502
502
  Ok(JsUndefined::new().as_value(&mut cx))
503
503
  }
504
504
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slint-ui",
3
- "version": "0.3.4",
3
+ "version": "1.0.0",
4
4
  "homepage": "https://github.com/slint-ui/slint",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "repository": {
@@ -17,9 +17,9 @@
17
17
  "scripts": {
18
18
  "install": "neon build --release && tsc",
19
19
  "build": "tsc",
20
- "docs": "typedoc lib/index.ts"
20
+ "docs": "typedoc --hideGenerator --readme cover.md lib/index.ts"
21
21
  },
22
22
  "devDependencies": {
23
23
  "typedoc": "^0.19.2"
24
24
  }
25
- }
25
+ }