pub enum Area {
Empty,
View(ViewArea),
InstanceRange(InstanceRangeArea),
}
Expand description
An Area
can be thought of as a “pointer” into the draw tree. You typically
get one as the result of a draw command, like Cx::add_instances
,
or View::end_view
.
Note that an Area
might point to an old element in the draw tree, so use
Area::is_valid
to check if it points to the latest version.
You can use an Area
pointer to write fields, e.g. using Area::get_slice_mut
,
Area::write_user_uniforms
, and so on. You
can also use it for checking if an event was fired on a certain part
of the draw tree (using Event::hits_pointer
, Cx::key_focus
, etc), and more.
TODO(JP): this can currently point to a View
/CxView
that isn’t
actually in the draw tree anymore (ie. there the corresponding CxView
is
never referenced in the draw tree), or which just doesn’t exist at all any
more (ie. the View
object has also been removed). There is currently no
was of telling if any of this is the case, since there is no “garbage
collection” of views. CxView
just sticks around in Cx::views
forever.
Variants
Empty
A “null pointer”, doesn’t point to anything yet.
View(ViewArea)
See ViewArea
.
InstanceRange(InstanceRangeArea)
See InstanceRangeArea
.
Implementations
Check if this is an Area::InstanceRange
that points to the first instance
in its corresponding DrawCall
. Useful for setting uniforms on a
DrawCall
only once, when handling the first instance.
The scroll position of an Area
is the cumulative offset of all scroll
containers (compared to if there had not been scrolling at all).
Returns the final screen Rect
for the first instance of the Area
.
TODO(JP): The “first instance” bit is confusing; in most (if not all)
cases you’d want to get something that covers the entire Area
. Maybe
returning a single Rect
isn’t the right thing then, since the
individual rectangles can be all over the place. We could return a Vec
instead?
TODO(JP): Specifically, this seems to return very weird values for
crate::TextIns
(only the first character, and offset to the bottom it seems).
Get an immutable slice for an Area::InstanceRange
.
This is not safe when T cannot be initialized with arbitrary
data, so be careful. See also crate::cast
.
Get an immutable reference to the first element.
If no such element exists, then a default element is returned.
Example:
let glyph = area.get_first::<TextIns>(cx);
TODO(JP): It would be nice if we can eliminate the default fallback altogether;
see Cx::temp_default_data
for ideas.
This is not safe when T cannot be initialized with arbitrary
data, so be careful. See also crate::cast
.
Get a mutable slice for an Area::InstanceRange
.
This is not safe when T cannot be initialized with arbitrary
data, so be careful. See also crate::cast
.
Get a mutable reference to the first element.
If no such element exists, then a default element is returned. Mutating such a default element won’t do anything, but it also won’t hurt.
Note that in general you can’t rely on these mutations to last very long, since they’ll be cleared on the next redraw.
Example:
let glyph = area.get_first_mut::<TextIns>(cx);
TODO(JP): It would be nice if we can eliminate the default fallback altogether;
see Cx::temp_default_data
for ideas.
This is not safe when T cannot be initialized with arbitrary
data, so be careful. See also crate::cast
.
Get a write user-level uniforms for the DrawCall
that this Area
points to.
It can be useful to wrap this in Area::is_first_instance
to avoid having to write
this multiple times for the same DrawCall
.
Write a Texture
value into the the DrawCall
associated with this
Area::InstanceRange
.
TODO(JP): Fix bug: https://github.com/Zaplib/zaplib/issues/156
Trait Implementations
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
impl RefUnwindSafe for Area
impl UnwindSafe for Area
Blanket Implementations
Mutably borrows from an owned value. Read more