Update libcosmic

This commit is contained in:
Ian Douglas Scott 2024-02-06 13:32:29 -08:00
parent 6e9119a988
commit 015f61922b
10 changed files with 394 additions and 418 deletions

View file

@ -26,14 +26,14 @@ pub struct ImageBg<'a, Msg> {
_msg: PhantomData<Msg>,
}
impl<'a, Msg> Widget<Msg, cosmic::Renderer> for ImageBg<'a, Msg> {
impl<'a, Msg> Widget<Msg, cosmic::Theme, cosmic::Renderer> for ImageBg<'a, Msg> {
delegate::delegate! {
to self.content.as_widget() {
fn tag(&self) -> tree::Tag;
fn state(&self) -> tree::State;
fn children(&self) -> Vec<Tree>;
fn width(&self) -> Length;
fn height(&self) -> Length;
fn size(&self) -> Size<Length>;
fn size_hint(&self) -> Size<Length>;
fn layout(
&self,
tree: &mut Tree,
@ -75,7 +75,7 @@ impl<'a, Msg> Widget<Msg, cosmic::Renderer> for ImageBg<'a, Msg> {
tree: &'b mut Tree,
layout: Layout<'_>,
renderer: &cosmic::Renderer,
) -> Option<overlay::Element<'b, Msg, cosmic::Renderer>>;
) -> Option<overlay::Element<'b, Msg, cosmic::Theme, cosmic::Renderer>>;
}
}
@ -123,6 +123,7 @@ impl<'a, Msg> Widget<Msg, cosmic::Renderer> for ImageBg<'a, Msg> {
//});
self.content
.as_widget()
.draw(state, renderer, theme, style, layout, cursor, viewport)
}
}

View file

@ -5,7 +5,7 @@ use cosmic::iced::{
Clipboard, Layout, Shell, Widget,
},
event::{self, Event},
Length, Rectangle,
Length, Rectangle, Size,
};
use std::marker::PhantomData;
@ -36,7 +36,7 @@ pub struct LayoutWrapper<'a, Msg> {
_msg: PhantomData<Msg>,
}
impl<'a, Msg> Widget<Msg, cosmic::Renderer> for LayoutWrapper<'a, Msg> {
impl<'a, Msg> Widget<Msg, cosmic::Theme, cosmic::Renderer> for LayoutWrapper<'a, Msg> {
fn layout(
&self,
tree: &mut Tree,
@ -52,8 +52,8 @@ impl<'a, Msg> Widget<Msg, cosmic::Renderer> for LayoutWrapper<'a, Msg> {
fn tag(&self) -> tree::Tag;
fn state(&self) -> tree::State;
fn children(&self) -> Vec<Tree>;
fn width(&self) -> Length;
fn height(&self) -> Length;
fn size(&self) -> Size<Length>;
fn size_hint(&self) -> Size<Length>;
fn operate(
&self,
tree: &mut Tree,
@ -100,7 +100,7 @@ impl<'a, Msg> Widget<Msg, cosmic::Renderer> for LayoutWrapper<'a, Msg> {
tree: &'b mut Tree,
layout: Layout<'_>,
renderer: &cosmic::Renderer,
) -> Option<overlay::Element<'b, Msg, cosmic::Renderer>>;
) -> Option<overlay::Element<'b, Msg, cosmic::Theme, cosmic::Renderer>>;
fn set_id(&mut self, id: Id);
}
}

View file

@ -5,7 +5,7 @@ use cosmic::iced::{
Clipboard, Layout, Shell, Widget,
},
event::{self, Event},
Length, Rectangle,
Length, Rectangle, Size,
};
use std::marker::PhantomData;
@ -27,14 +27,14 @@ pub struct MouseInteractionWrapper<'a, Msg> {
_msg: PhantomData<Msg>,
}
impl<'a, Msg> Widget<Msg, cosmic::Renderer> for MouseInteractionWrapper<'a, Msg> {
impl<'a, Msg> Widget<Msg, cosmic::Theme, cosmic::Renderer> for MouseInteractionWrapper<'a, Msg> {
delegate::delegate! {
to self.content.as_widget() {
fn tag(&self) -> tree::Tag;
fn state(&self) -> tree::State;
fn children(&self) -> Vec<Tree>;
fn width(&self) -> Length;
fn height(&self) -> Length;
fn size(&self) -> Size<Length>;
fn size_hint(&self) -> Size<Length>;
fn layout(
&self,
tree: &mut Tree,
@ -79,7 +79,7 @@ impl<'a, Msg> Widget<Msg, cosmic::Renderer> for MouseInteractionWrapper<'a, Msg>
tree: &'b mut Tree,
layout: Layout<'_>,
renderer: &cosmic::Renderer,
) -> Option<overlay::Element<'b, Msg, cosmic::Renderer>>;
) -> Option<overlay::Element<'b, Msg, cosmic::Theme, cosmic::Renderer>>;
fn set_id(&mut self, id: Id);
}
}

View file

@ -54,14 +54,13 @@ pub struct Toplevels<'a, Msg> {
_msg: PhantomData<Msg>,
}
impl<'a, Msg> Widget<Msg, cosmic::Renderer> for Toplevels<'a, Msg> {
fn width(&self) -> Length {
Length::Fill
}
fn height(&self) -> Length {
// TODO Make depend on orientation or drop that option
Length::Shrink
impl<'a, Msg> Widget<Msg, cosmic::Theme, cosmic::Renderer> for Toplevels<'a, Msg> {
fn size(&self) -> Size<Length> {
Size {
width: Length::Fill,
// TODO Make depend on orientation or drop that option
height: Length::Shrink,
}
}
fn layout(
@ -81,14 +80,13 @@ impl<'a, Msg> Widget<Msg, cosmic::Renderer> for Toplevels<'a, Msg> {
.zip(tree.children.iter_mut())
.map(|(child, tree)| {
let child_limits = layout::Limits::new(Size::ZERO, limits.max());
let mut layout = child.layout(tree, renderer, &child_limits);
let mut layout = child.as_widget().layout(tree, renderer, &child_limits);
self.axis.main(layout.size())
})
.collect::<Vec<_>>();
let requested_main_total: f32 = requested_mains.iter().sum::<f32>() + total_spacing as f32;
let scale_factor = (self.axis.main(limits.max()) / requested_main_total).min(1.0);
dbg!(scale_factor);
let max_cross = self.axis.cross(limits.max());
@ -112,11 +110,11 @@ impl<'a, Msg> Widget<Msg, cosmic::Renderer> for Toplevels<'a, Msg> {
let (max_width, max_height) = self.axis.pack(max_main, max_cross);
let child_limits =
layout::Limits::new(Size::ZERO, Size::new(max_width, max_height));
let mut layout = child.layout(tree, renderer, &child_limits);
let mut layout = child.as_widget().layout(tree, renderer, &child_limits);
// Center on cross axis
let cross = ((max_cross - self.axis.cross(layout.size())) / 2.).max(0.);
let (x, y) = self.axis.pack(total_main, cross);
layout.move_to(Point::new(x, y));
layout = layout.move_to(Point::new(x, y));
total_main += self.axis.main(layout.size());
layout
})

View file

@ -60,13 +60,12 @@ pub struct WorkspaceBar<'a, Msg> {
_msg: PhantomData<Msg>,
}
impl<'a, Msg> Widget<Msg, cosmic::Renderer> for WorkspaceBar<'a, Msg> {
fn width(&self) -> Length {
Length::Fill
}
fn height(&self) -> Length {
Length::Fill
impl<'a, Msg> Widget<Msg, cosmic::Theme, cosmic::Renderer> for WorkspaceBar<'a, Msg> {
fn size(&self) -> Size<Length> {
Size {
width: Length::Fill,
height: Length::Fill,
}
}
fn layout(
@ -103,9 +102,9 @@ impl<'a, Msg> Widget<Msg, cosmic::Renderer> for WorkspaceBar<'a, Msg> {
let (max_width, max_height) = self.axis.pack(max_main, max_cross);
let child_limits =
layout::Limits::new(Size::ZERO, Size::new(max_width, max_height));
let mut layout = child.layout(tree, renderer, &child_limits);
let mut layout = child.as_widget().layout(tree, renderer, &child_limits);
let (x, y) = self.axis.pack(total_main, 0.0);
layout.move_to(Point::new(x, y));
layout = layout.move_to(Point::new(x, y));
total_main += self.axis.main(layout.size());
layout
})

View file

@ -62,17 +62,16 @@ pub struct WorkspaceItem<'a, Msg> {
_msg: PhantomData<Msg>,
}
impl<'a, Msg> Widget<Msg, cosmic::Renderer> for WorkspaceItem<'a, Msg> {
fn width(&self) -> Length {
//Length::Fill
// XXX doesn't work when used in standard `row` widget
// But fixes allocation of `dnd_source` wrapping this, within `Workspaces` row
Length::Shrink
}
fn height(&self) -> Length {
// TODO Make depend on orientation or drop that option
Length::Shrink
impl<'a, Msg> Widget<Msg, cosmic::Theme, cosmic::Renderer> for WorkspaceItem<'a, Msg> {
fn size(&self) -> Size<Length> {
Size {
// width: Length::Fill
// XXX doesn't work when used in standard `row` widget
// But fixes allocation of `dnd_source` wrapping this, within `Workspaces` row
width: Length::Shrink,
// TODO Make depend on orientation or drop that option
height: Length::Shrink,
}
}
fn layout(
@ -88,7 +87,9 @@ impl<'a, Msg> Widget<Msg, cosmic::Renderer> for WorkspaceItem<'a, Msg> {
// Get layout of main widget, to set overall cross axis size
let (max_width, max_height) = self.axis.pack(max_main, max_cross);
let child_limits = layout::Limits::new(Size::ZERO, Size::new(max_width, max_height));
let layout = self.children[1].layout(tree, renderer, &child_limits);
let layout = self.children[1]
.as_widget()
.layout(tree, renderer, &child_limits);
let max_cross = self.axis.cross(layout.size());
@ -103,11 +104,11 @@ impl<'a, Msg> Widget<Msg, cosmic::Renderer> for WorkspaceItem<'a, Msg> {
let (max_width, max_height) = self.axis.pack(max_main, max_cross);
let child_limits =
layout::Limits::new(Size::ZERO, Size::new(max_width, max_height));
let mut layout = child.layout(tree, renderer, &child_limits);
let mut layout = child.as_widget().layout(tree, renderer, &child_limits);
// Center on cross axis
let cross = ((max_cross - self.axis.cross(layout.size())) / 2.).max(0.);
let (x, y) = self.axis.pack(total_main, cross);
layout.move_to(Point::new(x, y));
layout = layout.move_to(Point::new(x, y));
total_main += self.axis.main(layout.size());
layout
})