diff --git a/crates/story/src/dropdown_story.rs b/crates/story/src/dropdown_story.rs index cd79c67e..55c64cc0 100644 --- a/crates/story/src/dropdown_story.rs +++ b/crates/story/src/dropdown_story.rs @@ -50,7 +50,7 @@ pub struct DropdownStory { country_dropdown: View>>, fruit_dropdown: View>>, simple_dropdown1: View>>, - simple_dropdown2: View>>, + simple_dropdown2: View>>, simple_dropdown3: View>>, disabled_dropdown: View>>, } @@ -131,12 +131,12 @@ impl DropdownStory { simple_dropdown2: cx.new_view(|cx| { Dropdown::new( "string-list2", - vec![ + SearchableVec::new(vec![ "Rust".into(), "Go".into(), "C++".into(), "JavaScript".into(), - ], + ]), None, cx, ) diff --git a/crates/ui/src/button.rs b/crates/ui/src/button.rs index ac7ac502..b75acc5e 100644 --- a/crates/ui/src/button.rs +++ b/crates/ui/src/button.rs @@ -3,7 +3,7 @@ use crate::{ indicator::Indicator, theme::{ActiveTheme, Colorize as _}, tooltip::Tooltip, - Disableable, Icon, Selectable, Sizable, Size, StyledExt, + Disableable, Icon, Selectable, Sizable, Size, }; use gpui::{ div, prelude::FluentBuilder as _, px, relative, AnyElement, ClickEvent, Corners, Div, Edges, diff --git a/crates/ui/src/dropdown.rs b/crates/ui/src/dropdown.rs index 266754b6..576bd387 100644 --- a/crates/ui/src/dropdown.rs +++ b/crates/ui/src/dropdown.rs @@ -568,6 +568,12 @@ where let allow_open = !(self.open || self.disabled); let outline_visible = is_focused && !self.disabled; + // If the size has change, set size to self.list, to change the QueryInput size. + if self.list.read(cx).size != self.size { + self.list + .update(cx, |this, cx| this.set_size(self.size, cx)) + } + div() .id(self.id.clone()) .key_context(CONTEXT) diff --git a/crates/ui/src/input/input.rs b/crates/ui/src/input/input.rs index 7ab18079..b688ff65 100644 --- a/crates/ui/src/input/input.rs +++ b/crates/ui/src/input/input.rs @@ -235,6 +235,12 @@ impl TextInput { cx.notify(); } + /// Set the Input size + pub fn set_size(&mut self, size: Size, cx: &mut ViewContext) { + self.size = size; + cx.notify(); + } + /// Set the appearance of the input field. pub fn appearance(mut self, appearance: bool) -> Self { self.appearance = appearance; diff --git a/crates/ui/src/list/list.rs b/crates/ui/src/list/list.rs index 745839e2..3006e893 100644 --- a/crates/ui/src/list/list.rs +++ b/crates/ui/src/list/list.rs @@ -4,8 +4,8 @@ use std::{cell::Cell, rc::Rc}; use crate::input::{InputEvent, TextInput}; use crate::scroll::ScrollbarState; use crate::theme::ActiveTheme; -use crate::IconName; use crate::{scroll::Scrollbar, v_flex}; +use crate::{IconName, Size}; use gpui::{ actions, div, prelude::FluentBuilder, uniform_list, AppContext, FocusHandle, FocusableView, InteractiveElement, IntoElement, KeyBinding, Length, ListSizingBehavior, MouseButton, @@ -77,6 +77,7 @@ pub struct List { vertical_scroll_handle: UniformListScrollHandle, scrollbar_state: Rc>, + pub(crate) size: Size, selected_index: Option, _search_task: Task<()>, } @@ -108,10 +109,21 @@ where max_height: None, enable_scrollbar: true, loading: false, + size: Size::default(), _search_task: Task::Ready(None), } } + /// Set the size + pub fn set_size(&mut self, size: Size, cx: &mut ViewContext) { + if let Some(input) = &self.query_input { + input.update(cx, |input, cx| { + input.set_size(size, cx); + }) + } + self.size = size; + } + pub fn max_h(mut self, height: impl Into) -> Self { self.max_height = Some(height.into()); self @@ -127,6 +139,12 @@ where self } + pub fn set_query_input(&mut self, query_input: View, cx: &mut ViewContext) { + cx.subscribe(&query_input, Self::on_query_input_event) + .detach(); + self.query_input = Some(query_input); + } + pub fn delegate(&self) -> &D { &self.delegate } @@ -318,8 +336,10 @@ where .when_some(self.query_input.clone(), |this, input| { this.child( div() - .py_1() - .px_2() + .map(|this| match self.size { + Size::Small => this.py_0().px_1p5(), + _ => this.py_1().px_2(), + }) .border_b_1() .border_color(cx.theme().border) .child(input),