slint-ui 0.2.5 → 0.3.1
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/LICENSE.md +1 -1
- package/LICENSES/LicenseRef-Slint-commercial.md +278 -4
- package/README.md +1 -1
- package/lib/index.ts +59 -3
- package/native/Cargo.toml +4 -4
- package/native/lib.rs +126 -17
- package/package.json +1 -1
- package/dist/index.d.ts +0 -157
- package/dist/index.js +0 -163
package/LICENSE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Slint License
|
|
2
2
|
|
|
3
3
|
Slint is available under either a [commercial license](LICENSES/LicenseRef-Slint-commercial.md)
|
|
4
|
-
or
|
|
4
|
+
or [GNU GPLv3](LICENSES/GPL-3.0-only.txt), at your choice.
|
|
5
5
|
|
|
6
6
|
Third party licenses listed in the `LICENSES` folder also apply to parts of the product.
|
|
@@ -1,6 +1,280 @@
|
|
|
1
|
-
|
|
1
|
+
# Slint Software License Agreement
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Version 1.2
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
Copyright © 2022 SixtyFPS GmbH <https://slint-ui.com/imprint.html>
|
|
6
|
+
|
|
7
|
+
SixtyFPS GmbH with offices at Oranienburger Str. 44, 16540 Hohen Neuendorf,
|
|
8
|
+
Germany (**SixtyFPS**, **us**, **we** or **our**) grants a license to the
|
|
9
|
+
software (**Licensed Software**), as specified herein, subject to the Terms and
|
|
10
|
+
Conditions of this Slint Software License Agreement (**Agreement**).
|
|
11
|
+
|
|
12
|
+
By using the Licensed Software, **you** agree to be bound by this Agreement.
|
|
13
|
+
**If you do not agree, do not use the Licensed Software.** If you are accessing
|
|
14
|
+
and using the Licensed Software on behalf of a company (such as your employer)
|
|
15
|
+
or other legal entity, you represent and warrant that you have the authority to
|
|
16
|
+
bind that company or other legal entity to this Agreement. In that case, **you**
|
|
17
|
+
and **your** will refer to that company or other legal entity.
|
|
18
|
+
|
|
19
|
+
Each Party to this Agreement may be referred to herein individually as a
|
|
20
|
+
**Party** or collectively as the **Parties**.
|
|
21
|
+
|
|
22
|
+
## Licensed Software
|
|
23
|
+
|
|
24
|
+
The Licensed Software includes
|
|
25
|
+
|
|
26
|
+
1. Slint compiler tool to translate Slint Design Markup Language files to Rust
|
|
27
|
+
(last stable Rust version at the time of licensed Slint version) and C++
|
|
28
|
+
(second last C++ version at the time of licensed Slint version),
|
|
29
|
+
|
|
30
|
+
2. Slint run-time library that can render interactive user-interfaces and
|
|
31
|
+
provides Rust and C++ APIs (as per above versioning) to control the
|
|
32
|
+
interfaces,
|
|
33
|
+
|
|
34
|
+
3. API Documentation for Slint and reference documentation for Slint Design
|
|
35
|
+
Markup Language, and
|
|
36
|
+
|
|
37
|
+
4. Source code of Slint.
|
|
38
|
+
|
|
39
|
+
## Terms and Conditions
|
|
40
|
+
|
|
41
|
+
1. The Licensed Software is protected by copyright laws and international
|
|
42
|
+
copyright treaties, as well as other intellectual property laws and
|
|
43
|
+
treaties. The Licensed Software is licensed, not sold.
|
|
44
|
+
|
|
45
|
+
2. The Licensed Software may provide links to third Party libraries or code
|
|
46
|
+
(collectively **Third Party Libraries**) to implement various functions.
|
|
47
|
+
Third Party Libraries do not comprise part of the Licensed Software. In some
|
|
48
|
+
cases, access to Third Party Libraries may be included along with the
|
|
49
|
+
Licensed Software delivery as a convenience for development and testing
|
|
50
|
+
only. You acknowledge:
|
|
51
|
+
|
|
52
|
+
1. that some Third-Party Libraries may require additional licensing of
|
|
53
|
+
copyright and/or patents from the owners of such, and
|
|
54
|
+
|
|
55
|
+
2. that distribution of any of the Licensed Software referencing any portion
|
|
56
|
+
of a Third-Party Library may require appropriate licensing from such
|
|
57
|
+
third parties. All such Third Party Libraries, along with applicable
|
|
58
|
+
copyright notices and licenses, will be listed and made available to
|
|
59
|
+
you.
|
|
60
|
+
|
|
61
|
+
3. As part of the license grant, a Slint Software License Certificate
|
|
62
|
+
(**License Certificate**) will be issued containing details of
|
|
63
|
+
|
|
64
|
+
1. the license grant,
|
|
65
|
+
|
|
66
|
+
2. the permitted scope of your use of the Licensed Software, and
|
|
67
|
+
|
|
68
|
+
3. your contact details.
|
|
69
|
+
|
|
70
|
+
In case of any changes or deviations to the information noted in the License
|
|
71
|
+
Certificate, you are obliged to notify us in writing, not later than 7 days
|
|
72
|
+
after any such change or deviation has occured.
|
|
73
|
+
|
|
74
|
+
4. The Term of this Agreement shall begin on the date mentioned in the License
|
|
75
|
+
Certificate (**Effective Date**) and shall continue unless terminated
|
|
76
|
+
earlier as herein provided (**Term**).
|
|
77
|
+
|
|
78
|
+
5. New releases of the Licensed Software (**Updates**) will be made available
|
|
79
|
+
to you for the period (**Maintenance Period**) specified in the License
|
|
80
|
+
Certificate. Such Updates may be bound by additional license terms. You
|
|
81
|
+
consent to any such additional license terms, without which you may not
|
|
82
|
+
install, copy, or otherwise use such Updates.
|
|
83
|
+
|
|
84
|
+
6. The Licensed Software is to be used exclusively with your software
|
|
85
|
+
products (**Products**) specified in the License Certificate.
|
|
86
|
+
|
|
87
|
+
7. We grant you a perpetual, non-exclusive, non-transferable right to use the
|
|
88
|
+
Licensed Software, including making modifications, for the sole purposes of
|
|
89
|
+
designing, developing, and testing your Products during the Term. The number
|
|
90
|
+
of **Users** using the Licensed Software to design, develop and test your
|
|
91
|
+
Products is limited to the amount of **User Seats** specified in the License
|
|
92
|
+
Certificate. For clarity, each unique User is counted as one User Seat.
|
|
93
|
+
|
|
94
|
+
8. We grant you a perpetual, non-exclusive, non-transferable right to reproduce
|
|
95
|
+
and distribute the object code form of the Licensed Software, including any
|
|
96
|
+
modifications made to the Licensed Software, during the Term. Such
|
|
97
|
+
distributions is permitted only with your Products and limited to the amount
|
|
98
|
+
of **Distributions** specified in the License Certificate.
|
|
99
|
+
|
|
100
|
+
9. The license grants are conditional on the full and timely payment of all
|
|
101
|
+
applicable **Fees**; if said Fees are not paid in full and by their due
|
|
102
|
+
date, the license shall not be granted and your Products shall be deemed as
|
|
103
|
+
made in breach of the Agreement ex tunc.
|
|
104
|
+
|
|
105
|
+
10. Clause 9 above shall not apply if the license has been granted to you under
|
|
106
|
+
the **Ambassador** program. Instead, the license grants shall be conditional
|
|
107
|
+
on the fullfilment of the obligations as specified herein. If said
|
|
108
|
+
obligations are not fulfilled, the license shall not be granted and your
|
|
109
|
+
Products shall be deemed as made in breach of the Agreement ex tunc. The
|
|
110
|
+
obligations are as follows:
|
|
111
|
+
|
|
112
|
+
1. Showcase: You grant us the right to use your name, logo and your
|
|
113
|
+
Products in our marketing materials,
|
|
114
|
+
|
|
115
|
+
2. Spread the word: You will include reasonably visible notices in the
|
|
116
|
+
documentation, marketing materials and social media channels related to
|
|
117
|
+
your Products that such were built with the Licensed Software,
|
|
118
|
+
|
|
119
|
+
3. Give feedback: You agree to provide relevant feedback that would
|
|
120
|
+
help us improve the Licensed Software. We may use any such
|
|
121
|
+
feedback in testimonials.
|
|
122
|
+
|
|
123
|
+
11. The Fees and any other charges under this Agreement shall be paid by
|
|
124
|
+
you no later than thirty (30) days from the date of the applicable
|
|
125
|
+
invoice from us. A late payment charge of the lower of (a) one percent
|
|
126
|
+
per month; or (b) the interest rate stipulated by applicable law, shall be
|
|
127
|
+
charged on any unpaid balances that remain past due and which have not been
|
|
128
|
+
disputed by you in good faith.
|
|
129
|
+
|
|
130
|
+
12. The Fees and any other charges payable under this Agreement are gross
|
|
131
|
+
amounts but exclusive of any value added tax, use tax, sales tax,
|
|
132
|
+
withholding tax and other taxes, duties or tariffs levied directly for the
|
|
133
|
+
sale, delivery or use of the Licensed Software pursuant to any applicable
|
|
134
|
+
law.
|
|
135
|
+
|
|
136
|
+
13. The Parties also agree to all of the following conditions:
|
|
137
|
+
|
|
138
|
+
1. You may not remove or alter any copyright, trademark or other
|
|
139
|
+
proprietary rights notice contained in any portion of the Licensed
|
|
140
|
+
Software,
|
|
141
|
+
|
|
142
|
+
2. Your Products may not compete with the Licensed Software,
|
|
143
|
+
|
|
144
|
+
3. You will indemnify and hold us, our affiliated companies and our
|
|
145
|
+
suppliers, harmless from and against any claims or liabilities
|
|
146
|
+
arising out of the use, reproduction or distribution of your
|
|
147
|
+
Products, except as set out in clause 13.4. immediately below,
|
|
148
|
+
|
|
149
|
+
4. We shall indemnify and hold you harmless from and against any
|
|
150
|
+
claims from third parties alleging that the use of the Licensed Software
|
|
151
|
+
as set out in this Agreement infringes or will infringe such third
|
|
152
|
+
parties intellectual property rights or other rights,
|
|
153
|
+
|
|
154
|
+
5. A Party shall promptly notify the other Party if it receives a claim that
|
|
155
|
+
the other Party shall or may be obliged to indemnify. The Parties shall
|
|
156
|
+
promptly give each other information and other assistance needed for
|
|
157
|
+
handling the claim. The Indemnifying Party may, at its cost and in its
|
|
158
|
+
sole discretion, take control of the defense of such claim, including
|
|
159
|
+
the conduct of any litigation or arbitration and the negotiation of any
|
|
160
|
+
settlement, in which case the indemnifying Party shall not compromise or
|
|
161
|
+
settle or otherwise dispose of the claim, in whole or in part, where
|
|
162
|
+
such compromise or settlement or disposal would require any admission or
|
|
163
|
+
stipulation which would reasonably be expected to have an adverse effect
|
|
164
|
+
on the commercial reputation of the indemnified Party, without the prior
|
|
165
|
+
written consent of the indemnified Party. Where the indemnifying Party
|
|
166
|
+
has not taken control of the defense of the claim, the indemnified Party
|
|
167
|
+
shall not compromise or settle or fail adequately to defend or otherwise
|
|
168
|
+
dispose of a claim, in whole or in part, without the written consent of
|
|
169
|
+
the indemnifying Party, such consent not to be unreasonably withheld or
|
|
170
|
+
delayed.
|
|
171
|
+
|
|
172
|
+
14. The Licensed Software is licensed to you "as is". To the maximum extent
|
|
173
|
+
permitted by applicable law, we on behalf of us and our suppliers,
|
|
174
|
+
disclaim all warranties and conditions, either express or implied,
|
|
175
|
+
including, but not limited to, any implied warranties of merchantability or
|
|
176
|
+
fitness for a particular purpose, title and non-infringement with regard to
|
|
177
|
+
the Licensed Software. The warranty disclaimer in the foregoing
|
|
178
|
+
notwithstanding, you may have specific legal rights which may vary from
|
|
179
|
+
state/jurisdiction to state/jurisdiction; as far as legally permissible, you
|
|
180
|
+
waive any such legal rights vis-à-vis us.
|
|
181
|
+
|
|
182
|
+
15. We shall not under any circumstances be liable to you based on failure of
|
|
183
|
+
the Licensed Software if the failure resulted from your changing of the
|
|
184
|
+
Licensed Software, from your accident, abuse or misapplication, nor shall
|
|
185
|
+
we except in case of gross negligence or willful misconduct be
|
|
186
|
+
liable for special damages, punitive or exemplary damages, damages for loss
|
|
187
|
+
of profits or interruption of business or for loss or corruption of data,
|
|
188
|
+
nor shall any award of damages exceed the total amount you paid to us in
|
|
189
|
+
connection with this Agreement.
|
|
190
|
+
|
|
191
|
+
16. Each Party shall hold Confidential Information of the other Party, its
|
|
192
|
+
customers, and licensors in confidence, and without written permission from
|
|
193
|
+
will not disclose to any person or use for its own benefit, any such
|
|
194
|
+
information. **Confidential Information** includes without limitation the
|
|
195
|
+
terms of this Agreement, computer software programs developed or licensed by
|
|
196
|
+
the Parties, including all documentation and methods or concepts utilized
|
|
197
|
+
therein, all adaptations and modifications thereto and derivative works
|
|
198
|
+
thereof, and related materials and information. Confidential Information
|
|
199
|
+
also includes any other information identified by either Party, its
|
|
200
|
+
licensors, or customers as proprietary or confidential, or which would
|
|
201
|
+
reasonably be understood under the circumstances to be confidential. All
|
|
202
|
+
Confidential Information shall remain the sole property of each respective
|
|
203
|
+
Party. Information will not be considered to be Confidential Information if
|
|
204
|
+
|
|
205
|
+
1. available to the public other than by a breach of this Agreement;
|
|
206
|
+
|
|
207
|
+
2. rightfully received from a third Party not in breach of any obligation of
|
|
208
|
+
confidentiality;
|
|
209
|
+
|
|
210
|
+
3. independently developed by a Party without access to Confidential
|
|
211
|
+
Information of the other Party;
|
|
212
|
+
|
|
213
|
+
4. known to the other Party at the time of disclosure;
|
|
214
|
+
|
|
215
|
+
5. produced in compliance with applicable law or a court order, provided the
|
|
216
|
+
other Party is given notice and opportunity to intervene; or
|
|
217
|
+
|
|
218
|
+
6. it does not constitute a trade secret and more than five (5) years have
|
|
219
|
+
elapsed from the date of disclosure. In addition to any other rights or
|
|
220
|
+
remedies available, each Party shall be entitled to enforcement of such
|
|
221
|
+
obligations by court injunction.
|
|
222
|
+
|
|
223
|
+
17. During the Term, an independent, certified auditor on our behalf, may, upon
|
|
224
|
+
its reasonable request, with 30 (thirty) days written notice, and at its
|
|
225
|
+
sole expense, examine your books and records solely with respect to your use
|
|
226
|
+
of the Licensed Software. Any such audit shall be conducted during regular
|
|
227
|
+
business hours at your facilities and shall not unreasonably interfere with
|
|
228
|
+
your business activities. Our auditor shall not remove, copy, or
|
|
229
|
+
redistribute any electronic material during the course of an audit. If an
|
|
230
|
+
audit reveals that you are using the Licensed Software in a way that is in
|
|
231
|
+
material violation of the terms of this Agreement, then you shall pay us
|
|
232
|
+
reasonable costs of conducting the audit. Our auditor shall only be allowed
|
|
233
|
+
to report violations of the terms of this Agreement, with a copy to you. You
|
|
234
|
+
shall be provided the right to provide comments to the report before it is
|
|
235
|
+
finalized.
|
|
236
|
+
|
|
237
|
+
18. If you materially breach this Agreement, we will provide a 60 (sixty) days
|
|
238
|
+
written notice to you during which any such breach(es) may be cured, failing
|
|
239
|
+
which we will terminate the agreement. You undertake to pay a contractual
|
|
240
|
+
penalty for each case of negligent breach of this Agreement of EUR 10000
|
|
241
|
+
(ten thousand euros), which shall not be subject to a judicial right of
|
|
242
|
+
reduction. We shall in any case be free to assert any further damage/loss or
|
|
243
|
+
other claims. The amount of contractual penalty shall be offset against
|
|
244
|
+
claims for damages, if any.
|
|
245
|
+
|
|
246
|
+
19. You may terminate this Agreement at any time for any reason upon 90 (ninety)
|
|
247
|
+
days notice to us and upon payment of all applicable fees and contractual
|
|
248
|
+
penalties, if any, in connection with the use of the Licensed Software.
|
|
249
|
+
|
|
250
|
+
20. Both Parties shall comply with all applicable laws and regulations relating
|
|
251
|
+
to the Licensed Software in the countries in which the Parties use or modify
|
|
252
|
+
the Licensed Software.
|
|
253
|
+
|
|
254
|
+
21. All notices and communications between the Parties shall be in writing and
|
|
255
|
+
shall be deemed given when received. For avoidance of doubt, email is
|
|
256
|
+
considered a written form of communication.
|
|
257
|
+
|
|
258
|
+
22. This Agreement shall be construed, interpreted and governed by the laws of
|
|
259
|
+
the Federal Republic of Germany.
|
|
260
|
+
|
|
261
|
+
23. No term or condition contained in your purchase order will apply unless
|
|
262
|
+
expressly accepted by us in writing.
|
|
263
|
+
|
|
264
|
+
24. You may assign this Agreement, in whole or in part (whether by operation of
|
|
265
|
+
law or otherwise), with prior consent from us, which shall not be
|
|
266
|
+
unreasonably withheld or delayed. We may assign this Agreement or any of its
|
|
267
|
+
rights hereunder or delegate any of its obligations hereunder with prior
|
|
268
|
+
notice to you. Any attempt to assign this Agreement other than in accordance
|
|
269
|
+
with this provision shall be null and void.
|
|
270
|
+
|
|
271
|
+
25. This Agreement constitutes the complete agreement between the Parties and
|
|
272
|
+
supersedes all prior or contemporaneous discussions, representations, and
|
|
273
|
+
proposals, written or oral, with respect to the subject matters discussed
|
|
274
|
+
herein. No modification of this Agreement will be effective unless contained
|
|
275
|
+
in a written document executed by an authorized representative of each
|
|
276
|
+
Party. If any provision of the Agreement is found void or unenforceable, the
|
|
277
|
+
remainder will remain valid and enforceable according to its terms. If any
|
|
278
|
+
remedy provided is determined to have failed for its essential purpose, all
|
|
279
|
+
limitations of liability and exclusions of damages set forth in this
|
|
280
|
+
Agreement shall remain in effect.
|
package/README.md
CHANGED
package/lib/index.ts
CHANGED
|
@@ -41,8 +41,8 @@ class Component {
|
|
|
41
41
|
this.window.hide()
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
get window():
|
|
45
|
-
return this.comp.window();
|
|
44
|
+
get window(): SlintWindow {
|
|
45
|
+
return new WindowAPI(this.comp.window());
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
send_mouse_click(x: number, y: number) {
|
|
@@ -54,9 +54,65 @@ class Component {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
interface
|
|
57
|
+
interface Point {
|
|
58
|
+
x: number;
|
|
59
|
+
y: number;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface Size {
|
|
63
|
+
width: number;
|
|
64
|
+
height: number;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface SlintWindow {
|
|
58
68
|
show(): void;
|
|
59
69
|
hide(): void;
|
|
70
|
+
logical_position: Point;
|
|
71
|
+
physical_position: Point;
|
|
72
|
+
logical_size: Size;
|
|
73
|
+
physical_size: Size;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @hidden
|
|
78
|
+
*/
|
|
79
|
+
class WindowAPI implements SlintWindow {
|
|
80
|
+
protected impl: any;
|
|
81
|
+
|
|
82
|
+
constructor(impl: any) {
|
|
83
|
+
this.impl = impl;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
show(): void {
|
|
87
|
+
this.impl.show();
|
|
88
|
+
}
|
|
89
|
+
hide(): void {
|
|
90
|
+
this.impl.hide();
|
|
91
|
+
}
|
|
92
|
+
get logical_position(): Point {
|
|
93
|
+
return this.impl.get_logical_position();
|
|
94
|
+
}
|
|
95
|
+
set logical_position(pos: Point) {
|
|
96
|
+
this.impl.set_logical_position(pos);
|
|
97
|
+
}
|
|
98
|
+
get physical_position(): Point {
|
|
99
|
+
return this.impl.get_physical_position();
|
|
100
|
+
}
|
|
101
|
+
set physical_position(pos: Point) {
|
|
102
|
+
this.impl.set_physical_position(pos);
|
|
103
|
+
}
|
|
104
|
+
get logical_size(): Size {
|
|
105
|
+
return this.impl.get_logical_size();
|
|
106
|
+
}
|
|
107
|
+
set logical_size(size: Size) {
|
|
108
|
+
this.impl.set_logical_size(size);
|
|
109
|
+
}
|
|
110
|
+
get physical_size(): Size {
|
|
111
|
+
return this.impl.get_physical_size();
|
|
112
|
+
}
|
|
113
|
+
set physical_size(size: Size) {
|
|
114
|
+
this.impl.set_physical_size(size);
|
|
115
|
+
}
|
|
60
116
|
}
|
|
61
117
|
|
|
62
118
|
/**
|
package/native/Cargo.toml
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
[package]
|
|
5
5
|
name = "slint-node"
|
|
6
|
-
version = "0.
|
|
6
|
+
version = "0.3.1"
|
|
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.
|
|
24
|
-
i-slint-core = { version = "=0.
|
|
25
|
-
slint-interpreter = { version = "=0.
|
|
23
|
+
i-slint-compiler = { version = "=0.3.1"}
|
|
24
|
+
i-slint-core = { version = "=0.3.1"}
|
|
25
|
+
slint-interpreter = { version = "=0.3.1", features = ["display-diagnostics"] }
|
|
26
26
|
|
|
27
27
|
vtable = { version = "0.1.6"}
|
|
28
28
|
|
package/native/lib.rs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
use core::cell::RefCell;
|
|
5
5
|
use i_slint_compiler::langtype::Type;
|
|
6
6
|
use i_slint_core::model::{Model, ModelRc};
|
|
7
|
-
use i_slint_core::window::
|
|
7
|
+
use i_slint_core::window::WindowInner;
|
|
8
8
|
use i_slint_core::{ImageInner, SharedVector};
|
|
9
9
|
use neon::prelude::*;
|
|
10
10
|
use rand::RngCore;
|
|
@@ -15,7 +15,7 @@ mod persistent_context;
|
|
|
15
15
|
|
|
16
16
|
struct WrappedComponentType(Option<slint_interpreter::ComponentDefinition>);
|
|
17
17
|
struct WrappedComponentRc(Option<slint_interpreter::ComponentInstance>);
|
|
18
|
-
struct WrappedWindow(Option<i_slint_core::window::
|
|
18
|
+
struct WrappedWindow(Option<std::rc::Rc<dyn i_slint_core::window::WindowAdapter>>);
|
|
19
19
|
|
|
20
20
|
/// We need to do some gymnastic with closures to pass the ExecuteContext with the right lifetime
|
|
21
21
|
type GlobalContextCallback<'c> =
|
|
@@ -228,13 +228,10 @@ fn to_eval_value<'cx>(
|
|
|
228
228
|
| Type::Void
|
|
229
229
|
| Type::InferredProperty
|
|
230
230
|
| Type::InferredCallback
|
|
231
|
-
| Type::Builtin(_)
|
|
232
|
-
| Type::Native(_)
|
|
233
231
|
| Type::Function { .. }
|
|
234
232
|
| Type::Model
|
|
235
233
|
| Type::Callback { .. }
|
|
236
234
|
| Type::Easing
|
|
237
|
-
| Type::Component(_)
|
|
238
235
|
| Type::PathData
|
|
239
236
|
| Type::LayoutCache
|
|
240
237
|
| Type::ElementReference => cx.throw_error("Cannot convert to a Slint property value"),
|
|
@@ -254,12 +251,10 @@ fn to_js_value<'cx>(
|
|
|
254
251
|
Value::Bool(b) => JsBoolean::new(cx, b).as_value(cx),
|
|
255
252
|
Value::Image(r) => match (&r).into() {
|
|
256
253
|
&ImageInner::None => JsUndefined::new().as_value(cx),
|
|
257
|
-
&ImageInner::
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
&ImageInner::
|
|
261
|
-
| &ImageInner::EmbeddedImage { .. }
|
|
262
|
-
| &ImageInner::StaticTextures { .. } => JsNull::new().as_value(cx), // TODO: maybe pass around node buffers?
|
|
254
|
+
&ImageInner::EmbeddedImage { .. }
|
|
255
|
+
| &ImageInner::StaticTextures { .. }
|
|
256
|
+
| &ImageInner::Svg(..)
|
|
257
|
+
| &ImageInner::BackendStorage(..) => JsNull::new().as_value(cx), // TODO: maybe pass around node buffers?
|
|
263
258
|
},
|
|
264
259
|
Value::Model(model) => {
|
|
265
260
|
if let Some(js_model) = model.as_any().downcast_ref::<js_model::JsModel>() {
|
|
@@ -354,9 +349,9 @@ declare_types! {
|
|
|
354
349
|
let this = cx.this();
|
|
355
350
|
let component = cx.borrow(&this, |x| x.0.as_ref().map(|c| c.clone_strong()));
|
|
356
351
|
let component = component.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
|
357
|
-
let
|
|
352
|
+
let window_adapter = WindowInner::from_pub(component.window()).window_adapter();
|
|
358
353
|
let mut obj = SlintWindow::new::<_, JsValue, _>(&mut cx, std::iter::empty())?;
|
|
359
|
-
cx.borrow_mut(&mut obj, |mut obj| obj.0 = Some(
|
|
354
|
+
cx.borrow_mut(&mut obj, |mut obj| obj.0 = Some(window_adapter));
|
|
360
355
|
Ok(obj.as_value(&mut cx))
|
|
361
356
|
}
|
|
362
357
|
method get_property(mut cx) {
|
|
@@ -493,16 +488,130 @@ declare_types! {
|
|
|
493
488
|
method show(mut cx) {
|
|
494
489
|
let this = cx.this();
|
|
495
490
|
let window = cx.borrow(&this, |x| x.0.as_ref().cloned());
|
|
496
|
-
let
|
|
497
|
-
|
|
491
|
+
let window_adapter = window.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
|
492
|
+
window_adapter.show();
|
|
498
493
|
Ok(JsUndefined::new().as_value(&mut cx))
|
|
499
494
|
}
|
|
500
495
|
|
|
501
496
|
method hide(mut cx) {
|
|
502
497
|
let this = cx.this();
|
|
503
498
|
let window = cx.borrow(&this, |x| x.0.as_ref().cloned());
|
|
504
|
-
let
|
|
505
|
-
|
|
499
|
+
let window_adapter = window.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
|
500
|
+
window_adapter.hide();
|
|
501
|
+
Ok(JsUndefined::new().as_value(&mut cx))
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
method get_logical_position(mut cx) {
|
|
505
|
+
let this = cx.this();
|
|
506
|
+
let window = cx.borrow(&this, |x| x.0.as_ref().cloned());
|
|
507
|
+
let window_adapter = window.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
|
508
|
+
let pos = window_adapter.position().to_logical(window_adapter.window().scale_factor());
|
|
509
|
+
|
|
510
|
+
let point_object = JsObject::new(&mut cx);
|
|
511
|
+
let x_value = JsNumber::new(&mut cx, pos.x).as_value(&mut cx);
|
|
512
|
+
point_object.set(&mut cx, "x", x_value)?;
|
|
513
|
+
let y_value = JsNumber::new(&mut cx, pos.y).as_value(&mut cx);
|
|
514
|
+
point_object.set(&mut cx, "y", y_value)?;
|
|
515
|
+
Ok(point_object.as_value(&mut cx))
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
method get_physical_position(mut cx) {
|
|
519
|
+
let this = cx.this();
|
|
520
|
+
let window = cx.borrow(&this, |x| x.0.as_ref().cloned());
|
|
521
|
+
let window_adapter = window.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
|
522
|
+
let pos = window_adapter.position();
|
|
523
|
+
|
|
524
|
+
let point_object = JsObject::new(&mut cx);
|
|
525
|
+
let x_value = JsNumber::new(&mut cx, pos.x).as_value(&mut cx);
|
|
526
|
+
point_object.set(&mut cx, "x", x_value)?;
|
|
527
|
+
let y_value = JsNumber::new(&mut cx, pos.y).as_value(&mut cx);
|
|
528
|
+
point_object.set(&mut cx, "y", y_value)?;
|
|
529
|
+
Ok(point_object.as_value(&mut cx))
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
method set_logical_position(mut cx) {
|
|
533
|
+
let this = cx.this();
|
|
534
|
+
let window = cx.borrow(&this, |x| x.0.as_ref().cloned());
|
|
535
|
+
let window_adapter = window.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
|
536
|
+
|
|
537
|
+
let point_object = cx.argument::<JsObject>(0)?;
|
|
538
|
+
let x = point_object.get(&mut cx, "x")?.downcast_or_throw::<JsNumber, _>(&mut cx)?.value();
|
|
539
|
+
let y = point_object.get(&mut cx, "y")?.downcast_or_throw::<JsNumber, _>(&mut cx)?.value();
|
|
540
|
+
|
|
541
|
+
window_adapter.set_position(i_slint_core::api::LogicalPosition::new(x as f32, y as f32).into());
|
|
542
|
+
|
|
543
|
+
Ok(JsUndefined::new().as_value(&mut cx))
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
method set_physical_position(mut cx) {
|
|
547
|
+
let this = cx.this();
|
|
548
|
+
let window = cx.borrow(&this, |x| x.0.as_ref().cloned());
|
|
549
|
+
let window_adapter = window.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
|
550
|
+
|
|
551
|
+
let point_object = cx.argument::<JsObject>(0)?;
|
|
552
|
+
let x = point_object.get(&mut cx, "x")?.downcast_or_throw::<JsNumber, _>(&mut cx)?.value();
|
|
553
|
+
let y = point_object.get(&mut cx, "y")?.downcast_or_throw::<JsNumber, _>(&mut cx)?.value();
|
|
554
|
+
|
|
555
|
+
window_adapter.set_position(i_slint_core::api::PhysicalPosition::new(x as i32, y as i32).into());
|
|
556
|
+
|
|
557
|
+
Ok(JsUndefined::new().as_value(&mut cx))
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
method get_logical_size(mut cx) {
|
|
561
|
+
let this = cx.this();
|
|
562
|
+
let window_adapter = cx.borrow(&this, |x| x.0.as_ref().cloned());
|
|
563
|
+
let window_adapter = window_adapter.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
|
564
|
+
let size = window_adapter.window().size().to_logical(window_adapter.window().scale_factor());
|
|
565
|
+
|
|
566
|
+
let size_object = JsObject::new(&mut cx);
|
|
567
|
+
let width_value = JsNumber::new(&mut cx, size.width).as_value(&mut cx);
|
|
568
|
+
size_object.set(&mut cx, "width", width_value)?;
|
|
569
|
+
let height_value = JsNumber::new(&mut cx, size.height).as_value(&mut cx);
|
|
570
|
+
size_object.set(&mut cx, "height", height_value)?;
|
|
571
|
+
Ok(size_object.as_value(&mut cx))
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
method get_physical_size(mut cx) {
|
|
575
|
+
let this = cx.this();
|
|
576
|
+
let window_adapter = cx.borrow(&this, |x| x.0.as_ref().cloned());
|
|
577
|
+
let window_adapter = window_adapter.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
|
578
|
+
let size = window_adapter.window().size();
|
|
579
|
+
|
|
580
|
+
let size_object = JsObject::new(&mut cx);
|
|
581
|
+
let width_value = JsNumber::new(&mut cx, size.width).as_value(&mut cx);
|
|
582
|
+
size_object.set(&mut cx, "width", width_value)?;
|
|
583
|
+
let height_value = JsNumber::new(&mut cx, size.height).as_value(&mut cx);
|
|
584
|
+
size_object.set(&mut cx, "height", height_value)?;
|
|
585
|
+
Ok(size_object.as_value(&mut cx))
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
method set_logical_size(mut cx) {
|
|
589
|
+
let this = cx.this();
|
|
590
|
+
let window_adapter = cx.borrow(&this, |x| x.0.as_ref().cloned());
|
|
591
|
+
let window_adapter = window_adapter.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
|
592
|
+
let window = window_adapter.window();
|
|
593
|
+
|
|
594
|
+
let size_object = cx.argument::<JsObject>(0)?;
|
|
595
|
+
let width = size_object.get(&mut cx, "width")?.downcast_or_throw::<JsNumber, _>(&mut cx)?.value();
|
|
596
|
+
let height = size_object.get(&mut cx, "height")?.downcast_or_throw::<JsNumber, _>(&mut cx)?.value();
|
|
597
|
+
|
|
598
|
+
window.set_size(i_slint_core::api::LogicalSize::new(width as f32, height as f32));
|
|
599
|
+
|
|
600
|
+
Ok(JsUndefined::new().as_value(&mut cx))
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
method set_physical_size(mut cx) {
|
|
604
|
+
let this = cx.this();
|
|
605
|
+
let window_adapter = cx.borrow(&this, |x| x.0.as_ref().cloned());
|
|
606
|
+
let window_adapter = window_adapter.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
|
607
|
+
let window = window_adapter.window();
|
|
608
|
+
|
|
609
|
+
let size_object = cx.argument::<JsObject>(0)?;
|
|
610
|
+
let width = size_object.get(&mut cx, "width")?.downcast_or_throw::<JsNumber, _>(&mut cx)?.value();
|
|
611
|
+
let height = size_object.get(&mut cx, "height")?.downcast_or_throw::<JsNumber, _>(&mut cx)?.value();
|
|
612
|
+
|
|
613
|
+
window.set_size(i_slint_core::api::PhysicalSize::new(width as u32, height as u32));
|
|
614
|
+
|
|
506
615
|
Ok(JsUndefined::new().as_value(&mut cx))
|
|
507
616
|
}
|
|
508
617
|
}
|
package/package.json
CHANGED
package/dist/index.d.ts
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @hidden
|
|
3
|
-
*/
|
|
4
|
-
declare function load_native_lib(): any;
|
|
5
|
-
/**
|
|
6
|
-
* @hidden
|
|
7
|
-
*/
|
|
8
|
-
declare let native: any;
|
|
9
|
-
/**
|
|
10
|
-
* @hidden
|
|
11
|
-
*/
|
|
12
|
-
declare class Component {
|
|
13
|
-
protected comp: any;
|
|
14
|
-
constructor(comp: any);
|
|
15
|
-
run(): void;
|
|
16
|
-
show(): void;
|
|
17
|
-
hide(): void;
|
|
18
|
-
get window(): SlintWindow;
|
|
19
|
-
send_mouse_click(x: number, y: number): void;
|
|
20
|
-
send_keyboard_string_sequence(s: String): void;
|
|
21
|
-
}
|
|
22
|
-
interface Point {
|
|
23
|
-
x: Number;
|
|
24
|
-
y: Number;
|
|
25
|
-
}
|
|
26
|
-
interface SlintWindow {
|
|
27
|
-
show(): void;
|
|
28
|
-
hide(): void;
|
|
29
|
-
position: Point;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* @hidden
|
|
33
|
-
*/
|
|
34
|
-
declare class WindowAPI implements SlintWindow {
|
|
35
|
-
protected impl: any;
|
|
36
|
-
constructor(impl: any);
|
|
37
|
-
show(): void;
|
|
38
|
-
hide(): void;
|
|
39
|
-
get position(): Point;
|
|
40
|
-
set position(pos: Point);
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* @hidden
|
|
44
|
-
*/
|
|
45
|
-
interface Callback {
|
|
46
|
-
(): any;
|
|
47
|
-
setHandler(cb: any): void;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* ModelPeer is the interface that the run-time implements. An instance is
|
|
51
|
-
* set on dynamic Model<T> instances and can be used to notify the run-time
|
|
52
|
-
* of changes in the structure or data of the model.
|
|
53
|
-
*/
|
|
54
|
-
interface ModelPeer {
|
|
55
|
-
/**
|
|
56
|
-
* Call this function from our own model to notify that fields of data
|
|
57
|
-
* in the specified row have changed.
|
|
58
|
-
* @argument row
|
|
59
|
-
*/
|
|
60
|
-
rowDataChanged(row: number): void;
|
|
61
|
-
/**
|
|
62
|
-
* Call this function from your own model to notify that one or multiple
|
|
63
|
-
* rows were added to the model, starting at the specified row.
|
|
64
|
-
* @param row
|
|
65
|
-
* @param count
|
|
66
|
-
*/
|
|
67
|
-
rowAdded(row: number, count: number): void;
|
|
68
|
-
/**
|
|
69
|
-
* Call this function from your own model to notify that one or multiple
|
|
70
|
-
* rows were removed from the model, starting at the specified row.
|
|
71
|
-
* @param row
|
|
72
|
-
* @param count
|
|
73
|
-
*/
|
|
74
|
-
rowRemoved(row: number, count: number): void;
|
|
75
|
-
/**
|
|
76
|
-
* Call this function from your own model to notify that the model has been
|
|
77
|
-
* changed and everything must be reloaded
|
|
78
|
-
*/
|
|
79
|
-
reset(): void;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Model<T> is the interface for feeding dynamic data into
|
|
83
|
-
* `.slint` views.
|
|
84
|
-
*
|
|
85
|
-
* A model is organized like a table with rows of data. The
|
|
86
|
-
* fields of the data type T behave like columns.
|
|
87
|
-
*/
|
|
88
|
-
interface Model<T> {
|
|
89
|
-
/**
|
|
90
|
-
* Implementations of this function must return the current number of rows.
|
|
91
|
-
*/
|
|
92
|
-
rowCount(): number;
|
|
93
|
-
/**
|
|
94
|
-
* Implementations of this function must return the data at the specified row.
|
|
95
|
-
* @param row
|
|
96
|
-
*/
|
|
97
|
-
rowData(row: number): T;
|
|
98
|
-
/**
|
|
99
|
-
* Implementations of this function must store the provided data parameter
|
|
100
|
-
* in the model at the specified row.
|
|
101
|
-
* @param row
|
|
102
|
-
* @param data
|
|
103
|
-
*/
|
|
104
|
-
setRowData(row: number, data: T): void;
|
|
105
|
-
/**
|
|
106
|
-
* This public member is set by the run-time and implementation must use this
|
|
107
|
-
* to notify the run-time of changes in the model.
|
|
108
|
-
*/
|
|
109
|
-
notify: ModelPeer;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* @hidden
|
|
113
|
-
*/
|
|
114
|
-
declare class NullPeer implements ModelPeer {
|
|
115
|
-
rowDataChanged(row: number): void;
|
|
116
|
-
rowAdded(row: number, count: number): void;
|
|
117
|
-
rowRemoved(row: number, count: number): void;
|
|
118
|
-
reset(): void;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* ArrayModel wraps a JavaScript array for use in `.slint` views. The underlying
|
|
122
|
-
* array can be modified with the [[ArrayModel.push]] and [[ArrayModel.remove]] methods.
|
|
123
|
-
*/
|
|
124
|
-
declare class ArrayModel<T> implements Model<T> {
|
|
125
|
-
/**
|
|
126
|
-
* @hidden
|
|
127
|
-
*/
|
|
128
|
-
private a;
|
|
129
|
-
notify: ModelPeer;
|
|
130
|
-
/**
|
|
131
|
-
* Creates a new ArrayModel.
|
|
132
|
-
*
|
|
133
|
-
* @param arr
|
|
134
|
-
*/
|
|
135
|
-
constructor(arr: Array<T>);
|
|
136
|
-
rowCount(): number;
|
|
137
|
-
rowData(row: number): T;
|
|
138
|
-
setRowData(row: number, data: T): void;
|
|
139
|
-
/**
|
|
140
|
-
* Pushes new values to the array that's backing the model and notifies
|
|
141
|
-
* the run-time about the added rows.
|
|
142
|
-
* @param values
|
|
143
|
-
*/
|
|
144
|
-
push(...values: T[]): void;
|
|
145
|
-
/**
|
|
146
|
-
* Removes the specified number of element from the array that's backing
|
|
147
|
-
* the model, starting at the specified index. This is equivalent to calling
|
|
148
|
-
* Array.slice() on the array and notifying the run-time about the removed
|
|
149
|
-
* rows.
|
|
150
|
-
* @param index
|
|
151
|
-
* @param size
|
|
152
|
-
*/
|
|
153
|
-
remove(index: number, size: number): void;
|
|
154
|
-
get length(): number;
|
|
155
|
-
values(): IterableIterator<T>;
|
|
156
|
-
entries(): IterableIterator<[number, T]>;
|
|
157
|
-
}
|
package/dist/index.js
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
|
|
3
|
-
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
|
|
4
|
-
// Load the native library with `process.dlopen` instead of with `require`.
|
|
5
|
-
// This is only done for autotest that do not require nom or neon_cli to
|
|
6
|
-
// copy the lib to its right place
|
|
7
|
-
/**
|
|
8
|
-
* @hidden
|
|
9
|
-
*/
|
|
10
|
-
function load_native_lib() {
|
|
11
|
-
const os = require('os');
|
|
12
|
-
process.dlopen(module, process.env.SLINT_NODE_NATIVE_LIB, os.constants.dlopen.RTLD_NOW);
|
|
13
|
-
return module.exports;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* @hidden
|
|
17
|
-
*/
|
|
18
|
-
let native = !process.env.SLINT_NODE_NATIVE_LIB ? require('../native/index.node') : load_native_lib();
|
|
19
|
-
/**
|
|
20
|
-
* @hidden
|
|
21
|
-
*/
|
|
22
|
-
class Component {
|
|
23
|
-
constructor(comp) {
|
|
24
|
-
this.comp = comp;
|
|
25
|
-
}
|
|
26
|
-
run() {
|
|
27
|
-
this.comp.run();
|
|
28
|
-
}
|
|
29
|
-
show() {
|
|
30
|
-
this.window.show();
|
|
31
|
-
}
|
|
32
|
-
hide() {
|
|
33
|
-
this.window.hide();
|
|
34
|
-
}
|
|
35
|
-
get window() {
|
|
36
|
-
return new WindowAPI(this.comp.window());
|
|
37
|
-
}
|
|
38
|
-
send_mouse_click(x, y) {
|
|
39
|
-
this.comp.send_mouse_click(x, y);
|
|
40
|
-
}
|
|
41
|
-
send_keyboard_string_sequence(s) {
|
|
42
|
-
this.comp.send_keyboard_string_sequence(s);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* @hidden
|
|
47
|
-
*/
|
|
48
|
-
class WindowAPI {
|
|
49
|
-
constructor(impl) {
|
|
50
|
-
this.impl = impl;
|
|
51
|
-
}
|
|
52
|
-
show() {
|
|
53
|
-
this.impl.show();
|
|
54
|
-
}
|
|
55
|
-
hide() {
|
|
56
|
-
this.impl.hide();
|
|
57
|
-
}
|
|
58
|
-
get position() {
|
|
59
|
-
return this.impl.get_position();
|
|
60
|
-
}
|
|
61
|
-
set position(pos) {
|
|
62
|
-
this.impl.set_position(pos);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
require.extensions['.60'] = require.extensions['.slint'] =
|
|
66
|
-
function (module, filename) {
|
|
67
|
-
var c = native.load(filename);
|
|
68
|
-
module.exports[c.name().replace(/-/g, '_')] = function (init_properties) {
|
|
69
|
-
let comp = c.create(init_properties);
|
|
70
|
-
let ret = new Component(comp);
|
|
71
|
-
c.properties().forEach((x) => {
|
|
72
|
-
Object.defineProperty(ret, x.replace(/-/g, '_'), {
|
|
73
|
-
get() { return comp.get_property(x); },
|
|
74
|
-
set(newValue) { comp.set_property(x, newValue); },
|
|
75
|
-
enumerable: true,
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
c.callbacks().forEach((x) => {
|
|
79
|
-
Object.defineProperty(ret, x.replace(/-/g, '_'), {
|
|
80
|
-
get() {
|
|
81
|
-
let callback = function () { return comp.invoke_callback(x, [...arguments]); };
|
|
82
|
-
callback.setHandler = function (callback) { comp.connect_callback(x, callback); };
|
|
83
|
-
return callback;
|
|
84
|
-
},
|
|
85
|
-
enumerable: true,
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
return ret;
|
|
89
|
-
};
|
|
90
|
-
};
|
|
91
|
-
/**
|
|
92
|
-
* @hidden
|
|
93
|
-
*/
|
|
94
|
-
class NullPeer {
|
|
95
|
-
rowDataChanged(row) { }
|
|
96
|
-
rowAdded(row, count) { }
|
|
97
|
-
rowRemoved(row, count) { }
|
|
98
|
-
reset() { }
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* ArrayModel wraps a JavaScript array for use in `.slint` views. The underlying
|
|
102
|
-
* array can be modified with the [[ArrayModel.push]] and [[ArrayModel.remove]] methods.
|
|
103
|
-
*/
|
|
104
|
-
class ArrayModel {
|
|
105
|
-
/**
|
|
106
|
-
* Creates a new ArrayModel.
|
|
107
|
-
*
|
|
108
|
-
* @param arr
|
|
109
|
-
*/
|
|
110
|
-
constructor(arr) {
|
|
111
|
-
this.a = arr;
|
|
112
|
-
this.notify = new NullPeer();
|
|
113
|
-
}
|
|
114
|
-
rowCount() {
|
|
115
|
-
return this.a.length;
|
|
116
|
-
}
|
|
117
|
-
rowData(row) {
|
|
118
|
-
return this.a[row];
|
|
119
|
-
}
|
|
120
|
-
setRowData(row, data) {
|
|
121
|
-
this.a[row] = data;
|
|
122
|
-
this.notify.rowDataChanged(row);
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Pushes new values to the array that's backing the model and notifies
|
|
126
|
-
* the run-time about the added rows.
|
|
127
|
-
* @param values
|
|
128
|
-
*/
|
|
129
|
-
push(...values) {
|
|
130
|
-
let size = this.a.length;
|
|
131
|
-
Array.prototype.push.apply(this.a, values);
|
|
132
|
-
this.notify.rowAdded(size, arguments.length);
|
|
133
|
-
}
|
|
134
|
-
// FIXME: should this be named splice and have the splice api?
|
|
135
|
-
/**
|
|
136
|
-
* Removes the specified number of element from the array that's backing
|
|
137
|
-
* the model, starting at the specified index. This is equivalent to calling
|
|
138
|
-
* Array.slice() on the array and notifying the run-time about the removed
|
|
139
|
-
* rows.
|
|
140
|
-
* @param index
|
|
141
|
-
* @param size
|
|
142
|
-
*/
|
|
143
|
-
remove(index, size) {
|
|
144
|
-
let r = this.a.splice(index, size);
|
|
145
|
-
this.notify.rowRemoved(index, size);
|
|
146
|
-
}
|
|
147
|
-
get length() {
|
|
148
|
-
return this.a.length;
|
|
149
|
-
}
|
|
150
|
-
values() {
|
|
151
|
-
return this.a.values();
|
|
152
|
-
}
|
|
153
|
-
entries() {
|
|
154
|
-
return this.a.entries();
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
module.exports = {
|
|
158
|
-
private_api: native,
|
|
159
|
-
ArrayModel: ArrayModel,
|
|
160
|
-
Timer: {
|
|
161
|
-
singleShot: native.singleshot_timer,
|
|
162
|
-
},
|
|
163
|
-
};
|