@effindomv2/fui-rs 0.1.15 → 0.1.16

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "fui-rs"
3
- version = "0.1.15"
3
+ version = "0.1.16"
4
4
  edition = "2021"
5
5
  license = "AGPL-3.0-only OR LicenseRef-EffinDom-Commercial"
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effindomv2/fui-rs",
3
- "version": "0.1.15",
3
+ "version": "0.1.16",
4
4
  "private": false,
5
5
  "license": "AGPL-3.0-only OR LicenseRef-EffinDom-Commercial",
6
6
  "description": "EffinDom v2 Rust frontend framework SDK and host generators",
package/src/drawing.rs CHANGED
@@ -63,36 +63,45 @@ impl Paint {
63
63
  }
64
64
  }
65
65
 
66
- pub struct Path {
66
+ struct PathResource {
67
67
  id: u32,
68
- disposed: bool,
68
+ }
69
+
70
+ impl Drop for PathResource {
71
+ fn drop(&mut self) {
72
+ unsafe { ffi::fui_path_destroy(self.id) };
73
+ }
74
+ }
75
+
76
+ #[derive(Clone)]
77
+ pub struct Path {
78
+ resource: Rc<PathResource>,
69
79
  }
70
80
 
71
81
  impl Path {
72
82
  pub fn new() -> Self {
73
83
  let id = unsafe { ffi::fui_path_create() };
74
84
  Self {
75
- id,
76
- disposed: false,
85
+ resource: Rc::new(PathResource { id }),
77
86
  }
78
87
  }
79
88
 
80
89
  pub fn id(&self) -> u32 {
81
- self.id
90
+ self.resource.id
82
91
  }
83
92
 
84
93
  pub fn move_to(&mut self, x: f32, y: f32) -> &mut Self {
85
- unsafe { ffi::fui_path_move_to(self.id, x, y) };
94
+ unsafe { ffi::fui_path_move_to(self.id(), x, y) };
86
95
  self
87
96
  }
88
97
 
89
98
  pub fn line_to(&mut self, x: f32, y: f32) -> &mut Self {
90
- unsafe { ffi::fui_path_line_to(self.id, x, y) };
99
+ unsafe { ffi::fui_path_line_to(self.id(), x, y) };
91
100
  self
92
101
  }
93
102
 
94
103
  pub fn quad_to(&mut self, cx: f32, cy: f32, x: f32, y: f32) -> &mut Self {
95
- unsafe { ffi::fui_path_quad_to(self.id, cx, cy, x, y) };
104
+ unsafe { ffi::fui_path_quad_to(self.id(), cx, cy, x, y) };
96
105
  self
97
106
  }
98
107
 
@@ -105,39 +114,31 @@ impl Path {
105
114
  x: f32,
106
115
  y: f32,
107
116
  ) -> &mut Self {
108
- unsafe { ffi::fui_path_cubic_to(self.id, cx1, cy1, cx2, cy2, x, y) };
117
+ unsafe { ffi::fui_path_cubic_to(self.id(), cx1, cy1, cx2, cy2, x, y) };
109
118
  self
110
119
  }
111
120
 
112
121
  pub fn close(&mut self) -> &mut Self {
113
- unsafe { ffi::fui_path_close(self.id) };
122
+ unsafe { ffi::fui_path_close(self.id()) };
114
123
  self
115
124
  }
116
125
 
117
126
  pub fn add_rect(&mut self, x: f32, y: f32, w: f32, h: f32) -> &mut Self {
118
- unsafe { ffi::fui_path_add_rect(self.id, x, y, w, h) };
127
+ unsafe { ffi::fui_path_add_rect(self.id(), x, y, w, h) };
119
128
  self
120
129
  }
121
130
 
122
131
  pub fn add_circle(&mut self, cx: f32, cy: f32, r: f32) -> &mut Self {
123
- unsafe { ffi::fui_path_add_circle(self.id, cx, cy, r) };
132
+ unsafe { ffi::fui_path_add_circle(self.id(), cx, cy, r) };
124
133
  self
125
134
  }
126
135
  }
127
136
 
128
- impl Drop for Path {
129
- fn drop(&mut self) {
130
- if !self.disposed {
131
- unsafe { ffi::fui_path_destroy(self.id) };
132
- self.disposed = true;
133
- }
134
- }
135
- }
136
-
137
137
  #[derive(Default)]
138
138
  struct DrawContextState {
139
139
  canvas_ptr: usize,
140
140
  words: Vec<u32>,
141
+ retained_paths: Vec<Path>,
141
142
  }
142
143
 
143
144
  #[derive(Clone, Default)]
@@ -151,6 +152,7 @@ impl DrawContext {
151
152
  inner: Rc::new(RefCell::new(DrawContextState {
152
153
  canvas_ptr,
153
154
  words: Vec::new(),
155
+ retained_paths: Vec::new(),
154
156
  })),
155
157
  }
156
158
  }
@@ -172,6 +174,7 @@ impl DrawContext {
172
174
  )
173
175
  };
174
176
  state.words.clear();
177
+ state.retained_paths.clear();
175
178
  }
176
179
 
