mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-12 21:32:40 +00:00
Unify Flexible and Expanded elements
We'll use the name Expanded for something else now. Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
b19d92e918
commit
1f762e482d
11 changed files with 58 additions and 145 deletions
|
@ -233,7 +233,7 @@ impl ChatPanel {
|
||||||
Empty::new().boxed()
|
Empty::new().boxed()
|
||||||
};
|
};
|
||||||
|
|
||||||
Expanded::new(1., messages).boxed()
|
Flexible::new(1., true, messages).boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_message(&self, message: &ChannelMessage) -> ElementBox {
|
fn render_message(&self, message: &ChannelMessage) -> ElementBox {
|
||||||
|
|
|
@ -214,7 +214,7 @@ impl ContactsPanel {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.expanded(1.0)
|
.flexible(1., true)
|
||||||
.boxed()
|
.boxed()
|
||||||
})
|
})
|
||||||
.constrained()
|
.constrained()
|
||||||
|
|
|
@ -83,7 +83,7 @@ impl View for FileFinder {
|
||||||
.with_style(settings.theme.selector.input_editor.container)
|
.with_style(settings.theme.selector.input_editor.container)
|
||||||
.boxed(),
|
.boxed(),
|
||||||
)
|
)
|
||||||
.with_child(Flexible::new(1.0, self.render_matches()).boxed())
|
.with_child(Flexible::new(1.0, false, self.render_matches()).boxed())
|
||||||
.boxed(),
|
.boxed(),
|
||||||
)
|
)
|
||||||
.with_style(settings.theme.selector.container)
|
.with_style(settings.theme.selector.container)
|
||||||
|
@ -175,6 +175,7 @@ impl FileFinder {
|
||||||
.with_child(
|
.with_child(
|
||||||
Flexible::new(
|
Flexible::new(
|
||||||
1.0,
|
1.0,
|
||||||
|
false,
|
||||||
Flex::column()
|
Flex::column()
|
||||||
.with_child(
|
.with_child(
|
||||||
Label::new(file_name.to_string(), style.label.clone())
|
Label::new(file_name.to_string(), style.label.clone())
|
||||||
|
|
|
@ -130,11 +130,11 @@ pub trait Element {
|
||||||
Container::new(self.boxed())
|
Container::new(self.boxed())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expanded(self, flex: f32) -> Expanded
|
fn flexible(self, flex: f32, expanded: bool) -> Flexible
|
||||||
where
|
where
|
||||||
Self: 'static + Sized,
|
Self: 'static + Sized,
|
||||||
{
|
{
|
||||||
Expanded::new(flex, self.boxed())
|
Flexible::new(flex, expanded, self.boxed())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -228,88 +228,15 @@ struct FlexParentData {
|
||||||
expanded: bool,
|
expanded: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Expanded {
|
|
||||||
metadata: FlexParentData,
|
|
||||||
child: ElementBox,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Expanded {
|
|
||||||
pub fn new(flex: f32, child: ElementBox) -> Self {
|
|
||||||
Expanded {
|
|
||||||
metadata: FlexParentData {
|
|
||||||
flex,
|
|
||||||
expanded: true,
|
|
||||||
},
|
|
||||||
child,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Element for Expanded {
|
|
||||||
type LayoutState = ();
|
|
||||||
type PaintState = ();
|
|
||||||
|
|
||||||
fn layout(
|
|
||||||
&mut self,
|
|
||||||
constraint: SizeConstraint,
|
|
||||||
cx: &mut LayoutContext,
|
|
||||||
) -> (Vector2F, Self::LayoutState) {
|
|
||||||
let size = self.child.layout(constraint, cx);
|
|
||||||
(size, ())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn paint(
|
|
||||||
&mut self,
|
|
||||||
bounds: RectF,
|
|
||||||
visible_bounds: RectF,
|
|
||||||
_: &mut Self::LayoutState,
|
|
||||||
cx: &mut PaintContext,
|
|
||||||
) -> Self::PaintState {
|
|
||||||
self.child.paint(bounds.origin(), visible_bounds, cx)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn dispatch_event(
|
|
||||||
&mut self,
|
|
||||||
event: &Event,
|
|
||||||
_: RectF,
|
|
||||||
_: &mut Self::LayoutState,
|
|
||||||
_: &mut Self::PaintState,
|
|
||||||
cx: &mut EventContext,
|
|
||||||
) -> bool {
|
|
||||||
self.child.dispatch_event(event, cx)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn metadata(&self) -> Option<&dyn Any> {
|
|
||||||
Some(&self.metadata)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn debug(
|
|
||||||
&self,
|
|
||||||
_: RectF,
|
|
||||||
_: &Self::LayoutState,
|
|
||||||
_: &Self::PaintState,
|
|
||||||
cx: &DebugContext,
|
|
||||||
) -> Value {
|
|
||||||
json!({
|
|
||||||
"type": "Expanded",
|
|
||||||
"flex": self.metadata.flex,
|
|
||||||
"child": self.child.debug(cx)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Flexible {
|
pub struct Flexible {
|
||||||
metadata: FlexParentData,
|
metadata: FlexParentData,
|
||||||
child: ElementBox,
|
child: ElementBox,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Flexible {
|
impl Flexible {
|
||||||
pub fn new(flex: f32, child: ElementBox) -> Self {
|
pub fn new(flex: f32, expanded: bool, child: ElementBox) -> Self {
|
||||||
Flexible {
|
Flexible {
|
||||||
metadata: FlexParentData {
|
metadata: FlexParentData { flex, expanded },
|
||||||
flex,
|
|
||||||
expanded: false,
|
|
||||||
},
|
|
||||||
child,
|
child,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -293,7 +293,7 @@ impl View for ThemeSelector {
|
||||||
Container::new(
|
Container::new(
|
||||||
Flex::new(Axis::Vertical)
|
Flex::new(Axis::Vertical)
|
||||||
.with_child(ChildView::new(self.query_editor.id()).boxed())
|
.with_child(ChildView::new(self.query_editor.id()).boxed())
|
||||||
.with_child(Flexible::new(1.0, self.render_matches(cx)).boxed())
|
.with_child(Flexible::new(1.0, false, self.render_matches(cx)).boxed())
|
||||||
.boxed(),
|
.boxed(),
|
||||||
)
|
)
|
||||||
.with_style(settings.theme.selector.container)
|
.with_style(settings.theme.selector.container)
|
||||||
|
|
|
@ -314,13 +314,11 @@ impl Pane {
|
||||||
}
|
}
|
||||||
|
|
||||||
row.add_child(
|
row.add_child(
|
||||||
Expanded::new(
|
Empty::new()
|
||||||
0.0,
|
.contained()
|
||||||
Container::new(Empty::new().boxed())
|
.with_border(theme.workspace.tab.container.border)
|
||||||
.with_border(theme.workspace.tab.container.border)
|
.flexible(0., true)
|
||||||
.boxed(),
|
.named("filler"),
|
||||||
)
|
|
||||||
.named("filler"),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
row.boxed()
|
row.boxed()
|
||||||
|
@ -345,7 +343,7 @@ impl View for Pane {
|
||||||
if let Some(active_item) = self.active_item() {
|
if let Some(active_item) = self.active_item() {
|
||||||
Flex::column()
|
Flex::column()
|
||||||
.with_child(self.render_tabs(cx))
|
.with_child(self.render_tabs(cx))
|
||||||
.with_child(Expanded::new(1.0, ChildView::new(active_item.id()).boxed()).boxed())
|
.with_child(ChildView::new(active_item.id()).flexible(1., true).boxed())
|
||||||
.named("pane")
|
.named("pane")
|
||||||
} else {
|
} else {
|
||||||
Empty::new().named("pane")
|
Empty::new().named("pane")
|
||||||
|
|
|
@ -183,7 +183,7 @@ impl PaneAxis {
|
||||||
member = Container::new(member).with_border(border).boxed();
|
member = Container::new(member).with_border(border).boxed();
|
||||||
}
|
}
|
||||||
|
|
||||||
Expanded::new(1.0, member).boxed()
|
Flexible::new(1.0, true, member).boxed()
|
||||||
}))
|
}))
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,19 +135,16 @@ impl Sidebar {
|
||||||
}
|
}
|
||||||
|
|
||||||
container.add_child(
|
container.add_child(
|
||||||
Flexible::new(
|
Hook::new(
|
||||||
1.,
|
ConstrainedBox::new(ChildView::new(active_item.id()).boxed())
|
||||||
Hook::new(
|
.with_max_width(*self.width.borrow())
|
||||||
ConstrainedBox::new(ChildView::new(active_item.id()).boxed())
|
.boxed(),
|
||||||
.with_max_width(*self.width.borrow())
|
|
||||||
.boxed(),
|
|
||||||
)
|
|
||||||
.on_after_layout({
|
|
||||||
let width = self.width.clone();
|
|
||||||
move |size, _| *width.borrow_mut() = size.x()
|
|
||||||
})
|
|
||||||
.boxed(),
|
|
||||||
)
|
)
|
||||||
|
.on_after_layout({
|
||||||
|
let width = self.width.clone();
|
||||||
|
move |size, _| *width.borrow_mut() = size.x()
|
||||||
|
})
|
||||||
|
.flexible(1., false)
|
||||||
.boxed(),
|
.boxed(),
|
||||||
);
|
);
|
||||||
if matches!(self.side, Side::Left) {
|
if matches!(self.side, Side::Left) {
|
||||||
|
|
|
@ -47,7 +47,7 @@ impl View for StatusBar {
|
||||||
.iter()
|
.iter()
|
||||||
.map(|i| ChildView::new(i.id()).aligned().boxed()),
|
.map(|i| ChildView::new(i.id()).aligned().boxed()),
|
||||||
)
|
)
|
||||||
.with_child(Empty::new().expanded(1.).boxed())
|
.with_child(Empty::new().flexible(1., true).boxed())
|
||||||
.with_children(
|
.with_children(
|
||||||
self.right_items
|
self.right_items
|
||||||
.iter()
|
.iter()
|
||||||
|
|
|
@ -1191,50 +1191,40 @@ impl View for Workspace {
|
||||||
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
|
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
|
||||||
let settings = self.settings.borrow();
|
let settings = self.settings.borrow();
|
||||||
let theme = &settings.theme;
|
let theme = &settings.theme;
|
||||||
Container::new(
|
Flex::column()
|
||||||
Flex::column()
|
.with_child(self.render_titlebar(&theme, cx))
|
||||||
.with_child(self.render_titlebar(&theme, cx))
|
.with_child(
|
||||||
.with_child(
|
Stack::new()
|
||||||
Expanded::new(
|
.with_child({
|
||||||
1.0,
|
let mut content = Flex::row();
|
||||||
Stack::new()
|
content.add_child(self.left_sidebar.render(&settings, cx));
|
||||||
.with_child({
|
if let Some(element) = self.left_sidebar.render_active_item(&settings, cx) {
|
||||||
let mut content = Flex::row();
|
content.add_child(Flexible::new(0.8, false, element).boxed());
|
||||||
content.add_child(self.left_sidebar.render(&settings, cx));
|
}
|
||||||
if let Some(element) =
|
content.add_child(
|
||||||
self.left_sidebar.render_active_item(&settings, cx)
|
Flex::column()
|
||||||
{
|
.with_child(
|
||||||
content.add_child(Flexible::new(0.8, element).boxed());
|
Flexible::new(1., true, self.center.render(&settings.theme))
|
||||||
}
|
|
||||||
content.add_child(
|
|
||||||
Flex::column()
|
|
||||||
.with_child(
|
|
||||||
Expanded::new(1.0, self.center.render(&settings.theme))
|
|
||||||
.boxed(),
|
|
||||||
)
|
|
||||||
.with_child(ChildView::new(self.status_bar.id()).boxed())
|
|
||||||
.expanded(1.)
|
|
||||||
.boxed(),
|
.boxed(),
|
||||||
);
|
)
|
||||||
if let Some(element) =
|
.with_child(ChildView::new(self.status_bar.id()).boxed())
|
||||||
self.right_sidebar.render_active_item(&settings, cx)
|
.flexible(1., true)
|
||||||
{
|
.boxed(),
|
||||||
content.add_child(Flexible::new(0.8, element).boxed());
|
);
|
||||||
}
|
if let Some(element) = self.right_sidebar.render_active_item(&settings, cx)
|
||||||
content.add_child(self.right_sidebar.render(&settings, cx));
|
{
|
||||||
content.boxed()
|
content.add_child(Flexible::new(0.8, false, element).boxed());
|
||||||
})
|
}
|
||||||
.with_children(
|
content.add_child(self.right_sidebar.render(&settings, cx));
|
||||||
self.modal.as_ref().map(|m| ChildView::new(m.id()).boxed()),
|
content.boxed()
|
||||||
)
|
})
|
||||||
.boxed(),
|
.with_children(self.modal.as_ref().map(|m| ChildView::new(m.id()).boxed()))
|
||||||
)
|
.flexible(1.0, true)
|
||||||
.boxed(),
|
.boxed(),
|
||||||
)
|
)
|
||||||
.boxed(),
|
.contained()
|
||||||
)
|
.with_background_color(settings.theme.workspace.background)
|
||||||
.with_background_color(settings.theme.workspace.background)
|
.named("workspace")
|
||||||
.named("workspace")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_focus(&mut self, cx: &mut ViewContext<Self>) {
|
fn on_focus(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
|
|
Loading…
Reference in a new issue