Rename dropdown render_empty to empty (#82)
Also, `OTPInput` to `OtpInput`
This commit is contained in:
parent
a3df086e79
commit
66698bfe27
5 changed files with 17 additions and 17 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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<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 {
|
||||
|
|
@ -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)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
@ -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<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
|
||||
}
|
||||
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<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));
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue