slint-ui 0.2.5 → 0.3.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/dist/index.d.ts +7 -0
- package/dist/index.js +6 -0
- package/lib/index.ts +59 -3
- package/native/Cargo.toml +4 -4
- package/native/lib.rs +126 -14
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -23,10 +23,15 @@ interface Point {
|
|
|
23
23
|
x: Number;
|
|
24
24
|
y: Number;
|
|
25
25
|
}
|
|
26
|
+
interface Size {
|
|
27
|
+
width: Number;
|
|
28
|
+
height: Number;
|
|
29
|
+
}
|
|
26
30
|
interface SlintWindow {
|
|
27
31
|
show(): void;
|
|
28
32
|
hide(): void;
|
|
29
33
|
position: Point;
|
|
34
|
+
size: Size;
|
|
30
35
|
}
|
|
31
36
|
/**
|
|
32
37
|
* @hidden
|
|
@@ -38,6 +43,8 @@ declare class WindowAPI implements SlintWindow {
|
|
|
38
43
|
hide(): void;
|
|
39
44
|
get position(): Point;
|
|
40
45
|
set position(pos: Point);
|
|
46
|
+
get size(): Size;
|
|
47
|
+
set size(size: Size);
|
|
41
48
|
}
|
|
42
49
|
/**
|
|
43
50
|
* @hidden
|
package/dist/index.js
CHANGED
|
@@ -61,6 +61,12 @@ class WindowAPI {
|
|
|
61
61
|
set position(pos) {
|
|
62
62
|
this.impl.set_position(pos);
|
|
63
63
|
}
|
|
64
|
+
get size() {
|
|
65
|
+
return this.impl.get_size();
|
|
66
|
+
}
|
|
67
|
+
set size(size) {
|
|
68
|
+
this.impl.set_size(size);
|
|
69
|
+
}
|
|
64
70
|
}
|
|
65
71
|
require.extensions['.60'] = require.extensions['.slint'] =
|
|
66
72
|
function (module, filename) {
|
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.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.
|
|
24
|
-
i-slint-core = { version = "=0.
|
|
25
|
-
slint-interpreter = { version = "=0.
|
|
23
|
+
i-slint-compiler = { version = "=0.3.0"}
|
|
24
|
+
i-slint-core = { version = "=0.3.0"}
|
|
25
|
+
slint-interpreter = { version = "=0.3.0", 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> =
|
|
@@ -254,12 +254,10 @@ fn to_js_value<'cx>(
|
|
|
254
254
|
Value::Bool(b) => JsBoolean::new(cx, b).as_value(cx),
|
|
255
255
|
Value::Image(r) => match (&r).into() {
|
|
256
256
|
&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?
|
|
257
|
+
&ImageInner::EmbeddedImage { .. }
|
|
258
|
+
| &ImageInner::StaticTextures { .. }
|
|
259
|
+
| &ImageInner::Svg(..)
|
|
260
|
+
| &ImageInner::BackendStorage(..) => JsNull::new().as_value(cx), // TODO: maybe pass around node buffers?
|
|
263
261
|
},
|
|
264
262
|
Value::Model(model) => {
|
|
265
263
|
if let Some(js_model) = model.as_any().downcast_ref::<js_model::JsModel>() {
|
|
@@ -354,9 +352,9 @@ declare_types! {
|
|
|
354
352
|
let this = cx.this();
|
|
355
353
|
let component = cx.borrow(&this, |x| x.0.as_ref().map(|c| c.clone_strong()));
|
|
356
354
|
let component = component.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
|
357
|
-
let
|
|
355
|
+
let window_adapter = WindowInner::from_pub(component.window()).window_adapter();
|
|
358
356
|
let mut obj = SlintWindow::new::<_, JsValue, _>(&mut cx, std::iter::empty())?;
|
|
359
|
-
cx.borrow_mut(&mut obj, |mut obj| obj.0 = Some(
|
|
357
|
+
cx.borrow_mut(&mut obj, |mut obj| obj.0 = Some(window_adapter));
|
|
360
358
|
Ok(obj.as_value(&mut cx))
|
|
361
359
|
}
|
|
362
360
|
method get_property(mut cx) {
|
|
@@ -493,16 +491,130 @@ declare_types! {
|
|
|
493
491
|
method show(mut cx) {
|
|
494
492
|
let this = cx.this();
|
|
495
493
|
let window = cx.borrow(&this, |x| x.0.as_ref().cloned());
|
|
496
|
-
let
|
|
497
|
-
|
|
494
|
+
let window_adapter = window.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
|
495
|
+
window_adapter.show();
|
|
498
496
|
Ok(JsUndefined::new().as_value(&mut cx))
|
|
499
497
|
}
|
|
500
498
|
|
|
501
499
|
method hide(mut cx) {
|
|
502
500
|
let this = cx.this();
|
|
503
501
|
let window = cx.borrow(&this, |x| x.0.as_ref().cloned());
|
|
504
|
-
let
|
|
505
|
-
|
|
502
|
+
let window_adapter = window.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
|
503
|
+
window_adapter.hide();
|
|
504
|
+
Ok(JsUndefined::new().as_value(&mut cx))
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
method get_logical_position(mut cx) {
|
|
508
|
+
let this = cx.this();
|
|
509
|
+
let window = cx.borrow(&this, |x| x.0.as_ref().cloned());
|
|
510
|
+
let window_adapter = window.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
|
511
|
+
let pos = window_adapter.position().to_logical(window_adapter.window().scale_factor());
|
|
512
|
+
|
|
513
|
+
let point_object = JsObject::new(&mut cx);
|
|
514
|
+
let x_value = JsNumber::new(&mut cx, pos.x).as_value(&mut cx);
|
|
515
|
+
point_object.set(&mut cx, "x", x_value)?;
|
|
516
|
+
let y_value = JsNumber::new(&mut cx, pos.y).as_value(&mut cx);
|
|
517
|
+
point_object.set(&mut cx, "y", y_value)?;
|
|
518
|
+
Ok(point_object.as_value(&mut cx))
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
method get_physical_position(mut cx) {
|
|
522
|
+
let this = cx.this();
|
|
523
|
+
let window = cx.borrow(&this, |x| x.0.as_ref().cloned());
|
|
524
|
+
let window_adapter = window.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
|
525
|
+
let pos = window_adapter.position();
|
|
526
|
+
|
|
527
|
+
let point_object = JsObject::new(&mut cx);
|
|
528
|
+
let x_value = JsNumber::new(&mut cx, pos.x).as_value(&mut cx);
|
|
529
|
+
point_object.set(&mut cx, "x", x_value)?;
|
|
530
|
+
let y_value = JsNumber::new(&mut cx, pos.y).as_value(&mut cx);
|
|
531
|
+
point_object.set(&mut cx, "y", y_value)?;
|
|
532
|
+
Ok(point_object.as_value(&mut cx))
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
method set_logical_position(mut cx) {
|
|
536
|
+
let this = cx.this();
|
|
537
|
+
let window = cx.borrow(&this, |x| x.0.as_ref().cloned());
|
|
538
|
+
let window_adapter = window.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
|
539
|
+
|
|
540
|
+
let point_object = cx.argument::<JsObject>(0)?;
|
|
541
|
+
let x = point_object.get(&mut cx, "x")?.downcast_or_throw::<JsNumber, _>(&mut cx)?.value();
|
|
542
|
+
let y = point_object.get(&mut cx, "y")?.downcast_or_throw::<JsNumber, _>(&mut cx)?.value();
|
|
543
|
+
|
|
544
|
+
window_adapter.set_position(i_slint_core::api::LogicalPosition::new(x as f32, y as f32).into());
|
|
545
|
+
|
|
546
|
+
Ok(JsUndefined::new().as_value(&mut cx))
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
method set_physical_position(mut cx) {
|
|
550
|
+
let this = cx.this();
|
|
551
|
+
let window = cx.borrow(&this, |x| x.0.as_ref().cloned());
|
|
552
|
+
let window_adapter = window.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
|
553
|
+
|
|
554
|
+
let point_object = cx.argument::<JsObject>(0)?;
|
|
555
|
+
let x = point_object.get(&mut cx, "x")?.downcast_or_throw::<JsNumber, _>(&mut cx)?.value();
|
|
556
|
+
let y = point_object.get(&mut cx, "y")?.downcast_or_throw::<JsNumber, _>(&mut cx)?.value();
|
|
557
|
+
|
|
558
|
+
window_adapter.set_position(i_slint_core::api::PhysicalPosition::new(x as i32, y as i32).into());
|
|
559
|
+
|
|
560
|
+
Ok(JsUndefined::new().as_value(&mut cx))
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
method get_logical_size(mut cx) {
|
|
564
|
+
let this = cx.this();
|
|
565
|
+
let window_adapter = cx.borrow(&this, |x| x.0.as_ref().cloned());
|
|
566
|
+
let window_adapter = window_adapter.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
|
567
|
+
let size = window_adapter.window().size().to_logical(window_adapter.window().scale_factor());
|
|
568
|
+
|
|
569
|
+
let size_object = JsObject::new(&mut cx);
|
|
570
|
+
let width_value = JsNumber::new(&mut cx, size.width).as_value(&mut cx);
|
|
571
|
+
size_object.set(&mut cx, "width", width_value)?;
|
|
572
|
+
let height_value = JsNumber::new(&mut cx, size.height).as_value(&mut cx);
|
|
573
|
+
size_object.set(&mut cx, "height", height_value)?;
|
|
574
|
+
Ok(size_object.as_value(&mut cx))
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
method get_physical_size(mut cx) {
|
|
578
|
+
let this = cx.this();
|
|
579
|
+
let window_adapter = cx.borrow(&this, |x| x.0.as_ref().cloned());
|
|
580
|
+
let window_adapter = window_adapter.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
|
581
|
+
let size = window_adapter.window().size();
|
|
582
|
+
|
|
583
|
+
let size_object = JsObject::new(&mut cx);
|
|
584
|
+
let width_value = JsNumber::new(&mut cx, size.width).as_value(&mut cx);
|
|
585
|
+
size_object.set(&mut cx, "width", width_value)?;
|
|
586
|
+
let height_value = JsNumber::new(&mut cx, size.height).as_value(&mut cx);
|
|
587
|
+
size_object.set(&mut cx, "height", height_value)?;
|
|
588
|
+
Ok(size_object.as_value(&mut cx))
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
method set_logical_size(mut cx) {
|
|
592
|
+
let this = cx.this();
|
|
593
|
+
let window_adapter = cx.borrow(&this, |x| x.0.as_ref().cloned());
|
|
594
|
+
let window_adapter = window_adapter.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
|
595
|
+
let window = window_adapter.window();
|
|
596
|
+
|
|
597
|
+
let size_object = cx.argument::<JsObject>(0)?;
|
|
598
|
+
let width = size_object.get(&mut cx, "width")?.downcast_or_throw::<JsNumber, _>(&mut cx)?.value();
|
|
599
|
+
let height = size_object.get(&mut cx, "height")?.downcast_or_throw::<JsNumber, _>(&mut cx)?.value();
|
|
600
|
+
|
|
601
|
+
window.set_size(i_slint_core::api::LogicalSize::new(width as f32, height as f32));
|
|
602
|
+
|
|
603
|
+
Ok(JsUndefined::new().as_value(&mut cx))
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
method set_physical_size(mut cx) {
|
|
607
|
+
let this = cx.this();
|
|
608
|
+
let window_adapter = cx.borrow(&this, |x| x.0.as_ref().cloned());
|
|
609
|
+
let window_adapter = window_adapter.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
|
610
|
+
let window = window_adapter.window();
|
|
611
|
+
|
|
612
|
+
let size_object = cx.argument::<JsObject>(0)?;
|
|
613
|
+
let width = size_object.get(&mut cx, "width")?.downcast_or_throw::<JsNumber, _>(&mut cx)?.value();
|
|
614
|
+
let height = size_object.get(&mut cx, "height")?.downcast_or_throw::<JsNumber, _>(&mut cx)?.value();
|
|
615
|
+
|
|
616
|
+
window.set_size(i_slint_core::api::PhysicalSize::new(width as u32, height as u32));
|
|
617
|
+
|
|
506
618
|
Ok(JsUndefined::new().as_value(&mut cx))
|
|
507
619
|
}
|
|
508
620
|
}
|