gpui_base/input/input/
mod.rs1use gpui::{App, Entity, IntoElement, RenderOnce, Window};
2
3use super::{InputBaseState, InputMode};
4
5pub type InputState = InputBaseState<InputMode>;
11
12#[derive(IntoElement)]
17pub struct Input {
18 presentation: super::InlineTokenPresentation,
19 state: Entity<InputState>,
20}
21
22impl Input {
23 pub fn new(state: &Entity<InputState>) -> Self {
24 Self {
25 state: state.clone(),
26 presentation: Default::default(),
27 }
28 }
29 pub fn token<R: IntoElement>(
31 mut self,
32 render: impl Fn(&super::InlineTokenContext, &mut Window, &mut App) -> R + 'static,
33 ) -> Self {
34 self.presentation = self.presentation.token(render);
35 self
36 }
37 pub fn on_token_click(
39 mut self,
40 listener: impl Fn(&super::InlineTokenClickEvent, &mut Window, &mut App) + 'static,
41 ) -> Self {
42 self.presentation = self.presentation.on_token_click(listener);
43 self
44 }
45}
46
47impl RenderOnce for Input {
48 fn render(self, _: &mut Window, cx: &mut App) -> impl IntoElement {
49 self.state.update(cx, |state, _| {
50 state.set_token_presentation(self.presentation)
51 });
52 self.state
53 }
54}