Apply Resize's max size to available size too
I'm not sure if the input max size and the output max size should be separate, and I'm not sure whether the min size should also have an effect on the input. For now, this works well enough, but I may need to adjust it in the future as I stumble across new edge cases. This change was made because I was using Resize as a way to set the size of widgets containing text that were rendered inside Predraw widgets. After this change, setting a max_width but no max_height has the desired effect of making the inner widgets perform word wrapping. The resulting Predrawn is then as high as it needs to be to contain the wrapped text.
This commit is contained in:
parent
59710c8162
commit
57788a9dd9
1 changed files with 16 additions and 0 deletions
|
|
@ -42,6 +42,20 @@ impl<I> Resize<I> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn presize(
|
||||||
|
&self,
|
||||||
|
mut width: Option<u16>,
|
||||||
|
mut height: Option<u16>,
|
||||||
|
) -> (Option<u16>, Option<u16>) {
|
||||||
|
if let Some(mw) = self.max_width {
|
||||||
|
width = Some(width.unwrap_or(mw).min(mw));
|
||||||
|
}
|
||||||
|
if let Some(mh) = self.max_height {
|
||||||
|
height = Some(height.unwrap_or(mh).max(mh));
|
||||||
|
}
|
||||||
|
(width, height)
|
||||||
|
}
|
||||||
|
|
||||||
fn resize(&self, size: Size) -> Size {
|
fn resize(&self, size: Size) -> Size {
|
||||||
let mut width = size.width;
|
let mut width = size.width;
|
||||||
let mut height = size.height;
|
let mut height = size.height;
|
||||||
|
|
@ -74,6 +88,7 @@ where
|
||||||
max_width: Option<u16>,
|
max_width: Option<u16>,
|
||||||
max_height: Option<u16>,
|
max_height: Option<u16>,
|
||||||
) -> Result<Size, E> {
|
) -> Result<Size, E> {
|
||||||
|
let (max_width, max_height) = self.presize(max_width, max_height);
|
||||||
let size = self.inner.size(widthdb, max_width, max_height)?;
|
let size = self.inner.size(widthdb, max_width, max_height)?;
|
||||||
Ok(self.resize(size))
|
Ok(self.resize(size))
|
||||||
}
|
}
|
||||||
|
|
@ -94,6 +109,7 @@ where
|
||||||
max_width: Option<u16>,
|
max_width: Option<u16>,
|
||||||
max_height: Option<u16>,
|
max_height: Option<u16>,
|
||||||
) -> Result<Size, E> {
|
) -> Result<Size, E> {
|
||||||
|
let (max_width, max_height) = self.presize(max_width, max_height);
|
||||||
let size = self.inner.size(widthdb, max_width, max_height).await?;
|
let size = self.inner.size(widthdb, max_width, max_height).await?;
|
||||||
Ok(self.resize(size))
|
Ok(self.resize(size))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue