Add a new Hooks element to invoke a callback before layout

This is useful to cap the width of sidebars when dragging the
resize handles beyond the maximum bounds of the sidebar.
This commit is contained in:
Antonio Scandurra
2021-09-03 12:18:31 +02:00
parent a0dd41cdf6
commit 776f7dd5a9
3 changed files with 93 additions and 3 deletions
+12 -3
View File
@@ -112,12 +112,21 @@ impl Sidebar {
if matches!(self.side, Side::Right) {
container.add_child(self.render_resize_handle(settings, cx));
}
let width = self.width.clone();
container.add_child(
Flexible::new(
1.,
ConstrainedBox::new(ChildView::new(active_item.id()).boxed())
.with_max_width(*self.width.borrow())
.boxed(),
Hooks::new(
ConstrainedBox::new(ChildView::new(active_item.id()).boxed())
.with_max_width(*self.width.borrow())
.boxed(),
)
.on_before_layout(move |constraint, _| {
let mut width = width.borrow_mut();
*width = width.min(constraint.max.x());
})
.boxed(),
)
.boxed(),
);