feat: apply declarative render rule across components

This commit is contained in:
2026-11-10 08:04:24 +07:00
parent fbc4f24d16
commit 44abaf47a9
12 changed files with 545 additions and 561 deletions
+47 -52
View File
@@ -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
})
}
}