add an extremely basic example for editable_text which only shows a subset of what is documented in the module
This commit is contained in:
Generated
+1
@@ -2426,6 +2426,7 @@ name = "gpui_elements"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"gpui",
|
||||
"gpui_platform",
|
||||
"smallvec",
|
||||
"unicode-segmentation",
|
||||
]
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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<Self>) -> 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);
|
||||
});
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user