@effindomv2/fui-rs 0.1.17 → 0.1.19
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/README.md +69 -0
- package/package.json +1 -1
- package/scripts/hostgen/rust-host-events.ts +43 -13
- package/src/app.rs +7 -0
- package/src/assets.rs +2 -2
- package/src/bindings/ui.rs +2 -0
- package/src/bridge_callbacks.rs +27 -17
- package/src/color.rs +112 -0
- package/src/controls/button.rs +1 -0
- package/src/controls/checkbox.rs +1 -0
- package/src/controls/combobox.rs +5 -3
- package/src/controls/dropdown.rs +3 -1
- package/src/controls/internal/pressable_labeled_control.rs +1 -0
- package/src/controls/internal/text_input_core.rs +7 -3
- package/src/controls/radio_button.rs +1 -0
- package/src/controls/shared.rs +2 -5
- package/src/controls/slider.rs +1 -0
- package/src/controls/switch.rs +1 -0
- package/src/controls/tests.rs +36 -7
- package/src/debug.rs +8 -5
- package/src/drag_drop.rs +1 -3
- package/src/drawing.rs +8 -0
- package/src/event.rs +39 -27
- package/src/fetch.rs +21 -7
- package/src/ffi.rs +3 -1
- package/src/file.rs +88 -59
- package/src/host_events.rs +41 -0
- package/src/lib.rs +55 -9
- package/src/node/core.rs +22 -21
- package/src/node/helpers.rs +1 -1
- package/src/node/mod.rs +1 -1
- package/src/node/scroll_bar.rs +101 -0
- package/src/node/scroll_box.rs +7 -0
- package/src/node/scroll_view.rs +20 -14
- package/src/node/virtual_list.rs +120 -33
- package/src/platform.rs +3 -0
- package/src/popup_presenter.rs +1 -0
- package/src/theme.rs +8 -48
- package/src/timers.rs +1 -1
- package/src/typography.rs +6 -14
- package/src/worker.rs +25 -9
- package/src/worker_runtime.rs +61 -17
package/src/worker_runtime.rs
CHANGED
|
@@ -42,7 +42,9 @@ fn with_utf8(value: &str, callback: impl FnOnce(usize, u32)) {
|
|
|
42
42
|
pub struct WorkerRuntime;
|
|
43
43
|
|
|
44
44
|
impl WorkerRuntime {
|
|
45
|
-
|
|
45
|
+
/// # Safety
|
|
46
|
+
/// `input_ptr` must reference at least `input_len` readable bytes when `input_len` is non-zero.
|
|
47
|
+
pub unsafe fn entry_input(input_ptr: usize, input_len: u32) -> String {
|
|
46
48
|
if input_ptr == 0 || input_len == 0 {
|
|
47
49
|
return String::new();
|
|
48
50
|
}
|
|
@@ -56,7 +58,7 @@ impl WorkerRuntime {
|
|
|
56
58
|
return;
|
|
57
59
|
}
|
|
58
60
|
#[cfg(target_arch = "wasm32")]
|
|
59
|
-
|
|
61
|
+
with_utf8(progress.as_ref(), |ptr, len| unsafe {
|
|
60
62
|
host_worker_report_progress(ptr, len);
|
|
61
63
|
});
|
|
62
64
|
#[cfg(not(target_arch = "wasm32"))]
|
|
@@ -69,7 +71,7 @@ impl WorkerRuntime {
|
|
|
69
71
|
}
|
|
70
72
|
WORKER_TERMINAL_SENT.with(|sent| sent.set(true));
|
|
71
73
|
#[cfg(target_arch = "wasm32")]
|
|
72
|
-
|
|
74
|
+
with_utf8(result.as_ref(), |ptr, len| unsafe {
|
|
73
75
|
host_worker_complete_string(ptr, len);
|
|
74
76
|
});
|
|
75
77
|
#[cfg(not(target_arch = "wasm32"))]
|
|
@@ -82,7 +84,7 @@ impl WorkerRuntime {
|
|
|
82
84
|
}
|
|
83
85
|
WORKER_TERMINAL_SENT.with(|sent| sent.set(true));
|
|
84
86
|
#[cfg(target_arch = "wasm32")]
|
|
85
|
-
|
|
87
|
+
with_utf8(message.as_ref(), |ptr, len| unsafe {
|
|
86
88
|
host_worker_fail(ptr, len);
|
|
87
89
|
});
|
|
88
90
|
#[cfg(not(target_arch = "wasm32"))]
|
|
@@ -153,20 +155,62 @@ pub fn worker_text_buffer_size() -> u32 {
|
|
|
153
155
|
WORKER_CALLBACK_BUFFER.with(|buffer| buffer.borrow().len() as u32)
|
|
154
156
|
}
|
|
155
157
|
|
|
156
|
-
pub fn
|
|
157
|
-
|
|
158
|
-
ok: bool,
|
|
159
|
-
status: i32,
|
|
160
|
-
payload_ptr: *const u8,
|
|
161
|
-
payload_len: u32,
|
|
162
|
-
) {
|
|
163
|
-
crate::fetch::__fui_on_fetch_complete(request_id, ok, status, payload_ptr, payload_len);
|
|
158
|
+
pub fn reset_worker_runtime() {
|
|
159
|
+
WORKER_TERMINAL_SENT.with(|sent| sent.set(false));
|
|
164
160
|
}
|
|
165
161
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
162
|
+
#[cfg(test)]
|
|
163
|
+
mod tests {
|
|
164
|
+
use crate::{fui_worker, WorkerJob, WorkerJobState};
|
|
165
|
+
use std::cell::{Cell, RefCell};
|
|
169
166
|
|
|
170
|
-
|
|
171
|
-
|
|
167
|
+
thread_local! {
|
|
168
|
+
static START_INPUT: RefCell<String> = const { RefCell::new(String::new()) };
|
|
169
|
+
static RUN_COUNT: Cell<u32> = const { Cell::new(0) };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
#[derive(Default)]
|
|
173
|
+
struct TestJob {
|
|
174
|
+
state: WorkerJobState,
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
impl WorkerJob for TestJob {
|
|
178
|
+
fn state(&mut self) -> &mut WorkerJobState {
|
|
179
|
+
&mut self.state
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
fn on_start(&mut self, input: String) {
|
|
183
|
+
START_INPUT.with(|value| value.replace(input));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
fn run(&mut self) {
|
|
187
|
+
let run_count = RUN_COUNT.with(|value| {
|
|
188
|
+
let next = value.get() + 1;
|
|
189
|
+
value.set(next);
|
|
190
|
+
next
|
|
191
|
+
});
|
|
192
|
+
if run_count == 2 {
|
|
193
|
+
self.complete("complete");
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
fui_worker!(test_worker_entry => TestJob);
|
|
199
|
+
|
|
200
|
+
#[test]
|
|
201
|
+
fn worker_macro_keeps_job_state_across_resumes_and_exports_shared_buffer() {
|
|
202
|
+
RUN_COUNT.with(|value| value.set(0));
|
|
203
|
+
START_INPUT.with(|value| value.borrow_mut().clear());
|
|
204
|
+
let input = "start";
|
|
205
|
+
|
|
206
|
+
unsafe {
|
|
207
|
+
test_worker_entry(input.as_ptr() as usize, input.len() as u32);
|
|
208
|
+
test_worker_entry(0, 0);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
assert_eq!(START_INPUT.with(|value| value.borrow().clone()), "start");
|
|
212
|
+
assert_eq!(RUN_COUNT.with(Cell::get), 2);
|
|
213
|
+
assert_ne!(__fui_worker_text_buffer(), 0);
|
|
214
|
+
assert!(__fui_worker_text_buffer_size() > 0);
|
|
215
|
+
}
|
|
172
216
|
}
|