@effindomv2/fui-rs 0.1.13 → 0.1.15
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/Cargo.toml +1 -1
- package/package.json +1 -1
- package/src/lib.rs +21 -1
- package/src/node/custom_drawable.rs +48 -76
package/Cargo.toml
CHANGED
package/package.json
CHANGED
package/src/lib.rs
CHANGED
|
@@ -317,13 +317,22 @@ macro_rules! ui {
|
|
|
317
317
|
#[macro_export]
|
|
318
318
|
macro_rules! fui_component {
|
|
319
319
|
($component:ty => $root:ident) => {
|
|
320
|
+
$crate::fui_component!(@impl $component => $root, [root]);
|
|
321
|
+
};
|
|
322
|
+
($component:ty => $root:ident, owner: $owner:ident) => {
|
|
323
|
+
$crate::fui_component!(@impl $component => $root, [owner $owner]);
|
|
324
|
+
};
|
|
325
|
+
($component:ty => $root:ident, owners: [$($owner:ident),+ $(,)?]) => {
|
|
326
|
+
$crate::fui_component!(@impl $component => $root, [owners $($owner),+]);
|
|
327
|
+
};
|
|
328
|
+
(@impl $component:ty => $root:ident, $owner_spec:tt) => {
|
|
320
329
|
impl $crate::Node for $component {
|
|
321
330
|
fn retained_node_ref(&self) -> $crate::node::NodeRef {
|
|
322
331
|
$crate::Node::retained_node_ref(&self.$root)
|
|
323
332
|
}
|
|
324
333
|
|
|
325
334
|
fn retained_owner_attachment(&self) -> Option<std::rc::Rc<dyn std::any::Any>> {
|
|
326
|
-
$crate::
|
|
335
|
+
$crate::fui_component!(@owner_attachment self, $root, $owner_spec)
|
|
327
336
|
}
|
|
328
337
|
|
|
329
338
|
fn build_self(&self) {
|
|
@@ -337,6 +346,16 @@ macro_rules! fui_component {
|
|
|
337
346
|
}
|
|
338
347
|
}
|
|
339
348
|
};
|
|
349
|
+
(@owner_attachment $this:ident, $root:ident, [root]) => {
|
|
350
|
+
$crate::Node::retained_owner_attachment(&$this.$root)
|
|
351
|
+
};
|
|
352
|
+
(@owner_attachment $this:ident, $root:ident, [owner $owner:ident]) => {{
|
|
353
|
+
let owner: std::rc::Rc<dyn std::any::Any> = $this.$owner.clone();
|
|
354
|
+
Some(owner)
|
|
355
|
+
}};
|
|
356
|
+
(@owner_attachment $this:ident, $root:ident, [owners $($owner:ident),+]) => {
|
|
357
|
+
Some(std::rc::Rc::new(($($this.$owner.clone(),)+)))
|
|
358
|
+
};
|
|
340
359
|
}
|
|
341
360
|
|
|
342
361
|
pub mod prelude {
|
|
@@ -414,6 +433,7 @@ pub mod prelude {
|
|
|
414
433
|
FileWorkerProcessResult, FileWriteProgress,
|
|
415
434
|
};
|
|
416
435
|
pub use crate::focus_visibility::show_keyboard_focus_for_key_event;
|
|
436
|
+
pub use crate::frame_scheduler::{mark_needs_commit, on_loaded, LoadedEventArgs};
|
|
417
437
|
pub use crate::fui_component;
|
|
418
438
|
pub use crate::image_sampling::{ImageSampling, ImageSamplingMode};
|
|
419
439
|
pub use crate::logger;
|
|
@@ -17,82 +17,6 @@ impl CustomDrawable {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
pub fn width(&self, width: f32, unit: Unit) -> &Self {
|
|
21
|
-
self.base.width(width, unit);
|
|
22
|
-
self
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
pub fn width_len(&self, length: Length) -> &Self {
|
|
26
|
-
self.base.width_len(length);
|
|
27
|
-
self
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
pub fn height(&self, height: f32, unit: Unit) -> &Self {
|
|
31
|
-
self.base.height(height, unit);
|
|
32
|
-
self
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
pub fn height_len(&self, length: Length) -> &Self {
|
|
36
|
-
self.base.height_len(length);
|
|
37
|
-
self
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
pub fn bg_color(&self, color: u32) -> &Self {
|
|
41
|
-
self.base.bg_color(color);
|
|
42
|
-
self
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
pub fn corner_radius(&self, radius: f32) -> &Self {
|
|
46
|
-
self.base.corner_radius(radius);
|
|
47
|
-
self
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
pub fn border(&self, width: f32, color: u32) -> &Self {
|
|
51
|
-
self.base.border(width, color);
|
|
52
|
-
self
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
pub fn border_config(&self, border: Border) -> &Self {
|
|
56
|
-
self.base.border_config(border);
|
|
57
|
-
self
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
pub fn opacity(&self, value: f32) -> &Self {
|
|
61
|
-
self.base.opacity(value);
|
|
62
|
-
self
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
pub fn drop_shadow(
|
|
66
|
-
&self,
|
|
67
|
-
color: u32,
|
|
68
|
-
offset_x: f32,
|
|
69
|
-
offset_y: f32,
|
|
70
|
-
blur_sigma: f32,
|
|
71
|
-
spread: f32,
|
|
72
|
-
) -> &Self {
|
|
73
|
-
self.base
|
|
74
|
-
.drop_shadow(color, offset_x, offset_y, blur_sigma, spread);
|
|
75
|
-
self
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
pub fn linear_gradient(
|
|
79
|
-
&self,
|
|
80
|
-
sx: f32,
|
|
81
|
-
sy: f32,
|
|
82
|
-
ex: f32,
|
|
83
|
-
ey: f32,
|
|
84
|
-
offsets: Vec<f32>,
|
|
85
|
-
colors: Vec<u32>,
|
|
86
|
-
) -> &Self {
|
|
87
|
-
self.base.linear_gradient(sx, sy, ex, ey, offsets, colors);
|
|
88
|
-
self
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
pub fn child<T: Node>(&self, child: &T) -> &Self {
|
|
92
|
-
self.base.child(child);
|
|
93
|
-
self
|
|
94
|
-
}
|
|
95
|
-
|
|
96
20
|
pub fn mark_dirty(&self) {
|
|
97
21
|
let handle = self.handle();
|
|
98
22
|
if handle != NodeHandle::INVALID {
|
|
@@ -147,3 +71,51 @@ impl Node for CustomDrawable {
|
|
|
147
71
|
}));
|
|
148
72
|
}
|
|
149
73
|
}
|
|
74
|
+
|
|
75
|
+
impl HasFlexBoxRoot for CustomDrawable {
|
|
76
|
+
fn flex_box_root(&self) -> &FlexBox {
|
|
77
|
+
&self.base
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
impl ThemeBindable for CustomDrawable {
|
|
82
|
+
fn theme_binding_node(&self) -> NodeRef {
|
|
83
|
+
self.base.retained_node_ref()
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
fn weak_theme_target(&self) -> Box<dyn Fn() -> Option<Self>> {
|
|
87
|
+
let weak_base = self.base.downgrade();
|
|
88
|
+
let draw_callback = self.draw_callback.clone();
|
|
89
|
+
Box::new(move || {
|
|
90
|
+
weak_base.upgrade().map(|base| Self {
|
|
91
|
+
base,
|
|
92
|
+
draw_callback: draw_callback.clone(),
|
|
93
|
+
})
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
#[cfg(test)]
|
|
99
|
+
mod tests {
|
|
100
|
+
use super::*;
|
|
101
|
+
|
|
102
|
+
fn assert_flex_box_surface<T: FlexBoxSurface>() {}
|
|
103
|
+
fn assert_theme_bindable<T: ThemeBindable>() {}
|
|
104
|
+
|
|
105
|
+
#[test]
|
|
106
|
+
fn custom_drawable_exposes_generic_retained_visual_surfaces() {
|
|
107
|
+
assert_flex_box_surface::<CustomDrawable>();
|
|
108
|
+
assert_theme_bindable::<CustomDrawable>();
|
|
109
|
+
|
|
110
|
+
let drawable = CustomDrawable::new(|_| {});
|
|
111
|
+
drawable
|
|
112
|
+
.width(300.0, Unit::Pixel)
|
|
113
|
+
.height(200.0, Unit::Pixel)
|
|
114
|
+
.min_width(120.0, Unit::Pixel)
|
|
115
|
+
.margin(1.0, 2.0, 3.0, 4.0)
|
|
116
|
+
.padding(5.0, 6.0, 7.0, 8.0)
|
|
117
|
+
.corner_radius(12.0)
|
|
118
|
+
.bg_color(0x112233FF)
|
|
119
|
+
.clip_to_bounds(true);
|
|
120
|
+
}
|
|
121
|
+
}
|