working extension system

This commit is contained in:
2025-06-29 11:49:11 -05:00
parent af719d83db
commit 85bfa0f45f
5 changed files with 115 additions and 7 deletions
+44
View File
@@ -0,0 +1,44 @@
use std::sync::Arc;
use crate::{
component,
extensions::Extension,
style::{Position, Transform},
widget::Widget,
};
pub struct VelocityExtension;
impl Extension for VelocityExtension {
fn render(&self, _widget: &Arc<Widget>) {
if let Some(velocity) = _widget.get::<Velocity>() {
if let Some(mut t) = _widget.get::<Transform>() {
match &mut t.x {
Position::Const(x) => {
if velocity.0 > 0 {
*x += 1;
} else if velocity.0 < 0 {
*x -= 1;
}
}
_ => {}
}
match &mut t.y {
Position::Const(y) => {
if velocity.1 > 0 {
*y += 1;
} else if velocity.1 < 0 {
*y -= 1;
}
}
_ => {}
}
_widget.set_component(t);
}
}
}
}
component!(Velocity(pub i32, pub i32));