Fix to limit change when Input is disabled.

Add clean button to List query input.
Add ButtonRouneded with px support.
This commit is contained in:
Jason Lee 2024-07-17 10:47:25 +08:00
parent 702863eb83
commit 36411750ee
3 changed files with 24 additions and 5 deletions

View file

@ -6,8 +6,8 @@ use crate::{
};
use gpui::{
div, prelude::FluentBuilder as _, px, ClickEvent, DefiniteLength, Div, ElementId, FocusHandle,
Hsla, InteractiveElement, IntoElement, MouseButton, ParentElement, RenderOnce, SharedString,
StatefulInteractiveElement as _, Styled, WindowContext,
Hsla, InteractiveElement, IntoElement, MouseButton, ParentElement, Pixels, RenderOnce,
SharedString, StatefulInteractiveElement as _, Styled, WindowContext,
};
pub enum ButtonRounded {
@ -15,6 +15,13 @@ pub enum ButtonRounded {
Small,
Medium,
Large,
Size(Pixels),
}
impl From<Pixels> for ButtonRounded {
fn from(px: Pixels) -> Self {
ButtonRounded::Size(px)
}
}
#[derive(Clone, Copy)]
@ -100,8 +107,8 @@ impl Button {
self
}
pub fn rounded(mut self, rounded: ButtonRounded) -> Self {
self.rounded = rounded;
pub fn rounded(mut self, rounded: impl Into<ButtonRounded>) -> Self {
self.rounded = rounded.into();
self
}
@ -180,6 +187,7 @@ impl RenderOnce for Button {
.when_some(self.height, |this, height| this.h(height))
.map(|this| {
if self.label.is_none() {
// Icon Button
match self.size {
Size::Size(px) => this.size(px),
Size::XSmall => this.size_5(),
@ -187,6 +195,7 @@ impl RenderOnce for Button {
Size::Large | Size::Medium => this.size_8(),
}
} else {
// Normal Button
match self.size {
Size::XSmall => this.px_1().py_1().h_5(),
Size::Small => this.px_3().py_2().h_6(),
@ -198,6 +207,7 @@ impl RenderOnce for Button {
ButtonRounded::Small => this.rounded(px(cx.theme().radius * 0.5)),
ButtonRounded::Medium => this.rounded(px(cx.theme().radius)),
ButtonRounded::Large => this.rounded(px(cx.theme().radius * 2.0)),
ButtonRounded::Size(px) => this.rounded(px),
ButtonRounded::None => this.rounded_none(),
})
.when(self.selected, |this| {

View file

@ -508,6 +508,10 @@ impl ViewInputHandler for TextInput {
new_text: &str,
cx: &mut ViewContext<Self>,
) {
if self.disabled {
return;
}
let range = range_utf16
.as_ref()
.map(|range_utf16| self.range_from_utf16(range_utf16))
@ -531,6 +535,10 @@ impl ViewInputHandler for TextInput {
new_selected_range_utf16: Option<Range<usize>>,
cx: &mut ViewContext<Self>,
) {
if self.disabled {
return;
}
let range = range_utf16
.as_ref()
.map(|range_utf16| self.range_from_utf16(range_utf16))
@ -864,7 +872,7 @@ impl Render for TextInput {
Button::new("clean-text", cx)
.icon(IconName::Close)
.style(ButtonStyle::Ghost)
.size(px(14.))
.size(px(15.))
.cursor_pointer()
.on_click(cx.listener(Self::clean)),
)

View file

@ -81,6 +81,7 @@ where
.appearance(false)
.prefix(Icon::new(IconName::Search).view(cx))
.placeholder("Search...")
.cleanable(true)
});
cx.subscribe(&query_input, Self::on_query_input_event)