add stubs for allowing the user to provide their own storage mediums
This commit is contained in:
@@ -41,6 +41,11 @@ impl TextInputElement {
|
||||
self.placeholder = Some(text.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_storage(mut self, fn_init: impl Into<InitStorage>) -> Self {
|
||||
self.init_storage = fn_init.into();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl InteractiveElement for TextInputElement {
|
||||
|
||||
@@ -14,9 +14,21 @@ pub enum TextBoundary {
|
||||
}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub(super) struct InitStorage(Option<Rc<dyn Fn(&mut App) -> Box<dyn UnicodeTextStorage>>>);
|
||||
pub struct InitStorage(Option<Rc<dyn Fn(&mut App) -> Box<dyn UnicodeTextStorage>>>);
|
||||
|
||||
// TODO: Doesnt yet compile in practice "implementation of Fn is not general enough"
|
||||
// InitStorage::from(|_cx| Box::new(StringStorage::default()) as Box<dyn UnicodeTextStorage>);
|
||||
impl<F> From<F> for InitStorage
|
||||
where
|
||||
F: 'static + for<'app> Fn(&'app mut App) -> Box<dyn UnicodeTextStorage>,
|
||||
{
|
||||
fn from(value: F) -> Self {
|
||||
Self(Some(Rc::new(value)))
|
||||
}
|
||||
}
|
||||
|
||||
impl InitStorage {
|
||||
pub fn exec(&self, cx: &mut App) -> Box<dyn UnicodeTextStorage> {
|
||||
pub(super) fn exec(&self, cx: &mut App) -> Box<dyn UnicodeTextStorage> {
|
||||
match &self.0 {
|
||||
None => Box::new(StringStorage::default()),
|
||||
Some(init) => (*init)(cx),
|
||||
|
||||
@@ -40,6 +40,11 @@ impl TextAreaElement {
|
||||
self.placeholder = Some(text.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_storage(mut self, fn_init: impl Into<InitStorage>) -> Self {
|
||||
self.init_storage = fn_init.into();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl InteractiveElement for TextAreaElement {
|
||||
|
||||
Reference in New Issue
Block a user