Unbreak toolbar layout & improve disabling ButtonLike
This commit is contained in:
parent
d516ae0d8a
commit
ce16e5b54a
3 changed files with 30 additions and 34 deletions
|
@ -1,10 +1,11 @@
|
||||||
use gpui::{
|
use gpui::{
|
||||||
Div, Element, EventEmitter, InteractiveElement, IntoElement, ParentElement, Render, Stateful,
|
AnyElement, Component, Div, Element, EventEmitter, InteractiveElement, IntoElement,
|
||||||
StatefulInteractiveElement, Styled, StyledText, Subscription, ViewContext, WeakView,
|
ParentElement, Render, Stateful, StatefulInteractiveElement, Styled, StyledText, Subscription,
|
||||||
|
ViewContext, WeakView,
|
||||||
};
|
};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use theme::ActiveTheme;
|
use theme::ActiveTheme;
|
||||||
use ui::{h_stack, Label};
|
use ui::{h_stack, ButtonCommon, ButtonLike, ButtonStyle2, Clickable, Disableable, Label};
|
||||||
use workspace::{
|
use workspace::{
|
||||||
item::{ItemEvent, ItemHandle},
|
item::{ItemEvent, ItemHandle},
|
||||||
ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, Workspace,
|
ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, Workspace,
|
||||||
|
@ -36,20 +37,22 @@ impl EventEmitter<Event> for Breadcrumbs {}
|
||||||
impl EventEmitter<ToolbarItemEvent> for Breadcrumbs {}
|
impl EventEmitter<ToolbarItemEvent> for Breadcrumbs {}
|
||||||
|
|
||||||
impl Render for Breadcrumbs {
|
impl Render for Breadcrumbs {
|
||||||
type Element = Stateful<Div>;
|
type Element = Component<ButtonLike>;
|
||||||
|
|
||||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||||
let div = h_stack().id("breadcrumbs").bg(gpui::red());
|
let button = ButtonLike::new("breadcrumbs")
|
||||||
|
.style(ButtonStyle2::Transparent)
|
||||||
|
.disabled(true);
|
||||||
|
|
||||||
let active_item = match &self.active_item {
|
let active_item = match &self.active_item {
|
||||||
Some(active_item) => active_item,
|
Some(active_item) => active_item,
|
||||||
None => return div,
|
None => return button.into_element(),
|
||||||
};
|
};
|
||||||
let not_editor = active_item.downcast::<editor::Editor>().is_none();
|
let not_editor = active_item.downcast::<editor::Editor>().is_none();
|
||||||
|
|
||||||
let breadcrumbs = match active_item.breadcrumbs(cx.theme(), cx) {
|
let breadcrumbs = match active_item.breadcrumbs(cx.theme(), cx) {
|
||||||
Some(breadcrumbs) => breadcrumbs,
|
Some(breadcrumbs) => breadcrumbs,
|
||||||
None => return div,
|
None => return button.into_element(),
|
||||||
}
|
}
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|breadcrumb| {
|
.map(|breadcrumb| {
|
||||||
|
@ -58,26 +61,30 @@ impl Render for Breadcrumbs {
|
||||||
.into_any()
|
.into_any()
|
||||||
});
|
});
|
||||||
|
|
||||||
let crumbs = div.children(Itertools::intersperse_with(breadcrumbs, || {
|
let button = button.children(Itertools::intersperse_with(breadcrumbs, || {
|
||||||
Label::new(" › ").into_any_element()
|
Label::new(" › ").into_any_element()
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if not_editor || !self.pane_focused {
|
if not_editor || !self.pane_focused {
|
||||||
return crumbs;
|
return button.into_element();
|
||||||
}
|
}
|
||||||
|
|
||||||
// let this = cx.view().downgrade();
|
// let this = cx.view().downgrade();
|
||||||
crumbs.on_click(move |_, _cx| {
|
button
|
||||||
todo!("outline::toggle");
|
.style(ButtonStyle2::Filled)
|
||||||
// this.update(cx, |this, cx| {
|
.disabled(false)
|
||||||
// if let Some(workspace) = this.workspace.upgrade() {
|
.on_click(move |_, _cx| {
|
||||||
// workspace.update(cx, |_workspace, _cx| {
|
todo!("outline::toggle");
|
||||||
// outline::toggle(workspace, &Default::default(), cx)
|
// this.update(cx, |this, cx| {
|
||||||
// })
|
// if let Some(workspace) = this.workspace.upgrade() {
|
||||||
// }
|
// workspace.update(cx, |_workspace, _cx| {
|
||||||
// })
|
// outline::toggle(workspace, &Default::default(), cx)
|
||||||
// .ok();
|
// })
|
||||||
})
|
// }
|
||||||
|
// })
|
||||||
|
// .ok();
|
||||||
|
})
|
||||||
|
.into_element()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -250,7 +250,7 @@ impl RenderOnce for ButtonLike {
|
||||||
.id(self.id.clone())
|
.id(self.id.clone())
|
||||||
.h(self.size.height())
|
.h(self.size.height())
|
||||||
.rounded_md()
|
.rounded_md()
|
||||||
.cursor_pointer()
|
.when(!self.disabled, |el| el.cursor_pointer())
|
||||||
.gap_1()
|
.gap_1()
|
||||||
.px_1()
|
.px_1()
|
||||||
.bg(self.style.enabled(cx).background)
|
.bg(self.style.enabled(cx).background)
|
||||||
|
|
|
@ -80,7 +80,6 @@ impl Render for Toolbar {
|
||||||
type Element = Div;
|
type Element = Div;
|
||||||
|
|
||||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||||
//dbg!(&self.items.len());
|
|
||||||
v_stack()
|
v_stack()
|
||||||
.border_b()
|
.border_b()
|
||||||
.border_color(cx.theme().colors().border_variant)
|
.border_color(cx.theme().colors().border_variant)
|
||||||
|
@ -88,17 +87,8 @@ impl Render for Toolbar {
|
||||||
.child(
|
.child(
|
||||||
h_stack()
|
h_stack()
|
||||||
.justify_between()
|
.justify_between()
|
||||||
.child(
|
// Toolbar left side
|
||||||
// Toolbar left side
|
.children(self.items.iter().map(|(child, _)| child.to_any()))
|
||||||
h_stack().border().border_color(gpui::red()).p_1().child(
|
|
||||||
ButtonLike::new("breadcrumb")
|
|
||||||
.child(Label::new("crates/workspace2/src/toolbar.rs"))
|
|
||||||
.child(Label::new("›").color(Color::Muted))
|
|
||||||
.child(Label::new("impl Render for Toolbar"))
|
|
||||||
.child(Label::new("›").color(Color::Muted))
|
|
||||||
.child(Label::new("fn render")),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
// Toolbar right side
|
// Toolbar right side
|
||||||
.child(
|
.child(
|
||||||
h_stack()
|
h_stack()
|
||||||
|
@ -117,7 +107,6 @@ impl Render for Toolbar {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.children(self.items.iter().map(|(child, _)| child.to_any()))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue