use crate::{ Holds, LayerId, LayoutLen, MaskIdx, MoveIdx, PrimitiveHandle, RegionAlign, Size, TextureHandle, UiRegion, UiVec2, WidgetId, }; /// What is kept of a widget its parent has asked about. `drawn` says whether /// it currently draws; one that does not is kept so that a change to it, or /// under it, still reaches whoever asked. #[derive(Debug)] pub struct ActiveData { pub id: WidgetId, /// The box its drawing is in, in `parent_move`'s coordinates. pub region: UiRegion, /// The box its parent gave it, in the same coordinates: what it was /// asked about, before its own answer placed its drawing inside it. /// `region` is that placement, and a local redraw asks here. pub given: UiRegion, /// The same box as lengths of its parent's box, which is the one route /// to a box in pixels: a draw threads these down a level at a time, and /// [`crate::UiRenderState::redraw`] takes the same steps back up. pub given_len: UiVec2, /// The lengths of the box its parent first asked about it in, as /// lengths of the box the parent was itself offered. Any later box it /// was given was decided knowing its answer, so this is the question /// asked again -- and a chain of fractions has no frame in it, which is /// why a region node between two widgets cannot break it. pub offer_len: UiVec2, /// What it answered there: the size and what that held for. pub answer: (Size, [Holds; 2]), /// What the widget said it used of its box, the last time it drew. pub size: Size, /// The pixel lengths of `region`, per axis, that its drawing and `size` /// hold for. pub holds: [Holds; 2], pub drawn: bool, pub parent: Option, /// How far down the tree it was drawn, the root being 1. Carried down a /// draw rather than worked out by walking up, so it is right for every /// widget a frame visits and cannot drift while one is being drawn. pub depth: usize, pub textures: Vec, pub primitives: Vec, pub children: Vec, /// The children whose size this widget read while drawing. pub size_deps: Vec, /// The movable region its primitives are positioned through: its own when /// opted in, otherwise the nearest ancestor's. pub move_idx: MoveIdx, /// The declared lengths whoever drew this widget resolved into its box. /// A change to one moves a box this widget cannot fix by drawing again, /// and comparing them is what says so. pub declared: [Option; 2], /// The axes along which its parent chose its box from its own answer, /// so a local redraw asks the question its parent asked. pub decided: [bool; 2], /// Its alignment when it was last drawn, which a change to the property /// is found against. pub own_align: RegionAlign, /// The movable region whose coordinates `region` uses. pub parent_move: MoveIdx, pub mask: MaskIdx, pub layer: LayerId, } impl ActiveData { /// Whether its drawing and size hold for a box of these pixel lengths. pub fn holds_at(&self, px: crate::PxVec2) -> bool { self.holds[0].contains(px.x) && self.holds[1].contains(px.y) } }