add stubs for allowing the user to provide their own storage mediums

This commit is contained in:
temportalflux
2026-07-11 09:31:07 -04:00
parent 5e08033021
commit 0e34470a40
3 changed files with 24 additions and 2 deletions
@@ -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 {