forked from reya/gpui-native-kit
feat: apply declarative render rule across components
This commit is contained in:
+25
-24
@@ -1044,30 +1044,31 @@ fn render_pane(
|
||||
|
||||
tabs.iter()
|
||||
.map(|tab| {
|
||||
let mut entry = Tab::new(tab.panel.clone(), tab.title.clone());
|
||||
if let Some(icon) = tab.icon.clone() {
|
||||
entry = entry.lead(icon.size(metrics.icon_size));
|
||||
}
|
||||
entry.closeable(true).wrap({
|
||||
let panel = tab.panel.clone();
|
||||
let title = tab.title.clone();
|
||||
move |tab| {
|
||||
tab.on_drag(
|
||||
PanelDrag {
|
||||
panel: panel.clone(),
|
||||
},
|
||||
{
|
||||
let title = title.clone();
|
||||
move |_, _, _, cx| {
|
||||
cx.new(|_| DragPreview {
|
||||
title: title.clone(),
|
||||
})
|
||||
}
|
||||
},
|
||||
)
|
||||
.into_any_element()
|
||||
}
|
||||
})
|
||||
Tab::new(tab.panel.clone(), tab.title.clone())
|
||||
.when_some(tab.icon.clone(), |entry, icon| {
|
||||
entry.lead(icon.size(metrics.icon_size))
|
||||
})
|
||||
.closeable(true)
|
||||
.wrap({
|
||||
let panel = tab.panel.clone();
|
||||
let title = tab.title.clone();
|
||||
move |tab| {
|
||||
tab.on_drag(
|
||||
PanelDrag {
|
||||
panel: panel.clone(),
|
||||
},
|
||||
{
|
||||
let title = title.clone();
|
||||
move |_, _, _, cx| {
|
||||
cx.new(|_| DragPreview {
|
||||
title: title.clone(),
|
||||
})
|
||||
}
|
||||
},
|
||||
)
|
||||
.into_any_element()
|
||||
}
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -220,39 +220,36 @@ impl RenderOnce for Resizable {
|
||||
.map(|ix| state.read(cx).pane_size(ix, pane_count))
|
||||
.collect();
|
||||
|
||||
let mut group = div()
|
||||
div()
|
||||
.flex()
|
||||
.overflow_hidden()
|
||||
.when(axis == Axis::Vertical, |group| group.flex_col())
|
||||
.when(axis == Axis::Horizontal, |group| group.flex_row())
|
||||
.refine_style(&self.style);
|
||||
|
||||
for (ix, pane) in self.panes.into_iter().enumerate() {
|
||||
let remainder = ix + 1 == pane_count;
|
||||
let content = pane.content;
|
||||
let mut pane_element = if remainder {
|
||||
div()
|
||||
.flex_1()
|
||||
.refine_style(&self.style)
|
||||
.children(self.panes.into_iter().enumerate().flat_map(|(ix, pane)| {
|
||||
let remainder = ix + 1 == pane_count;
|
||||
let pane_element = div()
|
||||
.overflow_hidden()
|
||||
.when(axis == Axis::Vertical, |p| p.min_h(pane.min))
|
||||
.when(axis == Axis::Horizontal, |p| p.min_w(pane.min))
|
||||
} else {
|
||||
div()
|
||||
.flex_none()
|
||||
.overflow_hidden()
|
||||
.when(axis == Axis::Vertical, |p| p.h(sizes[ix]).w_full())
|
||||
.when(axis == Axis::Horizontal, |p| p.w(sizes[ix]).h_full())
|
||||
};
|
||||
.when(remainder, |pane_element| {
|
||||
pane_element
|
||||
.flex_1()
|
||||
.when(axis == Axis::Vertical, |p| p.min_h(pane.min))
|
||||
.when(axis == Axis::Horizontal, |p| p.min_w(pane.min))
|
||||
})
|
||||
.when(!remainder, |pane_element| {
|
||||
pane_element
|
||||
.flex_none()
|
||||
.when(axis == Axis::Vertical, |p| p.h(sizes[ix]).w_full())
|
||||
.when(axis == Axis::Horizontal, |p| p.w(sizes[ix]).h_full())
|
||||
})
|
||||
.when_some(debug_selector.clone(), |pane_element, selector| {
|
||||
let prefix = selector();
|
||||
pane_element.debug_selector(move || format!("{prefix}-{ix}"))
|
||||
})
|
||||
.child(pane.content)
|
||||
.into_any_element();
|
||||
|
||||
if let Some(selector) = &debug_selector {
|
||||
let prefix = selector();
|
||||
pane_element = pane_element.debug_selector(move || format!("{prefix}-{ix}"));
|
||||
}
|
||||
|
||||
group = group.child(pane_element.child(content));
|
||||
|
||||
if !remainder {
|
||||
let divider =
|
||||
let divider = (!remainder).then(|| {
|
||||
ResizeHandle::new(SharedString::from(format!("{}-divider-{ix}", self.id)))
|
||||
.axis(axis)
|
||||
.on_resize({
|
||||
@@ -268,32 +265,30 @@ impl RenderOnce for Resizable {
|
||||
move |_, cx| {
|
||||
state.update(cx, |state, cx| state.reset_pane(ix, mins.len(), cx));
|
||||
}
|
||||
});
|
||||
})
|
||||
.into_any_element()
|
||||
});
|
||||
|
||||
group = group.child(divider);
|
||||
}
|
||||
}
|
||||
|
||||
if pane_count > 0 {
|
||||
group = group.child(
|
||||
canvas(
|
||||
{
|
||||
let state = state.clone();
|
||||
move |bounds: Bounds<Pixels>, _, cx: &mut App| {
|
||||
let extent = match axis {
|
||||
Axis::Vertical => bounds.size.height,
|
||||
Axis::Horizontal => bounds.size.width,
|
||||
};
|
||||
state.update(cx, |state, cx| state.set_measured(extent, cx));
|
||||
}
|
||||
},
|
||||
|_, _, _, _| {},
|
||||
std::iter::once(pane_element).chain(divider)
|
||||
}))
|
||||
.when(pane_count > 0, |group| {
|
||||
group.child(
|
||||
canvas(
|
||||
{
|
||||
let state = state.clone();
|
||||
move |bounds: Bounds<Pixels>, _, cx: &mut App| {
|
||||
let extent = match axis {
|
||||
Axis::Vertical => bounds.size.height,
|
||||
Axis::Horizontal => bounds.size.width,
|
||||
};
|
||||
state.update(cx, |state, cx| state.set_measured(extent, cx));
|
||||
}
|
||||
},
|
||||
|_, _, _, _| {},
|
||||
)
|
||||
.absolute()
|
||||
.inset_0(),
|
||||
)
|
||||
.absolute()
|
||||
.inset_0(),
|
||||
);
|
||||
}
|
||||
|
||||
group
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user