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
|
- [x] Input icon
|
||||||
- [ ] Textarea
|
- [ ] Textarea
|
||||||
- [ ] ContextMenu to let user copy, cut, paste
|
- [ ] ContextMenu to let user copy, cut, paste
|
||||||
- [x] OTPInput
|
- [x] OtpInput
|
||||||
- [x] Button
|
- [x] Button
|
||||||
- [x] Button with Icon
|
- [x] Button with Icon
|
||||||
- [x] IconButton
|
- [x] IconButton
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ impl DropdownStory {
|
||||||
simple_dropdown3: cx.new_view(|cx| {
|
simple_dropdown3: cx.new_view(|cx| {
|
||||||
Dropdown::string_list("string-list3", Vec::<SharedString>::new(), None, cx)
|
Dropdown::string_list("string-list3", Vec::<SharedString>::new(), None, cx)
|
||||||
.size(ui::Size::Small)
|
.size(ui::Size::Small)
|
||||||
.render_empty(|cx| {
|
.empty(|cx| {
|
||||||
h_flex()
|
h_flex()
|
||||||
.h_24()
|
.h_24()
|
||||||
.justify_center()
|
.justify_center()
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use gpui::{
|
||||||
use ui::{
|
use ui::{
|
||||||
button::Button,
|
button::Button,
|
||||||
h_flex,
|
h_flex,
|
||||||
input::{InputEvent, OTPInput, TextInput},
|
input::{InputEvent, OtpInput, TextInput},
|
||||||
prelude::FluentBuilder as _,
|
prelude::FluentBuilder as _,
|
||||||
v_flex, Clickable, FocusableCycle, IconName, Size,
|
v_flex, Clickable, FocusableCycle, IconName, Size,
|
||||||
};
|
};
|
||||||
|
|
@ -33,9 +33,9 @@ pub struct InputStory {
|
||||||
both_input1: View<TextInput>,
|
both_input1: View<TextInput>,
|
||||||
large_input: View<TextInput>,
|
large_input: View<TextInput>,
|
||||||
small_input: View<TextInput>,
|
small_input: View<TextInput>,
|
||||||
otp_input: View<OTPInput>,
|
otp_input: View<OtpInput>,
|
||||||
otp_value: Option<SharedString>,
|
otp_value: Option<SharedString>,
|
||||||
opt_input2: View<OTPInput>,
|
opt_input2: View<OtpInput>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InputStory {
|
impl InputStory {
|
||||||
|
|
@ -87,7 +87,7 @@ impl InputStory {
|
||||||
.placeholder("This input have prefix and suffix.")
|
.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 {
|
cx.subscribe(&otp_input, |this, _, ev: &InputEvent, cx| match ev {
|
||||||
InputEvent::Change(text) => {
|
InputEvent::Change(text) => {
|
||||||
this.otp_value = Some(text.clone());
|
this.otp_value = Some(text.clone());
|
||||||
|
|
@ -123,7 +123,7 @@ impl InputStory {
|
||||||
both_input1,
|
both_input1,
|
||||||
otp_input,
|
otp_input,
|
||||||
otp_value: None,
|
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,
|
placeholder: SharedString,
|
||||||
title_prefix: Option<SharedString>,
|
title_prefix: Option<SharedString>,
|
||||||
selected_value: Option<<D::Item as DropdownItem>::Value>,
|
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>
|
impl<D> Dropdown<D>
|
||||||
|
|
@ -216,7 +216,7 @@ where
|
||||||
open: false,
|
open: false,
|
||||||
cleanable: false,
|
cleanable: false,
|
||||||
title_prefix: None,
|
title_prefix: None,
|
||||||
render_empty: None,
|
empty: None,
|
||||||
};
|
};
|
||||||
this.set_selected_index(selected_index, cx);
|
this.set_selected_index(selected_index, cx);
|
||||||
this
|
this
|
||||||
|
|
@ -249,12 +249,12 @@ where
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render_empty<E, F>(mut self, f: F) -> Self
|
pub fn empty<E, F>(mut self, f: F) -> Self
|
||||||
where
|
where
|
||||||
E: IntoElement,
|
E: IntoElement,
|
||||||
F: Fn(&WindowContext) -> E + 'static,
|
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
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -351,7 +351,7 @@ where
|
||||||
})
|
})
|
||||||
.map(|this| {
|
.map(|this| {
|
||||||
if is_empty {
|
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))
|
with_style(this, cx).child(render_empty(cx))
|
||||||
} else {
|
} else {
|
||||||
this
|
this
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ pub enum InputOptEvent {
|
||||||
Change(SharedString),
|
Change(SharedString),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct OTPInput {
|
pub struct OtpInput {
|
||||||
focus_handle: FocusHandle,
|
focus_handle: FocusHandle,
|
||||||
length: usize,
|
length: usize,
|
||||||
number_of_groups: usize,
|
number_of_groups: usize,
|
||||||
|
|
@ -22,7 +22,7 @@ pub struct OTPInput {
|
||||||
blink_cursor: Model<BlinkCursor>,
|
blink_cursor: Model<BlinkCursor>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OTPInput {
|
impl OtpInput {
|
||||||
pub fn new(length: usize, cx: &mut ViewContext<Self>) -> Self {
|
pub fn new(length: usize, cx: &mut ViewContext<Self>) -> Self {
|
||||||
let focus_handle = cx.focus_handle();
|
let focus_handle = cx.focus_handle();
|
||||||
let blink_cursor = cx.new_model(|cx| BlinkCursor::new(cx));
|
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 {
|
fn focus_handle(&self, _: &gpui::AppContext) -> FocusHandle {
|
||||||
self.focus_handle.clone()
|
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 {
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||||
let blink_show = self.blink_cursor.read(cx).visible();
|
let blink_show = self.blink_cursor.read(cx).visible();
|
||||||
let is_focused = self.focus_handle.is_focused(cx);
|
let is_focused = self.focus_handle.is_focused(cx);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue