feat(ui-dioxus): use dioxus-motion for Blitz-compatible pulse animation
This commit is contained in:
parent
c9f8679744
commit
67ab77ebf4
3 changed files with 3861 additions and 1240 deletions
5046
ui-dioxus/Cargo.lock
generated
5046
ui-dioxus/Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -15,4 +15,5 @@ serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
uuid = { version = "1", features = ["v4"] }
|
uuid = { version = "1", features = ["v4"] }
|
||||||
tokio = { version = "1", features = ["full"] }
|
tokio = { version = "1", features = ["full"] }
|
||||||
|
dioxus-motion = { version = "0.3", default-features = false, features = ["desktop"] }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,10 @@
|
||||||
/// PulsingDot — GPU-friendly animated status indicator for Blitz renderer.
|
/// PulsingDot — Blitz-compatible animated status indicator using dioxus-motion.
|
||||||
///
|
///
|
||||||
/// Pure OS-thread animation — no async runtime dependency.
|
/// Uses dioxus-motion's Tween with LoopMode::Alternate for infinite ping-pong.
|
||||||
/// OS thread updates AtomicU32 + calls schedule_update() to trigger re-render.
|
/// Avoids CSS @keyframes entirely — no Blitz full-scene repaint loop.
|
||||||
/// schedule_update() returns Arc<dyn Fn() + Send + Sync> — safe from any thread.
|
|
||||||
|
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
use std::sync::atomic::{AtomicU32, Ordering};
|
use dioxus_motion::prelude::*;
|
||||||
use std::sync::Arc;
|
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone, PartialEq)]
|
||||||
pub enum DotState {
|
pub enum DotState {
|
||||||
|
|
@ -21,35 +18,18 @@ pub enum DotState {
|
||||||
#[component]
|
#[component]
|
||||||
pub fn PulsingDot(state: DotState, size: Option<String>) -> Element {
|
pub fn PulsingDot(state: DotState, size: Option<String>) -> Element {
|
||||||
let should_pulse = matches!(state, DotState::Running | DotState::Stalled);
|
let should_pulse = matches!(state, DotState::Running | DotState::Stalled);
|
||||||
|
let mut opacity = use_motion(1.0f32);
|
||||||
|
|
||||||
// Shared atomic for cross-thread opacity (f32 as u32 bits)
|
// Infinite ping-pong tween: 1.0 → 0.4 → 1.0 → ...
|
||||||
let atomic_opacity = use_hook(|| Arc::new(AtomicU32::new(f32::to_bits(1.0))));
|
|
||||||
|
|
||||||
if should_pulse {
|
if should_pulse {
|
||||||
let ao = atomic_opacity.clone();
|
use_effect(move || {
|
||||||
// schedule_update returns Arc<dyn Fn() + Send + Sync> — works from OS threads
|
opacity.animate_to(
|
||||||
let updater = use_hook(|| dioxus::dioxus_core::schedule_update());
|
0.4,
|
||||||
|
AnimationConfig::new(AnimationMode::Tween(
|
||||||
use_hook(move || {
|
Tween::new(Duration::from_millis(1000))
|
||||||
std::thread::spawn(move || {
|
))
|
||||||
let steps = 8u32;
|
.with_loop(LoopMode::Alternate),
|
||||||
let step_ms = 125u64;
|
);
|
||||||
let mut going_down = true;
|
|
||||||
loop {
|
|
||||||
for i in 0..steps {
|
|
||||||
let t = i as f32 / (steps - 1) as f32;
|
|
||||||
let val = if going_down {
|
|
||||||
1.0 - (t * 0.6)
|
|
||||||
} else {
|
|
||||||
0.4 + (t * 0.6)
|
|
||||||
};
|
|
||||||
ao.store(f32::to_bits(val), Ordering::Relaxed);
|
|
||||||
updater(); // Trigger re-render from OS thread
|
|
||||||
std::thread::sleep(Duration::from_millis(step_ms));
|
|
||||||
}
|
|
||||||
going_down = !going_down;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -62,11 +42,7 @@ pub fn PulsingDot(state: DotState, size: Option<String>) -> Element {
|
||||||
};
|
};
|
||||||
|
|
||||||
let sz = size.unwrap_or_else(|| "8px".to_string());
|
let sz = size.unwrap_or_else(|| "8px".to_string());
|
||||||
let op = if should_pulse {
|
let op = if should_pulse { opacity.get_value() } else { 1.0 };
|
||||||
f32::from_bits(atomic_opacity.load(Ordering::Relaxed))
|
|
||||||
} else {
|
|
||||||
1.0
|
|
||||||
};
|
|
||||||
|
|
||||||
rsx! {
|
rsx! {
|
||||||
span {
|
span {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue