Skip to content

Commit

Permalink
fixed mouse-animation, particles, slot-particles
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelselleck authored and zackbrown committed Sep 12, 2024
1 parent 4e1b030 commit 2c19fc8
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 68 deletions.
43 changes: 20 additions & 23 deletions examples/src/mouse-animation/src/lib.pax
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
<Text x=50% y=50% text="Move mouse up & down" id=text/>
<Group anchor_x=50% anchor_y=50% x=50% y=50% width=200% rotate=20deg>
for i in 0..12 {
<PathAnimation rotate={(i*40)deg}
x=50%
y=50%
path_config={
amplitude: {0.03 + 0.1 * i*(i-12.0)/10.0},
amplitude_ramp: {0.2 + i*0.01},
frequency: 2.0,
frequency_ramp: {0.1*i},
thickness: {0.07 - 0.01*i/5.0},
thickness_ramp: {0.02 - i/5.0*0.01},
span: {0.1 + 0.1*i/10.0},
}
t={2.0*self.scroll - i/20.0}
fill={hsla(40.0*i, 150, 160 + 5*i, 100)}
/>
}
for i in 0..12 {
<PathAnimation rotate={(i * 40)deg} x=50% y=50% path_config={
amplitude: {0.03 + 0.10 * i * (i - 12.00) / 10.00}
amplitude_ramp: {0.20 + i * 0.01}
frequency: 2.00
frequency_ramp: {0.10 * i}
thickness: {0.07 - 0.01 * i / 5.00}
thickness_ramp: {0.02 - i / 5.00 * 0.01}
span: {0.10 + 0.10 * i / 10.00}
}
t={2.00 * scroll - i / 20.00} fill={hsla(40.00 * i, 150, 160 + 5 * i, 100)}/>
}
</Group>
<Rectangle fill=TRANSPARENT/>

@settings {
@mouse_move: on_mouse_move
@mount: on_mount,
@mouse_move: on_mouse_move
#text {
style: TextStyle {
font: Font::Web("Esenka", "", FontStyle::Normal, FontWeight::Normal),
font_size: 40px,
fill: BLACK,
align_vertical: TextAlignVertical::Center,
align_horizontal: TextAlignHorizontal::Center,
font: Font::Web("Esenka", "", FontStyle::Normal, FontWeight::Normal)
font_size: 40px
fill: BLACK
align_vertical: TextAlignVertical::Center
align_horizontal: TextAlignHorizontal::Center
}
}
}
1 change: 1 addition & 0 deletions examples/src/mouse-animation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct Example {
}

