pane_ui 0.1.0

A RON-driven, hot-reloadable wgpu UI library with spring animations and consistent scaling
Documentation
// ── Actor Helpers ─────────────────────────────────────────────────────────────
//
// These inject a programmatic override directly into ActorState, bypassing the
// normal trigger system. The injected override uses `latched: true` so it stays
// active until another API call or a higher-priority RON trigger fires.

/// Find an Actor item by id and return a mutable ref to its state via the root's item+state list.
/// Calls `f` with (actor, state) if found, returns whether it was found.
pub fn with_actor_state<F>(
    items: &mut [(crate::items::UiItem, crate::widgets::ItemState)],
    id: &str,
    mut f: F,
) -> bool
where
    F: FnMut(&crate::items::Actor, &mut crate::widgets::ActorState),
{
    for (item, state) in items.iter_mut() {
        if let (crate::items::UiItem::Actor(a), crate::widgets::ItemState::Actor(s)) = (item, state)
            && a.id == id
        {
            f(a, s);
            return true;
        }
    }
    false
}

/// Inject a `MoveTo` override — actor lerps to (x, y) and latches there.
pub fn actor_move_to_in(
    items: &mut [(crate::items::UiItem, crate::widgets::ItemState)],
    id: &str,
    x: f32,
    y: f32,
    speed: f32,
) -> bool {
    with_actor_state(items, id, |_a, s| {
        let t = s.active_override.as_ref().map_or(0.0, |o| o.override_time) + 1.0;
        s.active_override = Some(crate::widgets::ActiveOverride {
            trigger: crate::items::Trigger::Always, // placeholder — latched ignores trigger
            action: crate::items::Action::MoveTo { x, y, speed },
            override_time: t,
            latched: true,
        });
    })
}

/// Inject a `FollowCursor` override.
pub fn actor_follow_cursor_in(
    items: &mut [(crate::items::UiItem, crate::widgets::ItemState)],
    id: &str,
    speed: f32,
    trail: f32,
) -> bool {
    with_actor_state(items, id, |_a, s| {
        let t = s.active_override.as_ref().map_or(0.0, |o| o.override_time) + 1.0;
        s.active_override = Some(crate::widgets::ActiveOverride {
            trigger: crate::items::Trigger::Always,
            action: crate::items::Action::FollowCursor { speed, trail },
            override_time: t,
            latched: true,
        });
    })
}

/// Clear any programmatic or trigger override — returns actor to its Always behaviour.
pub fn actor_reset_in(
    items: &mut [(crate::items::UiItem, crate::widgets::ItemState)],
    id: &str,
) -> bool {
    with_actor_state(items, id, |_a, s| {
        s.active_override = None;
    })
}

/// Teleport the actor to (x, y) instantly with no lerp.
pub fn actor_set_pos_in(
    items: &mut [(crate::items::UiItem, crate::widgets::ItemState)],
    id: &str,
    x: f32,
    y: f32,
) -> bool {
    with_actor_state(items, id, |_a, s| {
        s.pos_x = x;
        s.pos_y = y;
    })
}