From 32cca07bb4aaf400a3bcc28723ced14c9f0c82c1 Mon Sep 17 00:00:00 2001 From: temportalflux Date: Sat, 11 Jul 2026 09:18:02 -0400 Subject: [PATCH] add an extremely basic example for editable_text which only shows a subset of what is documented in the module --- Cargo.lock | 1 + crates/gpui_elements/Cargo.toml | 5 ++ .../gpui_elements/examples/editable_text.rs | 66 +++++++++++++++++++ crates/gpui_elements/src/editable_text.rs | 3 +- 4 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 crates/gpui_elements/examples/editable_text.rs diff --git a/Cargo.lock b/Cargo.lock index ab9fdd6f6c..cd29eabaf3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2426,6 +2426,7 @@ name = "gpui_elements" version = "0.1.0" dependencies = [ "gpui", + "gpui_platform", "smallvec", "unicode-segmentation", ] diff --git a/crates/gpui_elements/Cargo.toml b/crates/gpui_elements/Cargo.toml index 07d893acb0..b0ad429fd7 100644 --- a/crates/gpui_elements/Cargo.toml +++ b/crates/gpui_elements/Cargo.toml @@ -18,3 +18,8 @@ smallvec.workspace = true [dev-dependencies] gpui = { path = "../gpui", features = ["test-support"] } +gpui_platform = { workspace = true, features = ["font-kit", "wayland", "x11"] } + +[[example]] +name = "editable_text" +path = "examples/editable_text.rs" diff --git a/crates/gpui_elements/examples/editable_text.rs b/crates/gpui_elements/examples/editable_text.rs new file mode 100644 index 0000000000..4fcffea1f6 --- /dev/null +++ b/crates/gpui_elements/examples/editable_text.rs @@ -0,0 +1,66 @@ +use gpui::{ + App, Bounds, Context, Hsla, Window, WindowBounds, WindowOptions, div, prelude::*, px, rgb, size, +}; +use gpui_elements::editable_text::{ + actions::{DEFAULT_INPUT_CONTEXT, default_bindings}, + text_area, text_input, +}; + +struct Example; +impl Render for Example { + fn render(&mut self, _window: &mut Window, _cx: &mut Context) -> impl IntoElement { + div() + .size_full() + .bg(rgb(0x505050)) + .flex() + .flex_col() + .p_2() + .gap_2() + .items_start() + .justify_start() + .child( + text_input("input-field") + .caret_blink_interval_500ms() + .placeholder("some placeholder text") + .border_1() + .rounded_lg() + .border_color(Hsla::white()) // has a border + .p_2() // padding between the text and border + .min_w_10() + .max_w_128() + .min_h_auto() + .max_h_auto() + .whitespace_nowrap(), + ) + .child( + text_area("text-area") + .placeholder("empty text") + .border_1() + .rounded_lg() + .border_color(Hsla::white()) // has a border + .p_2() // padding between the text and border + .w_full() + .min_h_24() + .max_h_128() + .whitespace_normal() // default + .overflow_y_scroll(), + ) + } +} + +fn main() { + gpui_platform::application().run(|cx: &mut App| { + cx.bind_keys(default_bindings().as_keybindings(Some(DEFAULT_INPUT_CONTEXT))); + + let bounds = Bounds::centered(None, size(px(500.), px(500.0)), cx); + cx.open_window( + WindowOptions { + window_bounds: Some(WindowBounds::Windowed(bounds)), + ..Default::default() + }, + |_, cx| cx.new(|_| Example), + ) + .unwrap(); + cx.activate(true); + }); +} diff --git a/crates/gpui_elements/src/editable_text.rs b/crates/gpui_elements/src/editable_text.rs index 1abe4f524d..2c05cf5280 100644 --- a/crates/gpui_elements/src/editable_text.rs +++ b/crates/gpui_elements/src/editable_text.rs @@ -150,8 +150,7 @@ //! # } //! ``` //! -//! You can view more complex examples in the gpui crate examples. -//! TODO: there is no example with editable text yet, and we should link it here when there is. +//! Full-text examples can be found in the [examples folder](https://github.com/gpui-ce/gpui-ce/tree/main/crates/gpui_elements/examples) //! //! ### Backlog of not-yet implemented features: //! - detecting focus being lost on an EditableText field