cacao/src/view/traits.rs

77 lines
2.9 KiB
Rust
Raw Normal View History

//! Various traits used for Views.
#[cfg(feature = "appkit")]
use crate::dragdrop::{DragInfo, DragOperation};
use crate::view::View;
/// 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.
#[allow(unused_variables)]
pub trait ViewDelegate {
/// 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
}
/// Called when the View is ready to work with. You're passed a `View` - this is safe to
/// store and use repeatedly, but it's not thread safe - any UI calls must be made from the
/// main thread!
fn did_load(&mut self, view: View) {}
/// Called when this is about to be added to the view heirarchy.
fn will_appear(&self, animated: bool) {}
/// Called after this has been added to the view heirarchy.
fn did_appear(&self, animated: bool) {}
/// Called when this is about to be removed from the view heirarchy.
fn will_disappear(&self, animated: bool) {}
/// Called when this has been removed from the view heirarchy.
fn did_disappear(&self, animated: bool) {}
2022-07-10 17:15:29 +02:00
/// Invoked when the dragged image enters destination bounds or frame; returns dragging
/// operation to perform.
#[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
/// drag operation.
#[cfg(feature = "appkit")]
2022-07-15 16:14:02 +02:00
fn prepare_for_drag_operation(&self, info: DragInfo) -> bool {
false
}
2022-07-10 17:15:29 +02:00
/// Invoked after the released image has been removed from the screen, signaling the
/// receiver to import the pasteboard data.
#[cfg(feature = "appkit")]
2022-07-15 16:14:02 +02:00
fn perform_drag_operation(&self, info: DragInfo) -> bool {
false
}
/// Invoked when the dragging operation is complete, signaling the receiver to perform
/// any necessary clean-up.
#[cfg(feature = "appkit")]
fn conclude_drag_operation(&self, info: DragInfo) {}
2022-07-10 17:15:29 +02:00
/// Invoked when the dragged image exits the destinations bounds rectangle (in the case
/// of a view) or its frame rectangle (in the case of a window object).
#[cfg(feature = "appkit")]
fn dragging_exited(&self, info: DragInfo) {}
Begin reworking many internals to push for v0.1. - Beginning to transition View types to use Rc/RefCell internally, which should provide better guarantees about ownership on the Rust side. This is also important for certain Objective-C side scenarios where we may need to set an ivar after creation, which requires some level of mutability. This may also possibly help bring down the unsafe usage, which would be cool. - Rewrote the Color module; this now handles system colors better, and provides support for dynamic color creation. Supporting combinations of dark/light/contrast is now possible with handler passed in via `Color::dynamic`. This still has work to do in terms of some accessor methods and such, but it works well for now. The `to_platform...` method should be removed before v0.1. - Added a new feature for enabling fallback color usage on older macOS versions that don't support system colors. This may honestly never be used, but it cost nothing to implement. - Fixed a bug in the Autolayout wrapper where dereferencing could cause constraints to crash at runtime. - Support setting text color on labels. - Support setting text color on buttons, albeit very hacky right now. This needs to be extracted and/or cleaned up, but getting it sketched out was important for this commit. - Support setting a key equivalent on buttons. - Creating a local event monitor is now possible. - Examples updated; Calculator clone example added. The only API breaking change in this commit from earlier commits should be `color::rgb` needing to be `color::Color` followed by a `Color::rgb(...)` call.
2021-02-12 17:57:06 -08:00
//fn perform_key_equivalent(&self, event: Event) -> bool { false }
}