From 36411750ee3289f5178377601d3d1d6e09dd795b Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Wed, 17 Jul 2024 10:47:25 +0800 Subject: [PATCH] Fix to limit change when Input is disabled. Add clean button to List query input. Add ButtonRouneded with px support. --- crates/ui/src/button.rs | 18 ++++++++++++++---- crates/ui/src/input.rs | 10 +++++++++- crates/ui/src/list/list.rs | 1 + 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/crates/ui/src/button.rs b/crates/ui/src/button.rs index f3b35422..dd0c7c2c 100644 --- a/crates/ui/src/button.rs +++ b/crates/ui/src/button.rs @@ -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 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) -> 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| { diff --git a/crates/ui/src/input.rs b/crates/ui/src/input.rs index 5a691242..4f31b97d 100644 --- a/crates/ui/src/input.rs +++ b/crates/ui/src/input.rs @@ -508,6 +508,10 @@ impl ViewInputHandler for TextInput { new_text: &str, cx: &mut ViewContext, ) { + 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>, cx: &mut ViewContext, ) { + 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)), ) diff --git a/crates/ui/src/list/list.rs b/crates/ui/src/list/list.rs index 5000569d..77b79d9e 100644 --- a/crates/ui/src/list/list.rs +++ b/crates/ui/src/list/list.rs @@ -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)