use crate::{ Holds, LayerId, LayoutLen, MaskIdx, MoveIdx, PrimitiveHandle, RegionAlign, Size, TextureHandle, UiRegion, 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 first asked about it in, as a part of the box the /// parent was itself asked in. Any later box it was given was decided /// knowing its answer, so this is where a question about it is asked /// again -- and it is kept relative so that it follows the parent's. pub offer: UiRegion, /// 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 alignment its parent asked it with. A local redraw repeats that /// question, including an override chosen by a container. pub align: RegionAlign, /// Whether that alignment was the parent's override rather than the /// widget's own property. pub align_override: bool, /// Its own alignment when it was last drawn. A change to the property is /// found against this even when its parent overrode the alignment. 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) } }