1//! This crate provides UI components that can be used for form-like scenarios, such as a input and number field.
2//!
3//! It can't be located in the `ui` crate because it depends on `editor`.
4//!
5mod input_field;
6
7use std::{
8 any::Any,
9 sync::{Arc, OnceLock},
10};
11
12use gpui::{FocusHandle, Subscription};
13pub use input_field::*;
14use ui::{AnyElement, App, Window};
15
16pub trait ErasedEditor: 'static {
17 fn text(&self, cx: &App) -> String;
18 fn set_text(&self, text: &str, window: &mut Window, cx: &mut App);
19 fn clear(&self, window: &mut Window, cx: &mut App);
20 fn set_placeholder_text(&self, text: &str, window: &mut Window, _: &mut App);
21 fn move_selection_to_end(&self, window: &mut Window, _: &mut App);
22 fn set_masked(&self, masked: bool, window: &mut Window, cx: &mut App);
23
24 fn focus_handle(&self, cx: &App) -> FocusHandle;
25
26 fn subscribe(
27 &self,
28 callback: Box<dyn FnMut(ErasedEditorEvent, &mut Window, &mut App) + 'static>,
29 window: &mut Window,
30 cx: &mut App,
31 ) -> Subscription;
32 fn render(&self, window: &mut Window, cx: &App) -> AnyElement;
33 fn as_any(&self) -> &dyn Any;
34}
35
36#[derive(Copy, Clone, Debug, PartialEq, Eq)]
37pub enum ErasedEditorEvent {
38 BufferEdited,
39 Blurred,
40}
41pub static ERASED_EDITOR_FACTORY: OnceLock<fn(&mut Window, &mut App) -> Arc<dyn ErasedEditor>> =
42 OnceLock::new();