2021-01-17 12:11:04 +11:00
|
|
|
|
//! Various traits used for Labels.
|
|
|
|
|
|
2021-03-15 03:03:20 +11:00
|
|
|
|
use crate::input::TextField;
|
|
|
|
|
|
2021-03-18 15:57:52 +11:00
|
|
|
|
/// This trait can be used for implementing custom text field behavior.
|
|
|
|
|
#[allow(unused_variables)]
|
2021-01-17 12:11:04 +11:00
|
|
|
|
pub trait TextFieldDelegate {
|
2021-03-15 03:03:20 +11: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-03-18 15:57:52 +11:00
|
|
|
|
/// Called when the text field is loaded. You're passed a reference to the underlying text
|
|
|
|
|
/// field for future local use.
|
|
|
|
|
fn did_load(&mut self, view: TextField) {}
|
|
|
|
|
|
2021-03-15 03:03:20 +11:00
|
|
|
|
/// Posts a notification when the text is no longer in edit mode.
|
2021-03-18 15:57:52 +11:00
|
|
|
|
fn text_did_end_editing(&self, value: &str) {}
|
2021-03-15 03:03:20 +11:00
|
|
|
|
|
|
|
|
|
/// Requests permission to begin editing a text object.
|
2021-03-18 15:57:52 +11:00
|
|
|
|
fn text_should_begin_editing(&self, value: &str) -> bool {
|
2021-03-15 03:03:20 +11:00
|
|
|
|
true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Posts a notification to the default notification center that the text is about to go into edit mode.
|
2021-03-18 15:57:52 +11:00
|
|
|
|
fn text_did_begin_editing(&self, value: &str) {}
|
2021-03-15 03:03:20 +11:00
|
|
|
|
|
|
|
|
|
/// Posts a notification when the text changes, and forwards the message to the text field’s cell if it responds.
|
2021-03-18 15:57:52 +11:00
|
|
|
|
fn text_did_change(&self, value: &str) {}
|
2021-03-15 03:03:20 +11:00
|
|
|
|
|
|
|
|
|
/// Performs validation on the text field’s new value.
|
2021-03-18 15:57:52 +11:00
|
|
|
|
fn text_should_end_editing(&self, value: &str) -> bool {
|
2021-03-15 03:03:20 +11:00
|
|
|
|
true
|
|
|
|
|
}
|
2021-01-17 12:11:04 +11:00
|
|
|
|
}
|