diff --git a/README.md b/README.md index 97e0d295..fa55f4f4 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ A UI components for building desktop application by using [GPUI](https://gpui.rs - [x] Input icon - [ ] Textarea - [ ] ContextMenu to let user copy, cut, paste -- [x] OTPInput +- [x] OtpInput - [x] Button - [x] Button with Icon - [x] IconButton diff --git a/crates/story/src/dropdown_story.rs b/crates/story/src/dropdown_story.rs index 4cf0b83c..75c7c561 100644 --- a/crates/story/src/dropdown_story.rs +++ b/crates/story/src/dropdown_story.rs @@ -110,7 +110,7 @@ impl DropdownStory { simple_dropdown3: cx.new_view(|cx| { Dropdown::string_list("string-list3", Vec::::new(), None, cx) .size(ui::Size::Small) - .render_empty(|cx| { + .empty(|cx| { h_flex() .h_24() .justify_center() diff --git a/crates/story/src/input_story.rs b/crates/story/src/input_story.rs index 8ba1ff37..9b70f6fa 100644 --- a/crates/story/src/input_story.rs +++ b/crates/story/src/input_story.rs @@ -7,7 +7,7 @@ use gpui::{ use ui::{ button::Button, h_flex, - input::{InputEvent, OTPInput, TextInput}, + input::{InputEvent, OtpInput, TextInput}, prelude::FluentBuilder as _, v_flex, Clickable, FocusableCycle, IconName, Size, }; @@ -33,9 +33,9 @@ pub struct InputStory { both_input1: View, large_input: View, small_input: View, - otp_input: View, + otp_input: View, otp_value: Option, - opt_input2: View, + opt_input2: View, } impl InputStory { @@ -87,7 +87,7 @@ impl InputStory { .placeholder("This input have prefix and suffix.") }); - let otp_input = cx.new_view(|cx| OTPInput::new(6, cx).masked(true)); + let otp_input = cx.new_view(|cx| OtpInput::new(6, cx).masked(true)); cx.subscribe(&otp_input, |this, _, ev: &InputEvent, cx| match ev { InputEvent::Change(text) => { this.otp_value = Some(text.clone()); @@ -123,7 +123,7 @@ impl InputStory { both_input1, otp_input, otp_value: None, - opt_input2: cx.new_view(|cx| OTPInput::new(6, cx).groups(3)), + opt_input2: cx.new_view(|cx| OtpInput::new(6, cx).groups(3)), } } diff --git a/crates/ui/src/dropdown.rs b/crates/ui/src/dropdown.rs index e8cc6321..f8806c45 100644 --- a/crates/ui/src/dropdown.rs +++ b/crates/ui/src/dropdown.rs @@ -186,7 +186,7 @@ pub struct Dropdown { placeholder: SharedString, title_prefix: Option, selected_value: Option<::Value>, - render_empty: Option AnyElement + 'static>>, + empty: Option AnyElement + 'static>>, } impl Dropdown @@ -216,7 +216,7 @@ where open: false, cleanable: false, title_prefix: None, - render_empty: None, + empty: None, }; this.set_selected_index(selected_index, cx); this @@ -249,12 +249,12 @@ where self } - pub fn render_empty(mut self, f: F) -> Self + pub fn empty(mut self, f: F) -> Self where E: IntoElement, F: Fn(&WindowContext) -> E + 'static, { - self.render_empty = Some(Box::new(move |cx| f(cx).into_any_element())); + self.empty = Some(Box::new(move |cx| f(cx).into_any_element())); self } @@ -351,7 +351,7 @@ where }) .map(|this| { if is_empty { - if let Some(render_empty) = &self.render_empty { + if let Some(render_empty) = &self.empty { with_style(this, cx).child(render_empty(cx)) } else { this diff --git a/crates/ui/src/input/otp_input.rs b/crates/ui/src/input/otp_input.rs index fa042ccb..02f34632 100644 --- a/crates/ui/src/input/otp_input.rs +++ b/crates/ui/src/input/otp_input.rs @@ -13,7 +13,7 @@ pub enum InputOptEvent { Change(SharedString), } -pub struct OTPInput { +pub struct OtpInput { focus_handle: FocusHandle, length: usize, number_of_groups: usize, @@ -22,7 +22,7 @@ pub struct OTPInput { blink_cursor: Model, } -impl OTPInput { +impl OtpInput { pub fn new(length: usize, cx: &mut ViewContext) -> Self { let focus_handle = cx.focus_handle(); let blink_cursor = cx.new_model(|cx| BlinkCursor::new(cx)); @@ -128,14 +128,14 @@ impl OTPInput { } } -impl FocusableView for OTPInput { +impl FocusableView for OtpInput { fn focus_handle(&self, _: &gpui::AppContext) -> FocusHandle { self.focus_handle.clone() } } -impl EventEmitter for OTPInput {} +impl EventEmitter for OtpInput {} -impl Render for OTPInput { +impl Render for OtpInput { fn render(&mut self, cx: &mut ViewContext) -> impl IntoElement { let blink_show = self.blink_cursor.read(cx).visible(); let is_focused = self.focus_handle.is_focused(cx);