Merge branch 'master' into feature/test-recorder
This commit is contained in:
commit
98d8f466bb
98 changed files with 643 additions and 204 deletions
|
|
@ -137,16 +137,24 @@ where
|
|||
//
|
||||
// We use the maximum cross length obtained in the first pass as the maximum
|
||||
// cross limit.
|
||||
//
|
||||
// We can defer the layout of any elements that have a fixed size in the main axis,
|
||||
// allowing them to use the cross calculations of the next pass.
|
||||
if cross_compress && some_fill_cross {
|
||||
for (i, (child, tree)) in items.iter().zip(trees.iter_mut()).enumerate()
|
||||
{
|
||||
let (fill_main_factor, fill_cross_factor) = {
|
||||
let (main_size, cross_size) = {
|
||||
let size = child.as_widget().size();
|
||||
|
||||
axis.pack(size.width.fill_factor(), size.height.fill_factor())
|
||||
axis.pack(size.width, size.height)
|
||||
};
|
||||
|
||||
if fill_main_factor == 0 && fill_cross_factor != 0 {
|
||||
if main_size.fill_factor() == 0 && cross_size.fill_factor() != 0 {
|
||||
if let Length::Fixed(main) = main_size {
|
||||
available -= main;
|
||||
continue;
|
||||
}
|
||||
|
||||
let (max_width, max_height) = axis.pack(available, cross);
|
||||
|
||||
let child_limits =
|
||||
|
|
@ -176,9 +184,9 @@ where
|
|||
};
|
||||
|
||||
// THIRD PASS
|
||||
// We only have the elements that are fluid in the main axis left.
|
||||
// We lay out the elements that are fluid in the main axis.
|
||||
// We use the remaining space to evenly allocate space based on fill factors.
|
||||
for (i, (child, tree)) in items.iter().zip(trees).enumerate() {
|
||||
for (i, (child, tree)) in items.iter().zip(trees.iter_mut()).enumerate() {
|
||||
let (fill_main_factor, fill_cross_factor) = {
|
||||
let size = child.as_widget().size();
|
||||
|
||||
|
|
@ -224,10 +232,43 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
// FOURTH PASS (conditional)
|
||||
// We lay out any elements that were deferred in the second pass.
|
||||
// These are elements that must be compressed in their cross axis and have
|
||||
// a fixed length in the main axis.
|
||||
if cross_compress && some_fill_cross {
|
||||
for (i, (child, tree)) in items.iter().zip(trees).enumerate() {
|
||||
let (main_size, cross_size) = {
|
||||
let size = child.as_widget().size();
|
||||
|
||||
axis.pack(size.width, size.height)
|
||||
};
|
||||
|
||||
if cross_size.fill_factor() != 0 {
|
||||
let Length::Fixed(main) = main_size else {
|
||||
continue;
|
||||
};
|
||||
|
||||
let (max_width, max_height) = axis.pack(main, cross);
|
||||
|
||||
let child_limits =
|
||||
Limits::new(Size::ZERO, Size::new(max_width, max_height));
|
||||
|
||||
let layout =
|
||||
child.as_widget().layout(tree, renderer, &child_limits);
|
||||
let size = layout.size();
|
||||
|
||||
cross = cross.max(axis.cross(size));
|
||||
|
||||
nodes[i] = layout;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let pad = axis.pack(padding.left, padding.top);
|
||||
let mut main = pad.0;
|
||||
|
||||
// FOURTH PASS
|
||||
// FIFTH PASS
|
||||
// We align all the laid out nodes in the cross axis, if needed.
|
||||
for (i, node) in nodes.iter_mut().enumerate() {
|
||||
if i > 0 {
|
||||
|
|
|
|||
|
|
@ -107,3 +107,13 @@ where
|
|||
write!(f, "Point {{ x: {}, y: {} }}", self.x, self.y)
|
||||
}
|
||||
}
|
||||
|
||||
impl Point<f32> {
|
||||
/// Snaps the [`Point`] to __unsigned__ integer coordinates.
|
||||
pub fn snap(self) -> Point<u32> {
|
||||
Point {
|
||||
x: self.x.round() as u32,
|
||||
y: self.y.round() as u32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -244,16 +244,19 @@ impl Rectangle<f32> {
|
|||
|
||||
/// Snaps the [`Rectangle`] to __unsigned__ integer coordinates.
|
||||
pub fn snap(self) -> Option<Rectangle<u32>> {
|
||||
let width = self.width as u32;
|
||||
let height = self.height as u32;
|
||||
let top_left = self.position().snap();
|
||||
let bottom_right = (self.position() + Vector::from(self.size())).snap();
|
||||
|
||||
let width = bottom_right.x.checked_sub(top_left.x)?;
|
||||
let height = bottom_right.y.checked_sub(top_left.y)?;
|
||||
|
||||
if width < 1 || height < 1 {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(Rectangle {
|
||||
x: self.x as u32,
|
||||
y: self.y as u32,
|
||||
x: top_left.x,
|
||||
y: top_left.y,
|
||||
width,
|
||||
height,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ impl<'a, Message> Shell<'a, Message> {
|
|||
}
|
||||
|
||||
/// Returns true if the [`Shell`] contains no published messages
|
||||
#[must_use]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.messages.is_empty()
|
||||
}
|
||||
|
|
@ -50,11 +51,13 @@ impl<'a, Message> Shell<'a, Message> {
|
|||
}
|
||||
|
||||
/// Returns the current [`event::Status`] of the [`Shell`].
|
||||
#[must_use]
|
||||
pub fn event_status(&self) -> event::Status {
|
||||
self.event_status
|
||||
}
|
||||
|
||||
/// Returns whether the current event has been captured.
|
||||
#[must_use]
|
||||
pub fn is_event_captured(&self) -> bool {
|
||||
self.event_status == event::Status::Captured
|
||||
}
|
||||
|
|
@ -73,6 +76,7 @@ impl<'a, Message> Shell<'a, Message> {
|
|||
}
|
||||
|
||||
/// Returns the request a redraw should happen, if any.
|
||||
#[must_use]
|
||||
pub fn redraw_request(&self) -> window::RedrawRequest {
|
||||
self.redraw_request
|
||||
}
|
||||
|
|
@ -101,16 +105,19 @@ impl<'a, Message> Shell<'a, Message> {
|
|||
}
|
||||
|
||||
/// Returns the current [`InputMethod`] strategy.
|
||||
#[must_use]
|
||||
pub fn input_method(&self) -> &InputMethod {
|
||||
&self.input_method
|
||||
}
|
||||
|
||||
/// Returns the current [`InputMethod`] strategy.
|
||||
#[must_use]
|
||||
pub fn input_method_mut(&mut self) -> &mut InputMethod {
|
||||
&mut self.input_method
|
||||
}
|
||||
|
||||
/// Returns whether the current layout is invalid or not.
|
||||
#[must_use]
|
||||
pub fn is_layout_invalid(&self) -> bool {
|
||||
self.is_layout_invalid
|
||||
}
|
||||
|
|
@ -134,6 +141,7 @@ impl<'a, Message> Shell<'a, Message> {
|
|||
|
||||
/// Returns whether the widgets of the current application have been
|
||||
/// invalidated.
|
||||
#[must_use]
|
||||
pub fn are_widgets_invalid(&self) -> bool {
|
||||
self.are_widgets_invalid
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::{Point, Size};
|
||||
|
||||
/// The position of a window in a given screen.
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum Position {
|
||||
/// The platform-specific default position for a new window.
|
||||
Default,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue