pub struct View {
pub view_id: Option<usize>,
/* private fields */
}Expand description
A group of DrawCalls.
This is really a pointer to a CxView (indexed in Cx::views using View::view_id),
so you can find more information there.
A View has a few special features:
- It has its own
Rect, within which everything is clipped (see also [DrawUniforms]). This typically gets set by the return value ofCx::end_typed_boxfor the [CxLayoutBox] that is associated with theView. TODO(JP): Look into decoupling [CxLayoutBox] fromView. - It can scroll (but does not have to; again see also [
DrawUniforms]). - It has its own set of
DrawCalls, which are isolated from theDrawCalls of the parentView.
Fieldsยง
ยงview_id: Option<usize>Implementationsยง
Sourceยงimpl View
impl View
Sourcepub fn with_is_overlay(self, is_overlay: bool) -> Self
pub fn with_is_overlay(self, is_overlay: bool) -> Self
Creates a new, empty View.
See View::is_overlay.
Sourcepub fn begin_view(&mut self, cx: &mut Cx, layout_size: LayoutSize)
pub fn begin_view(&mut self, cx: &mut Cx, layout_size: LayoutSize)
Register the View in the draw tree.
This also creates a new [CxLayoutBox] with the LayoutSize that is passed in.
Note that you should not create a View just in order to get a new
[CxLayoutBox], since creating a View is relatively expensive โ no
DrawCalls inside this View will get merged with ones outside of
it, so adding too many Views will create too many individual calls to
the GPU.
TODO(JP): Perhaps we should decouple [CxLayoutBox] and View altogether?
Sourcepub fn end_view(&mut self, cx: &mut Cx) -> Area
pub fn end_view(&mut self, cx: &mut Cx) -> Area
End the View, by ending the [CxLayoutBox]. Returns a ViewArea that
you can hold onto.
Should only be called if View::begin_view returned Result::Ok.
TODO(JP): Is the ViewArea redundant, since it basically contains the
same information as the View itself?
Sourcepub fn get_rect(&self, cx: &Cx) -> Rect
pub fn get_rect(&self, cx: &Cx) -> Rect
Get the Rect that the [CxLayoutBox] associated with the View
returned.
TODO(JP): Should we return an Option<Rect> instead of just
returning a zero-sized Rect when the View has never been
drawn yet?
TODO(JP): Doesnโt check if the View::redraw_id is still up to
date, so we might be returning an outdated Rect here.
Sourcepub fn area(&self) -> Area
pub fn area(&self) -> Area
Returns an Area::View for this View, or Area::Empty if the
View hasnโt been instantiated yet.
Sourcepub fn get_scroll_pos(&self, cx: &Cx) -> Vec2
pub fn get_scroll_pos(&self, cx: &Cx) -> Vec2
Get the current CxView::unsnapped_scroll if the View has been
instantiated.