mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-08 07:35:01 +03:00
Let toolbar items specify flex
when they have a primary location
This commit is contained in:
parent
6d4c748d82
commit
cd5389b4d8
@ -117,7 +117,7 @@ impl ToolbarItemView for Breadcrumbs {
|
|||||||
ToolbarItemLocation::Hidden
|
ToolbarItemLocation::Hidden
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ToolbarItemLocation::PrimaryLeft
|
ToolbarItemLocation::PrimaryLeft { flex: None }
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ToolbarItemLocation::Hidden
|
ToolbarItemLocation::Hidden
|
||||||
|
@ -769,7 +769,9 @@ impl ToolbarItemView for ProjectSearchBar {
|
|||||||
if let Some(search) = active_pane_item.and_then(|i| i.downcast::<ProjectSearchView>()) {
|
if let Some(search) = active_pane_item.and_then(|i| i.downcast::<ProjectSearchView>()) {
|
||||||
self.subscription = Some(cx.observe(&search, |_, _, cx| cx.notify()));
|
self.subscription = Some(cx.observe(&search, |_, _, cx| cx.notify()));
|
||||||
self.active_project_search = Some(search);
|
self.active_project_search = Some(search);
|
||||||
ToolbarItemLocation::PrimaryLeft
|
ToolbarItemLocation::PrimaryLeft {
|
||||||
|
flex: Some((1., false)),
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ToolbarItemLocation::Hidden
|
ToolbarItemLocation::Hidden
|
||||||
}
|
}
|
||||||
|
@ -31,11 +31,11 @@ trait ToolbarItemViewHandle {
|
|||||||
) -> ToolbarItemLocation;
|
) -> ToolbarItemLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||||
pub enum ToolbarItemLocation {
|
pub enum ToolbarItemLocation {
|
||||||
Hidden,
|
Hidden,
|
||||||
PrimaryLeft,
|
PrimaryLeft { flex: Option<(f32, bool)> },
|
||||||
PrimaryRight,
|
PrimaryRight { flex: Option<(f32, bool)> },
|
||||||
Secondary,
|
Secondary,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,44 +61,52 @@ impl View for Toolbar {
|
|||||||
let mut secondary_item = None;
|
let mut secondary_item = None;
|
||||||
|
|
||||||
for (item, position) in &self.items {
|
for (item, position) in &self.items {
|
||||||
match position {
|
match *position {
|
||||||
ToolbarItemLocation::Hidden => {}
|
ToolbarItemLocation::Hidden => {}
|
||||||
ToolbarItemLocation::PrimaryLeft => primary_left_items.push(item),
|
ToolbarItemLocation::PrimaryLeft { flex } => {
|
||||||
ToolbarItemLocation::PrimaryRight => primary_right_items.push(item),
|
let left_item = ChildView::new(item.as_ref())
|
||||||
ToolbarItemLocation::Secondary => secondary_item = Some(item),
|
.aligned()
|
||||||
|
.contained()
|
||||||
|
.with_margin_right(theme.item_spacing);
|
||||||
|
if let Some((flex, expanded)) = flex {
|
||||||
|
primary_left_items.push(left_item.flex(flex, expanded).boxed());
|
||||||
|
} else {
|
||||||
|
primary_left_items.push(left_item.boxed());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ToolbarItemLocation::PrimaryRight { flex } => {
|
||||||
|
let right_item = ChildView::new(item.as_ref())
|
||||||
|
.aligned()
|
||||||
|
.contained()
|
||||||
|
.with_margin_left(theme.item_spacing)
|
||||||
|
.flex_float();
|
||||||
|
if let Some((flex, expanded)) = flex {
|
||||||
|
primary_right_items.push(right_item.flex(flex, expanded).boxed());
|
||||||
|
} else {
|
||||||
|
primary_right_items.push(right_item.boxed());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ToolbarItemLocation::Secondary => {
|
||||||
|
secondary_item = Some(
|
||||||
|
ChildView::new(item.as_ref())
|
||||||
|
.constrained()
|
||||||
|
.with_height(theme.height)
|
||||||
|
.boxed(),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Flex::column()
|
Flex::column()
|
||||||
.with_child(
|
.with_child(
|
||||||
Flex::row()
|
Flex::row()
|
||||||
.with_children(primary_left_items.iter().map(|i| {
|
.with_children(primary_left_items)
|
||||||
ChildView::new(i.as_ref())
|
.with_children(primary_right_items)
|
||||||
.aligned()
|
|
||||||
.contained()
|
|
||||||
.with_margin_right(theme.item_spacing)
|
|
||||||
.flex(1., false)
|
|
||||||
.boxed()
|
|
||||||
}))
|
|
||||||
.with_children(primary_right_items.iter().map(|i| {
|
|
||||||
ChildView::new(i.as_ref())
|
|
||||||
.aligned()
|
|
||||||
.contained()
|
|
||||||
.with_margin_left(theme.item_spacing)
|
|
||||||
.flex_float()
|
|
||||||
.flex(1., false)
|
|
||||||
.boxed()
|
|
||||||
}))
|
|
||||||
.constrained()
|
.constrained()
|
||||||
.with_height(theme.height)
|
.with_height(theme.height)
|
||||||
.boxed(),
|
.boxed(),
|
||||||
)
|
)
|
||||||
.with_children(secondary_item.map(|item| {
|
.with_children(secondary_item)
|
||||||
ChildView::new(item.as_ref())
|
|
||||||
.constrained()
|
|
||||||
.with_height(theme.height)
|
|
||||||
.boxed()
|
|
||||||
}))
|
|
||||||
.contained()
|
.contained()
|
||||||
.with_style(theme.container)
|
.with_style(theme.container)
|
||||||
.boxed()
|
.boxed()
|
||||||
|
Loading…
Reference in New Issue
Block a user