impl Example {
pub fn on_mount(&mut self, ctx: &NodeContext) {}
pub fn on_mouse_move(&mut self, ctx: &NodeContext, event: Event<MouseMove>) {
let (_, h) = ctx.bounds_self.get();
let part = event.mouse.y / h;
Expand Down
4 changes: 4 additions & 0 deletions examples/src/mouse-animation/src/path_animation.pax
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
fill={self.fill}
elements={self.path_elements}
/>

@settings {
@mount: on_mount
}
48 changes: 24 additions & 24 deletions examples/src/mouse-animation/src/path_animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,31 @@ pub struct PathAnimation {

impl Default for PathAnimation {
fn default() -> Self {
let fill = Property::new(Color::RED);
let t: Property<Numeric> = Property::new(0.0.into());
let resolution: Property<Numeric> = Property::new(60.into());
let path_config = Property::new(PathConfig {
amplitude: Property::new(0.3.into()),
amplitude_ramp: Property::new(0.3.into()),
frequency: Property::new(1.0.into()),
frequency_ramp: Property::new(1.0.into()),
thickness: Property::new(0.01.into()),
thickness_ramp: Property::new(0.3.into()),
span: Property::new(0.3.into()),
});
Self {
fill: Property::new(Color::RED),
t: Property::new(0.0.into()),
resolution: Property::new(60.into()),
path_config: Property::new(PathConfig {
amplitude: Property::new(0.3.into()),
amplitude_ramp: Property::new(0.3.into()),
frequency: Property::new(1.0.into()),
frequency_ramp: Property::new(1.0.into()),
thickness: Property::new(0.01.into()),
thickness_ramp: Property::new(0.3.into()),
span: Property::new(0.3.into()),
}),
path_elements: Property::default(),
}
}
}

impl PathAnimation {
pub fn on_mount(&mut self, ctx: &NodeContext) {
let bounds = ctx.bounds_parent.get();
let path_elements = {
let t = t.clone();
let resolution = resolution.clone();
let path_config = path_config.clone();
let t = self.t.clone();
let resolution = self.resolution.clone();
let path_config = self.path_config.clone();
let deps = [t.untyped(), resolution.untyped(), path_config.untyped()];
Property::computed(
move || {
Expand Down Expand Up @@ -69,17 +77,9 @@ impl Default for PathAnimation {
&deps,
)
};

Self {
fill,
path_config,
t,
resolution,
path_elements,
}
self.path_elements.replace_with(path_elements);
}
}

#[pax]
pub struct PathConfig {
pub amplitude: Property<Numeric>,
Expand Down
4 changes: 4 additions & 0 deletions pax-designer/src/controls/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ impl Tree {
TreeMsg::ObjMouseMove(sender, x_offset, top_half) => {
drag_id.set(sender);
let tree_obj = tree_obj.get();
if drag_id_start.get() >= tree_obj.len() || sender >= tree_obj.len() {
self.dragging.set(false);
continue;
}
let original_indent = tree_obj[drag_id_start.get()].indent_level;
if drag_id_start.get() == sender {
let offset = x_offset - self.drag_x_start.get();
Expand Down
2 changes: 1 addition & 1 deletion pax-designer/src/designer_node_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl DesignerNodeType {
}
}

pub fn metadata(&self, ctx: &NodeContext) -> DesignerNodeTypeData {
pub fn metadata(&self, _ctx: &NodeContext) -> DesignerNodeTypeData {
let (name, img_path_suffix, type_id, is_container) = match self {
DesignerNodeType::Frame => (
"Frame",
Expand Down
14 changes: 6 additions & 8 deletions pax-designer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,12 @@ impl PaxDesigner {
// when manifests load, set transform of glass to fit scene
model::read_app_state(|app_state| {
let stage = app_state.stage.get();
let (w, h) = ctx
.get_nodes_by_id(DESIGNER_GLASS_ID)
.into_iter()
.next()
.unwrap()
.transform_and_bounds()
.get()
.bounds;
let Some(glass_node) = ctx.get_nodes_by_id(DESIGNER_GLASS_ID).into_iter().next()
else {
log::warn!("cound't hook up glass to world transform: couldn't find designer glass node");
return;
};
let (w, h) = glass_node.transform_and_bounds().get().bounds;
app_state.glass_to_world_transform.set(
Transform2::<World>::translate(Vector2::new(
stage.width as f64 / 2.0,
Expand Down
3 changes: 2 additions & 1 deletion pax-designer/src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ impl Model {
&deps,
)
} else {
panic!("no userland project")
log::error!("designer glass node not found");
Property::default()
}
},
&[],
Expand Down
32 changes: 25 additions & 7 deletions pax-runtime/src/engine/expanded_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ impl ExpandedNode {
Rc::new(RefCell::new(().to_pax_any())),
);
let root_node = Self::new(template, root_env, ctx, Weak::new(), Weak::new());
Rc::clone(&root_node).recurse_mount(ctx);
root_node.bind_to_parent_bounds(ctx);
Rc::clone(&root_node).recurse_mount(ctx);
root_node
}

Expand Down Expand Up @@ -293,9 +293,9 @@ impl ExpandedNode {
Rc::clone(&*borrow!(new_expanded_node.common_properties));
self.occlusion.set(Default::default());

self.bind_to_parent_bounds(context);
Rc::clone(self).recurse_mount(context);
Rc::clone(self).recurse_update(context);
self.bind_to_parent_bounds(context);
}

/// Returns whether this node is a descendant of the ExpandedNode described by `other_expanded_node_id` (id)
Expand Down Expand Up @@ -367,8 +367,8 @@ impl ExpandedNode {
Rc::clone(child).recurse_unmount(context);
}
for child in new_children.iter() {
Rc::clone(child).recurse_mount(context);
child.bind_to_parent_bounds(context);
Rc::clone(child).recurse_mount(context);
}
}
*curr_children = new_children.clone();
Expand Down Expand Up @@ -485,9 +485,8 @@ impl ExpandedNode {
slot_child.recurse_mount(context);
}
}
// this is needed to reslove slot connections in a single tick (otherwise
// self.compute_flattened_slot_children() isn't run)
self.recurse_update(context);
// this is needed to reslove slot connections in a single tick
self.compute_flattened_slot_children();
}
}

Expand Down Expand Up @@ -603,11 +602,30 @@ impl ExpandedNode {
.unwrap_or_default()
};

let last_frame = Rc::new(RefCell::new(globals.frames_elapsed.get()));
let suspended = self.suspended.clone();
let frames_elapsed = globals.frames_elapsed.clone();
let deps = [frames_elapsed.untyped(), suspended.untyped()];
// TODO: this still triggers the dirty dag dependencies of ellapsed
// frames even if the value is the same. Try to make it not trigger
// dependencides when frozen
let frames_ellapsed_frozen_if_suspended = Property::computed(
move || {
if suspended.get() {
*borrow!(last_frame)
} else {
let val = frames_elapsed.get();
*borrow_mut!(last_frame) = val;
val
}
},
&deps,
);
NodeContext {
slot_index: self.slot_index.clone(),
local_stack_frame: Rc::clone(&self.stack),
component_origin: Weak::clone(&self.containing_component),
frames_elapsed: globals.frames_elapsed.clone(),
frames_elapsed: frames_ellapsed_frozen_if_suspended,
bounds_self,
bounds_parent,
runtime_context: ctx.clone(),
Expand Down
3 changes: 0 additions & 3 deletions pax-runtime/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,6 @@ impl PaxEngine {
designtime: designtime.clone(),
};

//Must register userland node first, because this will mount component trees (calling .mount)
//Because InlineFrame's mount logic assumes that the "iframe" component is already registered and available
//on runtime context, it must first be registered (here)
let mut runtime_context = Rc::new(RuntimeContext::new(
globals,
userland_main_component_instance,
Expand Down
1 change: 1 addition & 0 deletions pax-runtime/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ impl<F: Space, T: Space> std::fmt::Debug for TransformAndBounds<F, T> {
.finish()
}
}

impl<F: Space, T: Space> Default for TransformAndBounds<F, T> {
fn default() -> Self {
Self {
Expand Down
1 change: 0 additions & 1 deletion pax-std/src/core/inline_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ impl InstanceNode for InlineFrameInstance {
Rc::new(RefCell::new(().to_pax_any())),
),
)];

let new_children =
expanded_node.generate_children(children_with_envs, ctx, &expanded_node.parent_frame);
*borrow_mut!(ctx.userland_root_expanded_node) = Some(Rc::clone(&new_children[0].clone()));
Expand Down

0 comments on commit 2c19fc8

Please sign in to comment.