resizable: Fix the bug for parent groups when initializing Panels with sizes Some and None (#356)
Optimization of https://github.com/longbridgeapp/gpui-component/pull/329 The issue with the initial width of the Panel has been optimised to ensure that the left side of a Panel combination like [Some(px(510.)), None] is initially rendered with a width of 510px. --------- Co-authored-by: Jason Lee <huacnlee@gmail.com>
This commit is contained in:
parent
8eff75d357
commit
913775c632
1 changed files with 12 additions and 4 deletions
|
|
@ -351,7 +351,8 @@ impl FluentBuilder for ResizablePanel {}
|
|||
impl Render for ResizablePanel {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
let view = cx.view().clone();
|
||||
|
||||
let total_size = self.group.as_ref().map(|group| group.read(cx).total_size());
|
||||
|
||||
div()
|
||||
.flex()
|
||||
.flex_grow()
|
||||
|
|
@ -366,9 +367,16 @@ impl Render for ResizablePanel {
|
|||
this.when(self.size.is_none(), |this| this.flex_shrink_0())
|
||||
.flex_basis(size)
|
||||
})
|
||||
.when_some(self.size_ratio, |this, size_ratio| {
|
||||
this.flex_basis(relative(size_ratio))
|
||||
})
|
||||
.map(
|
||||
|this| match (self.size_ratio, self.size, total_size) {
|
||||
(Some(size_ratio), _, _) => this.flex_basis(relative(size_ratio)),
|
||||
(None, Some(size), Some(total_size)) => {
|
||||
this.flex_basis(relative(size / total_size))
|
||||
}
|
||||
(None, Some(size), None) => this.flex_basis(size),
|
||||
_ => this,
|
||||
},
|
||||
)
|
||||
.child({
|
||||
canvas(
|
||||
move |bounds, cx| view.update(cx, |r, cx| r.update_size(bounds, cx)),
|
||||
|
|
|
|||
Loading…
Reference in a new issue