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:
@@ -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(),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user