pub trait ViewAssistant {
Show 16 methods
// Provided methods
fn setup(&mut self, context: &ViewAssistantContext) -> Result<(), Error> { ... }
fn resize(&mut self, new_size: &Size) -> Result<(), Error> { ... }
fn get_scene(&mut self, size: Size) -> Option<&mut Scene> { ... }
fn get_scene_with_contexts(
&mut self,
render_context: &mut Context,
view_context: &ViewAssistantContext,
) -> Option<&mut Scene> { ... }
fn render(
&mut self,
render_context: &mut Context,
buffer_ready_event: Event,
view_context: &ViewAssistantContext,
) -> Result<(), Error> { ... }
fn handle_input_event(
&mut self,
context: &mut ViewAssistantContext,
event: &Event,
) -> Result<(), Error> { ... }
fn handle_mouse_event(
&mut self,
context: &mut ViewAssistantContext,
event: &Event,
mouse_event: &Event,
) -> Result<(), Error> { ... }
fn handle_touch_event(
&mut self,
context: &mut ViewAssistantContext,
event: &Event,
touch_event: &Event,
) -> Result<(), Error> { ... }
fn handle_pointer_event(
&mut self,
context: &mut ViewAssistantContext,
event: &Event,
pointer_event: &Event,
) -> Result<(), Error> { ... }
fn handle_keyboard_event(
&mut self,
context: &mut ViewAssistantContext,
event: &Event,
keyboard_event: &Event,
) -> Result<(), Error> { ... }
fn handle_consumer_control_event(
&mut self,
context: &mut ViewAssistantContext,
event: &Event,
consumer_control_event: &Event,
) -> Result<(), Error> { ... }
fn handle_focus_event(
&mut self,
context: &mut ViewAssistantContext,
focused: bool,
) -> Result<(), Error> { ... }
fn handle_message(&mut self, message: Message) { ... }
fn uses_pointer_events(&self) -> bool { ... }
fn ownership_changed(&mut self, _owned: bool) -> Result<(), Error> { ... }
fn get_render_offset(&mut self) -> Option<i64> { ... }
}
Expand description
Trait that allows Carnelian developers to customize the behavior of views.
Provided Methods§
Sourcefn setup(&mut self, context: &ViewAssistantContext) -> Result<(), Error>
fn setup(&mut self, context: &ViewAssistantContext) -> Result<(), Error>
This method is called once when a view is created.
Sourcefn resize(&mut self, new_size: &Size) -> Result<(), Error>
fn resize(&mut self, new_size: &Size) -> Result<(), Error>
Implement this method to to handle when a view is resized.
Sourcefn get_scene(&mut self, size: Size) -> Option<&mut Scene>
fn get_scene(&mut self, size: Size) -> Option<&mut Scene>
Implement this method to return a mutable reference to the scene that represents the view.
Sourcefn get_scene_with_contexts(
&mut self,
render_context: &mut Context,
view_context: &ViewAssistantContext,
) -> Option<&mut Scene>
fn get_scene_with_contexts( &mut self, render_context: &mut Context, view_context: &ViewAssistantContext, ) -> Option<&mut Scene>
Implement this method to return a mutable reference to the scene that represents the view. Implement this one if you’ll need the various contexts to build a scene.
Sourcefn render(
&mut self,
render_context: &mut Context,
buffer_ready_event: Event,
view_context: &ViewAssistantContext,
) -> Result<(), Error>
fn render( &mut self, render_context: &mut Context, buffer_ready_event: Event, view_context: &ViewAssistantContext, ) -> Result<(), Error>
This method is called when a view needs to be rendered.
Sourcefn handle_input_event(
&mut self,
context: &mut ViewAssistantContext,
event: &Event,
) -> Result<(), Error>
fn handle_input_event( &mut self, context: &mut ViewAssistantContext, event: &Event, ) -> Result<(), Error>
This method is called when input events come to this view. The default implementation calls specific methods for the type of event, so usually one does not need to implement this method. Since the default methods for touch and mouse handle the pointer abstraction, make sure to call them in an implementation of this method if you wish to use that abstraction.
Sourcefn handle_mouse_event(
&mut self,
context: &mut ViewAssistantContext,
event: &Event,
mouse_event: &Event,
) -> Result<(), Error>
fn handle_mouse_event( &mut self, context: &mut ViewAssistantContext, event: &Event, mouse_event: &Event, ) -> Result<(), Error>
This method is called when mouse events come to this view.
impl ViewAssistant for SampleViewAssistant {
fn handle_mouse_event(
&mut self,
context: &mut ViewAssistantContext,
event: &input::Event,
mouse_event: &input::mouse::Event,
) -> Result<(), Error> {
match &mouse_event.phase {
input::mouse::Phase::Down(button) => {
if button.is_primary() {
self.mouse_start = mouse_event.location
}
}
input::mouse::Phase::Moved => {}
input::mouse::Phase::Up(button) => {
if button.is_primary() {
println!("mouse moved {}", mouse_event.location - self.mouse_start);
}
}
_ => (),
}
Ok(())
}
}
Sourcefn handle_touch_event(
&mut self,
context: &mut ViewAssistantContext,
event: &Event,
touch_event: &Event,
) -> Result<(), Error>
fn handle_touch_event( &mut self, context: &mut ViewAssistantContext, event: &Event, touch_event: &Event, ) -> Result<(), Error>
This method is called when touch events come to this view.
impl ViewAssistant for SampleViewAssistant {
fn handle_touch_event(
&mut self,
context: &mut ViewAssistantContext,
event: &input::Event,
touch_event: &input::touch::Event,
) -> Result<(), Error> {
for contact in &touch_event.contacts {
// Use contact.contact_id as a key to handle
// each contact individually
}
Ok(())
}
}
Sourcefn handle_pointer_event(
&mut self,
context: &mut ViewAssistantContext,
event: &Event,
pointer_event: &Event,
) -> Result<(), Error>
fn handle_pointer_event( &mut self, context: &mut ViewAssistantContext, event: &Event, pointer_event: &Event, ) -> Result<(), Error>
This method is called when the view desires pointer events and a compatible mouse or touch event comes to this view.
impl ViewAssistant for SampleViewAssistant {
fn handle_pointer_event(
&mut self,
context: &mut ViewAssistantContext,
event: &input::Event,
pointer_event: &input::pointer::Event,
) -> Result<(), Error> {
match pointer_event.phase {
input::pointer::Phase::Down(pointer_location) => {
self.pointer_start = pointer_location
}
input::pointer::Phase::Moved(pointer_location) => {
self.current_pointer_location = pointer_location;
}
input::pointer::Phase::Up => {
println!(
"pointer moved {}",
self.current_pointer_location - self.pointer_start
);
}
_ => (),
}
Ok(())
}
}
Sourcefn handle_keyboard_event(
&mut self,
context: &mut ViewAssistantContext,
event: &Event,
keyboard_event: &Event,
) -> Result<(), Error>
fn handle_keyboard_event( &mut self, context: &mut ViewAssistantContext, event: &Event, keyboard_event: &Event, ) -> Result<(), Error>
This method is called when keyboard events come to this view.
Sourcefn handle_consumer_control_event(
&mut self,
context: &mut ViewAssistantContext,
event: &Event,
consumer_control_event: &Event,
) -> Result<(), Error>
fn handle_consumer_control_event( &mut self, context: &mut ViewAssistantContext, event: &Event, consumer_control_event: &Event, ) -> Result<(), Error>
This method is called when consumer control events come to this view.
Sourcefn handle_focus_event(
&mut self,
context: &mut ViewAssistantContext,
focused: bool,
) -> Result<(), Error>
fn handle_focus_event( &mut self, context: &mut ViewAssistantContext, focused: bool, ) -> Result<(), Error>
This method is called when focus events come from Scenic to this view. It will be called once when a Carnelian app is running directly on the frame buffer, as such views are always focused. See the button sample for an one way to respond to focus.
Sourcefn handle_message(&mut self, message: Message)
fn handle_message(&mut self, message: Message)
This method is called when App::send_message
is called with the associated
view controller’s ViewKey
and the view controller does not handle the message.
use zx::MonotonicInstant;
pub enum SampleMessages {
Pressed(MonotonicInstant),
}
impl ViewAssistant for SampleViewAssistant {
fn handle_message(&mut self, message: Message) {
if let Some(sample_message) = message.downcast_ref::<SampleMessages>() {
match sample_message {
SampleMessages::Pressed(value) => {
println!("value = {:#?}", value);
}
}
}
}
}
Sourcefn uses_pointer_events(&self) -> bool
fn uses_pointer_events(&self) -> bool
Whether this view wants touch and mouse events abstracted as
input::pointer::Event
. Defaults to true.
Sourcefn ownership_changed(&mut self, _owned: bool) -> Result<(), Error>
fn ownership_changed(&mut self, _owned: bool) -> Result<(), Error>
This method is called when running directly on the display and the ownership of the display changes.
Sourcefn get_render_offset(&mut self) -> Option<i64>
fn get_render_offset(&mut self) -> Option<i64>
This method is called after setup to get an offset to use when calculating render time. It is only called once.