mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Remove BoxView::squishable
No-one knew what it was doing.
This commit is contained in:
parent
0a81454e7d
commit
b3fed80939
@ -25,13 +25,6 @@ pub struct BoxView<T: View> {
|
|||||||
/// Constraint on each axis
|
/// Constraint on each axis
|
||||||
size: XY<SizeConstraint>,
|
size: XY<SizeConstraint>,
|
||||||
|
|
||||||
/// `true` if the view can be squished.
|
|
||||||
///
|
|
||||||
/// This means if the required size is less than the computed size,
|
|
||||||
/// consider returning a smaller size.
|
|
||||||
/// For instance, try to return the child's desired size.
|
|
||||||
squishable: bool, // TODO: remove?
|
|
||||||
|
|
||||||
/// Set to `true` whenever we change some settings. Means we should re-layout just in case.
|
/// Set to `true` whenever we change some settings. Means we should re-layout just in case.
|
||||||
invalidated: bool,
|
invalidated: bool,
|
||||||
|
|
||||||
@ -50,7 +43,6 @@ impl<T: View> BoxView<T> {
|
|||||||
) -> Self {
|
) -> Self {
|
||||||
BoxView {
|
BoxView {
|
||||||
size: (width, height).into(),
|
size: (width, height).into(),
|
||||||
squishable: false,
|
|
||||||
invalidated: true,
|
invalidated: true,
|
||||||
view,
|
view,
|
||||||
}
|
}
|
||||||
@ -82,24 +74,6 @@ impl<T: View> BoxView<T> {
|
|||||||
self.invalidate();
|
self.invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets `self` to be squishable.
|
|
||||||
///
|
|
||||||
/// A squishable `BoxView` will take a smaller size than it should when
|
|
||||||
/// the available space is too small. In that case, it will allow the
|
|
||||||
/// child view to contract, if it can.
|
|
||||||
///
|
|
||||||
/// More specifically, if the available space is less than the size we
|
|
||||||
/// would normally ask for, return the child size.
|
|
||||||
pub fn squishable(self) -> Self {
|
|
||||||
self.with(|s| s.set_squishable(true))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Controls the "squishability" of `self`.
|
|
||||||
pub fn set_squishable(&mut self, squishable: bool) {
|
|
||||||
self.squishable = squishable;
|
|
||||||
self.invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Wraps `view` in a new `BoxView` with the given size.
|
/// Wraps `view` in a new `BoxView` with the given size.
|
||||||
pub fn with_fixed_size<S: Into<Vec2>>(size: S, view: T) -> Self {
|
pub fn with_fixed_size<S: Into<Vec2>>(size: S, view: T) -> Self {
|
||||||
let size = size.into();
|
let size = size.into();
|
||||||
@ -228,28 +202,14 @@ impl<T: View> ViewWrapper for BoxView<T> {
|
|||||||
let child_size = self.view.required_size(req);
|
let child_size = self.view.required_size(req);
|
||||||
|
|
||||||
// Some of this request will be granted, but maybe not all.
|
// Some of this request will be granted, but maybe not all.
|
||||||
let result = self
|
self.size
|
||||||
.size
|
.zip_map(child_size.zip(req), SizeConstraint::result)
|
||||||
.zip_map(child_size.zip(req), SizeConstraint::result);
|
|
||||||
|
|
||||||
if self.squishable {
|
|
||||||
// When we're squishable, special behaviour:
|
|
||||||
//
|
|
||||||
|
|
||||||
// We respect the request if we're less or equal.
|
|
||||||
let respect_req = result.zip_map(req, |res, req| res <= req);
|
|
||||||
|
|
||||||
// If we respect the request, keep the result
|
|
||||||
// Otherwise, take the child as squish attempt.
|
|
||||||
respect_req.select_or(result, child_size)
|
|
||||||
} else {
|
|
||||||
result
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wrap_layout(&mut self, size: Vec2) {
|
fn wrap_layout(&mut self, size: Vec2) {
|
||||||
self.invalidated = false;
|
self.invalidated = false;
|
||||||
self.view.layout(size);
|
self.view
|
||||||
|
.layout(self.size.zip_map(size, |c, s| c.result((s, s))));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wrap_needs_relayout(&self) -> bool {
|
fn wrap_needs_relayout(&self) -> bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user