Implement overlay ordering for Image::float
This commit is contained in:
parent
7f1dcec391
commit
e64c58d032
8 changed files with 416 additions and 143 deletions
|
|
@ -25,8 +25,17 @@ where
|
|||
|
||||
/// Creates a [`Group`] with the given elements.
|
||||
pub fn with_children(
|
||||
children: Vec<overlay::Element<'a, Message, Theme, Renderer>>,
|
||||
mut children: Vec<overlay::Element<'a, Message, Theme, Renderer>>,
|
||||
) -> Self {
|
||||
use std::cmp;
|
||||
|
||||
children.sort_unstable_by(|a, b| {
|
||||
a.as_overlay()
|
||||
.index()
|
||||
.partial_cmp(&b.as_overlay().index())
|
||||
.unwrap_or(cmp::Ordering::Equal)
|
||||
});
|
||||
|
||||
Group { children }
|
||||
}
|
||||
|
||||
|
|
@ -67,7 +76,7 @@ where
|
|||
bounds,
|
||||
self.children
|
||||
.iter_mut()
|
||||
.map(|child| child.layout(renderer, bounds))
|
||||
.map(|child| child.as_overlay_mut().layout(renderer, bounds))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
|
@ -82,7 +91,9 @@ where
|
|||
shell: &mut Shell<'_, Message>,
|
||||
) {
|
||||
for (child, layout) in self.children.iter_mut().zip(layout.children()) {
|
||||
child.update(event, layout, cursor, renderer, clipboard, shell);
|
||||
child
|
||||
.as_overlay_mut()
|
||||
.update(event, layout, cursor, renderer, clipboard, shell);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -95,7 +106,9 @@ where
|
|||
cursor: mouse::Cursor,
|
||||
) {
|
||||
for (child, layout) in self.children.iter().zip(layout.children()) {
|
||||
child.draw(renderer, theme, style, layout, cursor);
|
||||
child
|
||||
.as_overlay()
|
||||
.draw(renderer, theme, style, layout, cursor);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -110,7 +123,9 @@ where
|
|||
.iter()
|
||||
.zip(layout.children())
|
||||
.map(|(child, layout)| {
|
||||
child.mouse_interaction(layout, cursor, viewport, renderer)
|
||||
child
|
||||
.as_overlay()
|
||||
.mouse_interaction(layout, cursor, viewport, renderer)
|
||||
})
|
||||
.max()
|
||||
.unwrap_or_default()
|
||||
|
|
@ -125,7 +140,7 @@ where
|
|||
operation.container(None, layout.bounds(), &mut |operation| {
|
||||
self.children.iter_mut().zip(layout.children()).for_each(
|
||||
|(child, layout)| {
|
||||
child.operate(layout, renderer, operation);
|
||||
child.as_overlay_mut().operate(layout, renderer, operation);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
|
@ -141,7 +156,9 @@ where
|
|||
.iter()
|
||||
.zip(layout.children())
|
||||
.any(|(child, layout)| {
|
||||
child.is_over(layout, renderer, cursor_position)
|
||||
child
|
||||
.as_overlay()
|
||||
.is_over(layout, renderer, cursor_position)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -154,11 +171,20 @@ where
|
|||
.children
|
||||
.iter_mut()
|
||||
.zip(layout.children())
|
||||
.filter_map(|(child, layout)| child.overlay(layout, renderer))
|
||||
.filter_map(|(child, layout)| {
|
||||
child.as_overlay_mut().overlay(layout, renderer)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
(!children.is_empty()).then(|| Group::with_children(children).overlay())
|
||||
}
|
||||
|
||||
fn index(&self) -> f32 {
|
||||
self.children
|
||||
.first()
|
||||
.map(|child| child.as_overlay().index())
|
||||
.unwrap_or(1.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Message, Theme, Renderer> From<Group<'a, Message, Theme, Renderer>>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue