Extra rows approach draft

co-authored-by: Max <max@zed.dev>
This commit is contained in:
Kirill Bulatov 2023-05-09 13:55:18 +03:00 committed by Kirill Bulatov
parent b5abac6af6
commit 13296d502c
4 changed files with 136 additions and 90 deletions

View file

@ -451,11 +451,12 @@ impl ProjectSearchView {
.detach(); .detach();
let included_files_editor = cx.add_view(|cx| { let included_files_editor = cx.add_view(|cx| {
let editor = Editor::single_line( Editor::single_line(
Some(Arc::new(|theme| theme.search.editor.input.clone())), Some(Arc::new(|theme| {
theme.search.include_exclude_editor.input.clone()
})),
cx, cx,
); )
editor
}); });
// Subcribe to include_files_editor in order to reraise editor events for workspace item activation purposes // Subcribe to include_files_editor in order to reraise editor events for workspace item activation purposes
cx.subscribe(&included_files_editor, |_, _, event, cx| { cx.subscribe(&included_files_editor, |_, _, event, cx| {
@ -464,11 +465,12 @@ impl ProjectSearchView {
.detach(); .detach();
let excluded_files_editor = cx.add_view(|cx| { let excluded_files_editor = cx.add_view(|cx| {
let editor = Editor::single_line( Editor::single_line(
Some(Arc::new(|theme| theme.search.editor.input.clone())), Some(Arc::new(|theme| {
theme.search.include_exclude_editor.input.clone()
})),
cx, cx,
); )
editor
}); });
// Subcribe to excluded_files_editor in order to reraise editor events for workspace item activation purposes // Subcribe to excluded_files_editor in order to reraise editor events for workspace item activation purposes
cx.subscribe(&excluded_files_editor, |_, _, event, cx| { cx.subscribe(&excluded_files_editor, |_, _, event, cx| {
@ -935,12 +937,16 @@ impl View for ProjectSearchBar {
let included_files_view = ChildView::new(&search.included_files_editor, cx) let included_files_view = ChildView::new(&search.included_files_editor, cx)
.aligned() .aligned()
.left() .left()
.flex(0.5, true); .flex(1.0, true);
let excluded_files_view = ChildView::new(&search.excluded_files_editor, cx) let excluded_files_view = ChildView::new(&search.excluded_files_editor, cx)
.aligned() .aligned()
.right() .right()
.flex(0.5, true); .flex(1.0, true);
let row_spacing = theme.workspace.toolbar.container.padding.bottom;
Flex::column()
.with_child(
Flex::row() Flex::row()
.with_child( .with_child(
Flex::row() Flex::row()
@ -984,12 +990,25 @@ impl View for ProjectSearchBar {
SearchOption::CaseSensitive, SearchOption::CaseSensitive,
cx, cx,
)) ))
.with_child(self.render_option_button("Word", SearchOption::WholeWord, cx)) .with_child(self.render_option_button(
.with_child(self.render_option_button("Regex", SearchOption::Regex, cx)) "Word",
SearchOption::WholeWord,
cx,
))
.with_child(self.render_option_button(
"Regex",
SearchOption::Regex,
cx,
))
.contained() .contained()
.with_style(theme.search.option_button_group) .with_style(theme.search.option_button_group)
.aligned(), .aligned(),
) )
.contained()
.with_margin_bottom(row_spacing),
)
.with_child(
Flex::row()
// TODO kb better layout // TODO kb better layout
.with_child( .with_child(
Flex::row() Flex::row()
@ -1004,11 +1023,11 @@ impl View for ProjectSearchBar {
) )
.with_child(included_files_view) .with_child(included_files_view)
.contained() .contained()
.with_style(theme.search.editor.input.container) .with_style(theme.search.include_exclude_editor.input.container)
.aligned() .aligned()
.constrained() .constrained()
.with_min_width(theme.search.editor.min_width) .with_min_width(theme.search.include_exclude_editor.min_width)
.with_max_width(theme.search.editor.max_width) .with_max_width(theme.search.include_exclude_editor.max_width)
.flex(1., false), .flex(1., false),
) )
.with_child( .with_child(
@ -1024,12 +1043,13 @@ impl View for ProjectSearchBar {
) )
.with_child(excluded_files_view) .with_child(excluded_files_view)
.contained() .contained()
.with_style(theme.search.editor.input.container) .with_style(theme.search.include_exclude_editor.input.container)
.aligned() .aligned()
.constrained() .constrained()
.with_min_width(theme.search.editor.min_width) .with_min_width(theme.search.include_exclude_editor.min_width)
.with_max_width(theme.search.editor.max_width) .with_max_width(theme.search.include_exclude_editor.max_width)
.flex(1., false), .flex(1., false),
),
) )
.contained() .contained()
.with_style(theme.search.container) .with_style(theme.search.container)
@ -1061,6 +1081,10 @@ impl ToolbarItemView for ProjectSearchBar {
ToolbarItemLocation::Hidden ToolbarItemLocation::Hidden
} }
} }
fn row_count(&self) -> usize {
2
}
} }
#[cfg(test)] #[cfg(test)]

View file

@ -319,6 +319,7 @@ pub struct Search {
pub editor: FindEditor, pub editor: FindEditor,
pub invalid_editor: ContainerStyle, pub invalid_editor: ContainerStyle,
pub option_button_group: ContainerStyle, pub option_button_group: ContainerStyle,
pub include_exclude_editor: FindEditor,
pub include_exclude_inputs: ContainedText, pub include_exclude_inputs: ContainedText,
pub option_button: Interactive<ContainedText>, pub option_button: Interactive<ContainedText>,
pub match_background: Color, pub match_background: Color,

View file

@ -22,6 +22,10 @@ pub trait ToolbarItemView: View {
} }
fn pane_focus_update(&mut self, _pane_focused: bool, _cx: &mut ViewContext<Self>) {} fn pane_focus_update(&mut self, _pane_focused: bool, _cx: &mut ViewContext<Self>) {}
fn row_count(&self) -> usize {
1
}
} }
trait ToolbarItemViewHandle { trait ToolbarItemViewHandle {
@ -33,6 +37,7 @@ trait ToolbarItemViewHandle {
cx: &mut WindowContext, cx: &mut WindowContext,
) -> ToolbarItemLocation; ) -> ToolbarItemLocation;
fn pane_focus_update(&mut self, pane_focused: bool, cx: &mut WindowContext); fn pane_focus_update(&mut self, pane_focused: bool, cx: &mut WindowContext);
fn row_count(&self, cx: &WindowContext) -> usize;
} }
#[derive(Copy, Clone, Debug, PartialEq)] #[derive(Copy, Clone, Debug, PartialEq)]
@ -66,12 +71,14 @@ impl View for Toolbar {
let mut primary_right_items = Vec::new(); let mut primary_right_items = Vec::new();
let mut secondary_item = None; let mut secondary_item = None;
let spacing = theme.item_spacing; let spacing = theme.item_spacing;
let mut primary_items_row_count = 1;
for (item, position) in &self.items { for (item, position) in &self.items {
match *position { match *position {
ToolbarItemLocation::Hidden => {} ToolbarItemLocation::Hidden => {}
ToolbarItemLocation::PrimaryLeft { flex } => { ToolbarItemLocation::PrimaryLeft { flex } => {
primary_items_row_count = primary_items_row_count.max(item.row_count(cx));
let left_item = ChildView::new(item.as_any(), cx) let left_item = ChildView::new(item.as_any(), cx)
.aligned() .aligned()
.contained() .contained()
@ -84,6 +91,7 @@ impl View for Toolbar {
} }
ToolbarItemLocation::PrimaryRight { flex } => { ToolbarItemLocation::PrimaryRight { flex } => {
primary_items_row_count = primary_items_row_count.max(item.row_count(cx));
let right_item = ChildView::new(item.as_any(), cx) let right_item = ChildView::new(item.as_any(), cx)
.aligned() .aligned()
.contained() .contained()
@ -100,7 +108,7 @@ impl View for Toolbar {
secondary_item = Some( secondary_item = Some(
ChildView::new(item.as_any(), cx) ChildView::new(item.as_any(), cx)
.constrained() .constrained()
.with_height(theme.height) .with_height(theme.height * item.row_count(cx) as f32)
.into_any(), .into_any(),
); );
} }
@ -117,7 +125,7 @@ impl View for Toolbar {
} }
let container_style = theme.container; let container_style = theme.container;
let height = theme.height; let height = theme.height * primary_items_row_count as f32;
let button_style = theme.nav_button; let button_style = theme.nav_button;
let tooltip_style = cx.global::<Settings>().theme.tooltip.clone(); let tooltip_style = cx.global::<Settings>().theme.tooltip.clone();
@ -338,6 +346,10 @@ impl<T: ToolbarItemView> ToolbarItemViewHandle for ViewHandle<T> {
cx.notify(); cx.notify();
}); });
} }
fn row_count(&self, cx: &WindowContext) -> usize {
self.read(cx).row_count()
}
} }
impl From<&dyn ToolbarItemViewHandle> for AnyViewHandle { impl From<&dyn ToolbarItemViewHandle> for AnyViewHandle {

View file

@ -64,9 +64,16 @@ export default function search(colorScheme: ColorScheme) {
...editor, ...editor,
border: border(layer, "negative"), border: border(layer, "negative"),
}, },
includeExcludeEditor: {
...editor,
minWidth: 100,
maxWidth: 250,
},
matchIndex: { matchIndex: {
...text(layer, "mono", "variant"), ...text(layer, "mono", "variant"),
padding: 6, padding: {
left: 6,
},
}, },
optionButtonGroup: { optionButtonGroup: {
padding: { padding: {
@ -76,7 +83,9 @@ export default function search(colorScheme: ColorScheme) {
}, },
includeExcludeInputs: { includeExcludeInputs: {
...text(layer, "mono", "variant"), ...text(layer, "mono", "variant"),
padding: 6, padding: {
right: 6,
},
}, },
resultsStatus: { resultsStatus: {
...text(layer, "mono", "on"), ...text(layer, "mono", "on"),