Skip to content

Commit

Permalink
input: Add to support multi-line Input. (#463)
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee authored Dec 9, 2024
1 parent 39ec84b commit 9288dc9
Show file tree
Hide file tree
Showing 6 changed files with 1,008 additions and 343 deletions.
13 changes: 10 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/story/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ regex = "1"
chrono = "0.4"
serde = "1"
serde_json = "1"
unindent = "0.2.3"

[lints]
workspace = true
35 changes: 35 additions & 0 deletions crates/story/src/input_story.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub fn init(cx: &mut AppContext) {
pub struct InputStory {
input1: View<TextInput>,
input2: View<TextInput>,
textarea: View<TextInput>,
number_input1_value: i64,
number_input1: View<NumberInput>,
number_input2: View<NumberInput>,
Expand Down Expand Up @@ -83,6 +84,38 @@ impl InputStory {
let input2 = cx.new_view(|cx| TextInput::new(cx).placeholder("Enter text here..."));
cx.subscribe(&input2, Self::on_input_event).detach();

let textarea = cx.new_view(|cx| {
let mut input = TextInput::new(cx)
.multi_line()
.rows(10)
.placeholder("Enter text here...");
input.set_text(
unindent::unindent(
r#"Hello 世界,this is GPUI component.
The GPUI Component is a collection of UI components for GPUI framework, including.
Button, Input, Checkbox, Radio, Dropdown, Tab, and more...
Here is an application that is built by using GPUI Component.
> This application is still under development, not published yet.
![image](https://github.com/user-attachments/assets/559a648d-19df-4b5a-b563-b78cc79c8894)
![image](https://github.com/user-attachments/assets/5e06ad5d-7ea0-43db-8d13-86a240da4c8d)
## Demo
If you want to see the demo, here is a some demo applications.
"#,
),
cx,
);
input
});
cx.subscribe(&textarea, Self::on_input_event).detach();

let number_input1_value = 1;
let number_input1 = cx.new_view(|cx| {
let input = NumberInput::new(cx).placeholder("Number Input", cx);
Expand Down Expand Up @@ -143,6 +176,7 @@ impl InputStory {
Self {
input1,
input2,
textarea,
number_input1,
number_input1_value,
number_input2,
Expand Down Expand Up @@ -342,6 +376,7 @@ impl Render for InputStory {
.child(self.number_input2.clone()),
),
)
.child(section("Textarea", cx).child(self.textarea.clone()))
.child(
section("Input State", cx)
.child(self.disabled_input.clone())
Expand Down
Loading

0 comments on commit 9288dc9

Please sign in to comment.