177
180
  pub fn save(&self) {
@@ -289,6 +292,7 @@ impl DrawContext {
289
292
  state.words.push(paint.fill_color);
290
293
  state.words.push(paint.stroke_color);
291
294
  Self::push_float(&mut state.words, paint.stroke_width);
295
+ state.retained_paths.push(path.clone());
292
296
  }
293
297
 
294
298
  pub fn draw_text_node<T: Node>(&self, node: &T, x: f32, y: f32) {
package/src/lib.rs CHANGED
@@ -441,8 +441,8 @@ pub mod prelude {
441
441
  pub use crate::node::{
442
442
  auto, column, custom_drawable, fill, flex_box, grid, image, pct, portal, px, row,
443
443
  scroll_box, scroll_view, svg, text, viewport_height, viewport_width, virtual_list, Border,
444
- Child, ContextMenuEventArgs, Corners, CustomDrawable, EdgeInsets, FlexBox, FlexBoxSurface,
445
- GradientStop, Grid, GridTrack, HasFlexBoxRoot, Image, ImageNode, Length, Node,
444
+ Child, ContextMenuEventArgs, Corners, CustomDrawable, DrawableInvalidator, EdgeInsets,
445
+ FlexBox, FlexBoxSurface, GradientStop, Grid, GridTrack, HasFlexBoxRoot, Image, ImageNode, Length, Node,
446
446
  PresenterHostStyle, ScrollBar, ScrollBarVisibility, ScrollBox, ScrollState, ScrollView,
447
447
  Shadow, Svg, SvgNode, Text, TextCore, TextNode, ThemeBindable, VirtualList,
448
448
  };
@@ -559,8 +559,8 @@ pub use navigation::*;
559
559
  pub use node::{
560
560
  auto, column, custom_drawable, fill, flex_box, grid, image, pct, portal, px, row, scroll_box,
561
561
  scroll_view, svg, text, viewport_height, viewport_width, virtual_list, Border, Child,
562
- ContextMenuEventArgs, Corners, CustomDrawable, EdgeInsets, FlexBox, FlexBoxSurface,
563
- GradientStop, Grid, GridTrack, HasFlexBoxRoot, Image, ImageNode, Length, Node,
562
+ ContextMenuEventArgs, Corners, CustomDrawable, DrawableInvalidator, EdgeInsets, FlexBox,
563
+ FlexBoxSurface, GradientStop, Grid, GridTrack, HasFlexBoxRoot, Image, ImageNode, Length, Node,
564
564
  PresenterHostStyle, ScrollBar, ScrollBarVisibility, ScrollBox, ScrollState, ScrollView, Shadow,
565
565
  Svg, SvgNode, Text, TextCore, TextNode, ThemeBindable, VirtualList,
566
566
  };
@@ -7,6 +7,19 @@ pub struct CustomDrawable {
7
7
  draw_callback: DrawCallback,
8
8
  }
9
9
 
10
+ #[derive(Clone)]
11
+ pub struct DrawableInvalidator {
12
+ base: WeakFlexBox,
13
+ }
14
+
15
+ impl DrawableInvalidator {
16
+ pub fn mark_dirty(&self) {
17
+ if let Some(base) = self.base.upgrade() {
18
+ mark_base_dirty(&base);
19
+ }
20
+ }
21
+ }
22
+
10
23
  impl CustomDrawable {
11
24
  pub fn new(handler: impl Fn(&mut DrawContext) + 'static) -> Self {
12
25
  let base = FlexBox::default();
@@ -18,19 +31,29 @@ impl CustomDrawable {
18
31
  }
19
32
 
20
33
  pub fn mark_dirty(&self) {
21
- let handle = self.handle();
22
- if handle != NodeHandle::INVALID {
23
- let Some(bounds) = ui::get_visible_bounds(handle.raw()) else {
24
- return;
25
- };
26
- if bounds[2] <= 0.0 || bounds[3] <= 0.0 {
27
- return;
28
- }
34
+ mark_base_dirty(&self.base);
35
+ }
36
+
37
+ pub fn invalidator(&self) -> DrawableInvalidator {
38
+ DrawableInvalidator {
39
+ base: self.base.downgrade(),
29
40
  }
30
- crate::frame_scheduler::mark_needs_commit();
31
41
  }
32
42
  }
33
43
 
44
+ fn mark_base_dirty(base: &FlexBox) {
45
+ let handle = base.handle();
46
+ if handle != NodeHandle::INVALID {
47
+ let Some(bounds) = ui::get_visible_bounds(handle.raw()) else {
48
+ return;
49
+ };
50
+ if bounds[2] <= 0.0 || bounds[3] <= 0.0 {
51
+ return;
52
+ }
53
+ }
54
+ crate::frame_scheduler::mark_needs_commit();
55
+ }
56
+
34
57
  impl Node for CustomDrawable {
35
58
  fn retained_node_ref(&self) -> NodeRef {
36
59
  NodeRef::from_node(self.base.core.clone(), self.clone())
@@ -117,5 +140,9 @@ mod tests {
117
140
  .corner_radius(12.0)
118
141
  .bg_color(0x112233FF)
119
142
  .clip_to_bounds(true);
143
+
144
+ let invalidator = drawable.invalidator();
145
+ drop(drawable);
146
+ invalidator.mark_dirty();
120
147
  }
121
148
  }
package/src/node/mod.rs CHANGED
@@ -37,7 +37,7 @@ mod virtual_list;
37
37
  pub use core::NodeRef;
38
38
  pub use core::{ContextMenuEventArgs, Node, NodeHandle};
39
39
  pub(crate) use core::{WeakFlexBox, WeakNodeRef};
40
- pub use custom_drawable::CustomDrawable;
40
+ pub use custom_drawable::{CustomDrawable, DrawableInvalidator};
41
41
  pub use flex_box::{Border, FlexBox, GradientStop};
42
42
  pub use grid::{Grid, GridTrack};
43
43
  pub(crate) use helpers::*;