pub trait View {
Show 18 methods
// Required methods
fn view_data(&self) -> &ViewData;
fn view_data_mut(&mut self) -> &mut ViewData;
// Provided methods
fn for_each_child<'a>(
&'a self,
_for_each: &mut dyn FnMut(&'a dyn View) -> bool
) { ... }
fn for_each_child_mut<'a>(
&'a mut self,
_for_each: &mut dyn FnMut(&'a mut dyn View) -> bool
) { ... }
fn for_each_child_rev_mut<'a>(
&'a mut self,
_for_each: &mut dyn FnMut(&'a mut dyn View) -> bool
) { ... }
fn id(&self) -> Id { ... }
fn view_style(&self) -> Option<Style> { ... }
fn view_class(&self) -> Option<StyleClassRef> { ... }
fn child(&self, id: Id) -> Option<&dyn View> { ... }
fn child_mut(&mut self, id: Id) -> Option<&mut dyn View> { ... }
fn debug_name(&self) -> Cow<'static, str> { ... }
fn update(&mut self, _cx: &mut UpdateCx<'_>, _state: Box<dyn Any>) { ... }
fn style(&mut self, cx: &mut StyleCx<'_>) { ... }
fn layout(&mut self, cx: &mut LayoutCx<'_>) -> Node { ... }
fn compute_layout(&mut self, cx: &mut ComputeLayoutCx<'_>) -> Option<Rect> { ... }
fn event(
&mut self,
cx: &mut EventCx<'_>,
id_path: Option<&[Id]>,
event: Event
) -> EventPropagation { ... }
fn paint(&mut self, cx: &mut PaintCx<'_>) { ... }
fn scroll_to(
&mut self,
cx: &mut AppState,
target: Id,
rect: Option<Rect>
) -> bool { ... }
}
Required Methods§
Provided Methods§
sourcefn for_each_child<'a>(&'a self, _for_each: &mut dyn FnMut(&'a dyn View) -> bool)
fn for_each_child<'a>(&'a self, _for_each: &mut dyn FnMut(&'a dyn View) -> bool)
This method walks over children and must be implemented if the view has any children.
It should return children back to front and should stop if _for_each
returns true
.
sourcefn for_each_child_mut<'a>(
&'a mut self,
_for_each: &mut dyn FnMut(&'a mut dyn View) -> bool
)
fn for_each_child_mut<'a>( &'a mut self, _for_each: &mut dyn FnMut(&'a mut dyn View) -> bool )
This method walks over children and must be implemented if the view has any children.
It should return children back to front and should stop if _for_each
returns true
.
sourcefn for_each_child_rev_mut<'a>(
&'a mut self,
_for_each: &mut dyn FnMut(&'a mut dyn View) -> bool
)
fn for_each_child_rev_mut<'a>( &'a mut self, _for_each: &mut dyn FnMut(&'a mut dyn View) -> bool )
This method walks over children and must be implemented if the view has any children.
It should return children front to back and should stop if _for_each
returns true
.
fn id(&self) -> Id
fn view_style(&self) -> Option<Style>
fn view_class(&self) -> Option<StyleClassRef>
fn child(&self, id: Id) -> Option<&dyn View>
fn child_mut(&mut self, id: Id) -> Option<&mut dyn View>
fn debug_name(&self) -> Cow<'static, str>
sourcefn update(&mut self, _cx: &mut UpdateCx<'_>, _state: Box<dyn Any>)
fn update(&mut self, _cx: &mut UpdateCx<'_>, _state: Box<dyn Any>)
Use this method to react to changes in view-related state.
You will usually send state to this hook manually using the View
’s Id
handle
self.id.update_state(SomeState)
You are in charge of downcasting the state to the expected type.
If the update needs other passes to run you’re expected to call
_cx.app_state_mut().request_changes
.
sourcefn style(&mut self, cx: &mut StyleCx<'_>)
fn style(&mut self, cx: &mut StyleCx<'_>)
Use this method to style the view’s children.
If the style changes needs other passes to run you’re expected to call
cx.app_state_mut().request_changes
.
sourcefn layout(&mut self, cx: &mut LayoutCx<'_>) -> Node
fn layout(&mut self, cx: &mut LayoutCx<'_>) -> Node
Use this method to layout the view’s children.
Usually you’ll do this by calling LayoutCx::layout_node
.
If the layout changes needs other passes to run you’re expected to call
cx.app_state_mut().request_changes
.
sourcefn compute_layout(&mut self, cx: &mut ComputeLayoutCx<'_>) -> Option<Rect>
fn compute_layout(&mut self, cx: &mut ComputeLayoutCx<'_>) -> Option<Rect>
Responsible for computing the layout of the view’s children.
If the layout changes needs other passes to run you’re expected to call
cx.app_state_mut().request_changes
.
sourcefn event(
&mut self,
cx: &mut EventCx<'_>,
id_path: Option<&[Id]>,
event: Event
) -> EventPropagation
fn event( &mut self, cx: &mut EventCx<'_>, id_path: Option<&[Id]>, event: Event ) -> EventPropagation
Implement this to handle events and to pass them down to children
Return true to stop the event from propagating to other views
If the event needs other passes to run you’re expected to call
cx.app_state_mut().request_changes
.
sourcefn paint(&mut self, cx: &mut PaintCx<'_>)
fn paint(&mut self, cx: &mut PaintCx<'_>)
View
-specific implementation. Will be called in PaintCx::paint_view
.
Usually you’ll call paint_view
for every child view. But you might also draw text, adjust the offset, clip
or draw text.
Trait Implementations§
source§impl View for Box<dyn View>
impl View for Box<dyn View>
fn view_data(&self) -> &ViewData
fn view_data_mut(&mut self) -> &mut ViewData
source§fn for_each_child<'a>(&'a self, for_each: &mut dyn FnMut(&'a dyn View) -> bool)
fn for_each_child<'a>(&'a self, for_each: &mut dyn FnMut(&'a dyn View) -> bool)
_for_each
returns true
.source§fn for_each_child_mut<'a>(
&'a mut self,
for_each: &mut dyn FnMut(&'a mut dyn View) -> bool
)
fn for_each_child_mut<'a>( &'a mut self, for_each: &mut dyn FnMut(&'a mut dyn View) -> bool )
_for_each
returns true
.source§fn for_each_child_rev_mut<'a>(
&'a mut self,
for_each: &mut dyn FnMut(&'a mut dyn View) -> bool
)
fn for_each_child_rev_mut<'a>( &'a mut self, for_each: &mut dyn FnMut(&'a mut dyn View) -> bool )
_for_each
returns true
.fn id(&self) -> Id
fn view_style(&self) -> Option<Style>
fn view_class(&self) -> Option<StyleClassRef>
fn child(&self, id: Id) -> Option<&dyn View>
fn child_mut(&mut self, id: Id) -> Option<&mut dyn View>
fn debug_name(&self) -> Cow<'static, str>
source§fn update(&mut self, cx: &mut UpdateCx<'_>, state: Box<dyn Any>)
fn update(&mut self, cx: &mut UpdateCx<'_>, state: Box<dyn Any>)
View
’s Id
handle Read moresource§fn style(&mut self, cx: &mut StyleCx<'_>)
fn style(&mut self, cx: &mut StyleCx<'_>)
source§fn layout(&mut self, cx: &mut LayoutCx<'_>) -> Node
fn layout(&mut self, cx: &mut LayoutCx<'_>) -> Node
LayoutCx::layout_node
. Read moresource§fn compute_layout(&mut self, cx: &mut ComputeLayoutCx<'_>) -> Option<Rect>
fn compute_layout(&mut self, cx: &mut ComputeLayoutCx<'_>) -> Option<Rect>
source§fn event(
&mut self,
cx: &mut EventCx<'_>,
id_path: Option<&[Id]>,
event: Event
) -> EventPropagation
fn event( &mut self, cx: &mut EventCx<'_>, id_path: Option<&[Id]>, event: Event ) -> EventPropagation
source§fn paint(&mut self, cx: &mut PaintCx<'_>)
fn paint(&mut self, cx: &mut PaintCx<'_>)
View
-specific implementation. Will be called in PaintCx::paint_view
.
Usually you’ll call paint_view
for every child view. But you might also draw text, adjust the offset, clip
or draw text.