aura-gui 0.2.2

UI nativa acelerada por GPU para escritorio, Android e iOS, en un solo crate: estilo tipo Tailwind, componentes, sombras, animaciones y agentes de IA. Reposo a cero. Licencia AGPL-3.0 o comercial.
//! Hitboxes dentro de elementos transformados: se llevan a pantalla con la matriz vigente.

use crate::core::{Bounds, HitboxId, Pixels, Point, Size};
use crate::gpu::Affine;
use crate::view::context::ElementContext;

impl ElementContext<'_> {
    pub fn insert_hitbox(&mut self, bounds: Bounds, blocks: bool) -> HitboxId {
        let Some(transform) = self.hit_transforms.last().filter(|transform| !transform.is_identity()) else {
            let clipped = self.mask().intersect(&bounds);
            return self.frame.hitboxes.insert(clipped, blocks);
        };
        // Dentro de un elemento transformado el hitbox es el rectángulo que envuelve a la figura transformada.
        let [x, y, width, height] =
            transform.bounds_of([bounds.origin.x.0, bounds.origin.y.0, bounds.size.width.0, bounds.size.height.0]);
        self.frame
            .hitboxes
            .insert(Bounds::new(Point::new(Pixels(x), Pixels(y)), Size::new(Pixels(width), Pixels(height))), blocks)
    }

    /// Hasta `pop_hit_transform`, los hitboxes se llevan a pantalla con `transform` (dentro de la vigente).
    pub fn push_hit_transform(&mut self, transform: Affine) {
        let current = self.hit_transforms.last().copied().unwrap_or_default();
        self.hit_transforms.push(transform.then(current));
    }

    pub fn pop_hit_transform(&mut self) {
        self.hit_transforms.pop();
    }
}