2020-03-04 18:33:11 -08:00
|
|
|
|
//! Various traits used for Views.
|
|
|
|
|
|
2021-08-07 22:31:48 -07:00
|
|
|
|
#[cfg(feature = "appkit")]
|
2020-03-10 20:09:24 -07:00
|
|
|
|
use crate::dragdrop::{DragInfo, DragOperation};
|
2021-04-15 17:13:59 -07:00
|
|
|
|
|
2020-03-19 20:07:44 -07:00
|
|
|
|
use crate::view::View;
|
|
|
|
|
|
2021-03-05 14:11:17 -08:00
|
|
|
|
/// This trait can be used for implementing custom View behavior. You implement this trait on your
|
|
|
|
|
/// struct, and wrap your struct in a `View` or `ViewController`. The view or controller then
|
|
|
|
|
/// handles interfacing between your struct and system events.
|
|
|
|
|
///
|
|
|
|
|
/// It winds up feeling to subclassing, without the ability to subclass multiple levels deep and
|
|
|
|
|
/// get ultra confusing.
|
2021-02-07 20:25:56 -08:00
|
|
|
|
#[allow(unused_variables)]
|
2020-03-19 20:07:44 -07:00
|
|
|
|
pub trait ViewDelegate {
|
2021-02-07 20:25:56 -08:00
|
|
|
|
/// Used to cache subclass creations on the Objective-C side.
|
|
|
|
|
/// You can just set this to be the name of your view type. This
|
|
|
|
|
/// value *must* be unique per-type.
|
|
|
|
|
const NAME: &'static str;
|
|
|
|
|
|
|
|
|
|
/// You should rarely (read: probably never) need to implement this yourself.
|
|
|
|
|
/// It simply acts as a getter for the associated `NAME` const on this trait.
|
|
|
|
|
fn subclass_name(&self) -> &'static str {
|
|
|
|
|
Self::NAME
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-16 17:11:04 -08:00
|
|
|
|
/// Called when the View is ready to work with. You're passed a `View` - this is safe to
|
2020-03-19 20:07:44 -07:00
|
|
|
|
/// store and use repeatedly, but it's not thread safe - any UI calls must be made from the
|
|
|
|
|
/// main thread!
|
2021-02-07 20:25:56 -08:00
|
|
|
|
fn did_load(&mut self, view: View) {}
|
2020-03-19 20:07:44 -07:00
|
|
|
|
|
|
|
|
|
/// Called when this is about to be added to the view heirarchy.
|
2021-02-07 20:25:56 -08:00
|
|
|
|
fn will_appear(&self, animated: bool) {}
|
2020-03-19 20:07:44 -07:00
|
|
|
|
|
|
|
|
|
/// Called after this has been added to the view heirarchy.
|
2021-02-07 20:25:56 -08:00
|
|
|
|
fn did_appear(&self, animated: bool) {}
|
2020-03-19 20:07:44 -07:00
|
|
|
|
|
|
|
|
|
/// Called when this is about to be removed from the view heirarchy.
|
2021-02-07 20:25:56 -08:00
|
|
|
|
fn will_disappear(&self, animated: bool) {}
|
2020-03-19 20:07:44 -07:00
|
|
|
|
|
|
|
|
|
/// Called when this has been removed from the view heirarchy.
|
2021-02-07 20:25:56 -08:00
|
|
|
|
fn did_disappear(&self, animated: bool) {}
|
2020-03-04 18:33:11 -08:00
|
|
|
|
|
2022-07-10 17:15:29 +02:00
|
|
|
|
/// Invoked when the dragged image enters destination bounds or frame; returns dragging
|
2021-03-05 14:11:17 -08:00
|
|
|
|
/// operation to perform.
|
2021-08-07 22:31:48 -07:00
|
|
|
|
#[cfg(feature = "appkit")]
|
2022-07-15 16:14:02 +02:00
|
|
|
|
fn dragging_entered(&self, info: DragInfo) -> DragOperation {
|
|
|
|
|
DragOperation::None
|
|
|
|
|
}
|
2022-07-10 17:15:29 +02:00
|
|
|
|
|
|
|
|
|
/// Invoked when the image is released, allowing the receiver to agree to or refuse
|
2021-03-05 14:11:17 -08:00
|
|
|
|
/// drag operation.
|
2021-08-07 22:31:48 -07:00
|
|
|
|
#[cfg(feature = "appkit")]
|
2022-07-15 16:14:02 +02:00
|
|
|
|
fn prepare_for_drag_operation(&self, info: DragInfo) -> bool {
|
|
|
|
|
false
|
|
|
|
|
}
|
2020-03-10 20:09:24 -07:00
|
|
|
|
|
2022-07-10 17:15:29 +02:00
|
|
|
|
/// Invoked after the released image has been removed from the screen, signaling the
|
2021-03-05 14:11:17 -08:00
|
|
|
|
/// receiver to import the pasteboard data.
|
2021-08-07 22:31:48 -07:00
|
|
|
|
#[cfg(feature = "appkit")]
|
2022-07-15 16:14:02 +02:00
|
|
|
|
fn perform_drag_operation(&self, info: DragInfo) -> bool {
|
|
|
|
|
false
|
|
|
|
|
}
|
2020-03-10 20:09:24 -07:00
|
|
|
|
|
2021-03-05 14:11:17 -08:00
|
|
|
|
/// Invoked when the dragging operation is complete, signaling the receiver to perform
|
|
|
|
|
/// any necessary clean-up.
|
2021-08-07 22:31:48 -07:00
|
|
|
|
#[cfg(feature = "appkit")]
|
2021-02-07 20:25:56 -08:00
|
|
|
|
fn conclude_drag_operation(&self, info: DragInfo) {}
|
2020-03-10 20:09:24 -07:00
|
|
|
|
|
2022-07-10 17:15:29 +02:00
|
|
|
|
/// Invoked when the dragged image exits the destination’s bounds rectangle (in the case
|
2021-03-05 14:11:17 -08:00
|
|
|
|
/// of a view) or its frame rectangle (in the case of a window object).
|
2021-08-07 22:31:48 -07:00
|
|
|
|
#[cfg(feature = "appkit")]
|
2021-02-07 20:25:56 -08:00
|
|
|
|
fn dragging_exited(&self, info: DragInfo) {}
|
2021-02-12 17:57:06 -08:00
|
|
|
|
|
|
|
|
|
//fn perform_key_equivalent(&self, event: Event) -> bool { false }
|
2020-03-04 18:33:11 -08:00
|
|
|
|
}
|