Use aliasable in AxisToplevelLayout to use slice in argument
This makes layouts possible to compose without clones.
This commit is contained in:
parent
f2a2904978
commit
874245bc2e
4 changed files with 29 additions and 6 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -1252,6 +1252,7 @@ dependencies = [
|
|||
name = "cosmic-workspaces"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"aliasable",
|
||||
"anyhow",
|
||||
"calloop 0.14.2",
|
||||
"calloop-wayland-source 0.4.0",
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ i18n-embed-fl = "0.9.0"
|
|||
rust-embed = "8.1.0"
|
||||
rustix = { version = "0.38.30", features = ["fs"] }
|
||||
calloop-wayland-source = "0.4.0"
|
||||
aliasable = "0.1.3"
|
||||
|
||||
[dependencies.i18n-embed]
|
||||
version = "0.15.3"
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use aliasable::vec::AliasableVec;
|
||||
use cosmic::iced::{advanced::layout::flex::Axis, Length, Point, Rectangle, Size};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
|
|
@ -70,7 +71,7 @@ pub trait AxisToplevelLayout {
|
|||
fn layout(
|
||||
&self,
|
||||
max_limit: AxisSize,
|
||||
toplevels: Vec<LayoutToplevel<'_, AxisSize>>,
|
||||
toplevels: &[LayoutToplevel<'_, AxisSize>],
|
||||
) -> impl Iterator<Item = AxisRectangle>;
|
||||
}
|
||||
|
||||
|
|
@ -79,10 +80,10 @@ impl<T: AxisToplevelLayout> ToplevelLayout for T {
|
|||
self.size().pack(self.axis())
|
||||
}
|
||||
|
||||
fn layout(
|
||||
fn layout<'a>(
|
||||
&self,
|
||||
max_limit: Size,
|
||||
toplevels: &[LayoutToplevel<'_>],
|
||||
toplevels: &[LayoutToplevel<'a>],
|
||||
) -> impl Iterator<Item = Rectangle> {
|
||||
let max_limit = AxisSize::unpack(self.axis(), max_limit);
|
||||
let toplevels = toplevels
|
||||
|
|
@ -92,7 +93,27 @@ impl<T: AxisToplevelLayout> ToplevelLayout for T {
|
|||
_phantom_data: PhantomData,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
self.layout(max_limit, toplevels)
|
||||
.map(|rect| rect.pack(self.axis()))
|
||||
let toplevels = AliasableVec::from_unique(toplevels);
|
||||
// Extend lifetime
|
||||
let toplevels_slice =
|
||||
unsafe { std::mem::transmute::<_, &'a [LayoutToplevel<'a, AxisSize>]>(&*toplevels) };
|
||||
let inner = self
|
||||
.layout(max_limit, toplevels_slice)
|
||||
.map(|rect| rect.pack(self.axis()));
|
||||
AxisLayoutIterator { inner, toplevels }
|
||||
}
|
||||
}
|
||||
|
||||
struct AxisLayoutIterator<'a, I: Iterator<Item = Rectangle>> {
|
||||
inner: I,
|
||||
// After `inner` so it is dropped only after that is dropped
|
||||
toplevels: AliasableVec<LayoutToplevel<'a, AxisSize>>,
|
||||
}
|
||||
|
||||
impl<'a, I: Iterator<Item = Rectangle>> Iterator for AxisLayoutIterator<'a, I> {
|
||||
type Item = Rectangle;
|
||||
|
||||
fn next(&mut self) -> Option<Rectangle> {
|
||||
self.inner.next()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ impl AxisToplevelLayout for RowColToplevelLayout {
|
|||
fn layout(
|
||||
&self,
|
||||
max_limit: AxisSize,
|
||||
toplevels: Vec<LayoutToplevel<'_, AxisSize>>,
|
||||
toplevels: &[LayoutToplevel<'_, AxisSize>],
|
||||
) -> impl Iterator<Item = AxisRectangle> {
|
||||
let requested_main_total = self.requested_main_total(&toplevels);
|
||||
let scale_factor = (max_limit.main / requested_main_total).min(1.0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue