Skip to content

Commit

Permalink
Rename dropdown render_empty to empty
Browse files Browse the repository at this point in the history
  • Loading branch information
madcodelife committed Jul 29, 2024
1 parent a3df086 commit d899832
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/story/src/dropdown_story.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl DropdownStory {
simple_dropdown3: cx.new_view(|cx| {
Dropdown::string_list("string-list3", Vec::<SharedString>::new(), None, cx)
.size(ui::Size::Small)
.render_empty(|cx| {
.empty(|cx| {
h_flex()
.h_24()
.justify_center()
Expand Down
10 changes: 5 additions & 5 deletions crates/story/src/input_story.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -33,9 +33,9 @@ pub struct InputStory {
both_input1: View<TextInput>,
large_input: View<TextInput>,
small_input: View<TextInput>,
otp_input: View<OTPInput>,
otp_input: View<OtpInput>,
otp_value: Option<SharedString>,
opt_input2: View<OTPInput>,
opt_input2: View<OtpInput>,
}

impl InputStory {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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)),
}
}

Expand Down
10 changes: 5 additions & 5 deletions crates/ui/src/dropdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ pub struct Dropdown<D: DropdownDelegate + 'static> {
placeholder: SharedString,
title_prefix: Option<SharedString>,
selected_value: Option<<D::Item as DropdownItem>::Value>,
render_empty: Option<Box<dyn Fn(&WindowContext) -> AnyElement + 'static>>,
empty: Option<Box<dyn Fn(&WindowContext) -> AnyElement + 'static>>,
}

impl<D> Dropdown<D>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -249,12 +249,12 @@ where
self
}

pub fn render_empty<E, F>(mut self, f: F) -> Self
pub fn empty<E, F>(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
}

Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions crates/ui/src/input/otp_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub enum InputOptEvent {
Change(SharedString),
}

pub struct OTPInput {
pub struct OtpInput {
focus_handle: FocusHandle,
length: usize,
number_of_groups: usize,
Expand All @@ -22,7 +22,7 @@ pub struct OTPInput {
blink_cursor: Model<BlinkCursor>,
}

impl OTPInput {
impl OtpInput {
pub fn new(length: usize, cx: &mut ViewContext<Self>) -> Self {
let focus_handle = cx.focus_handle();
let blink_cursor = cx.new_model(|cx| BlinkCursor::new(cx));
Expand Down Expand Up @@ -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<InputEvent> for OTPInput {}
impl EventEmitter<InputEvent> for OtpInput {}

impl Render for OTPInput {
impl Render for OtpInput {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
let blink_show = self.blink_cursor.read(cx).visible();
let is_focused = self.focus_handle.is_focused(cx);
Expand Down

0 comments on commit d899832

Please sign in to comment.