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