Use delegate crate to simplify things a bit.

This commit is contained in:
Ian Douglas Scott 2023-12-15 13:33:29 -08:00
parent 5a69aff778
commit c4adca76c0
3 changed files with 24 additions and 21 deletions

12
Cargo.lock generated
View file

@ -871,6 +871,7 @@ dependencies = [
"clap",
"cosmic-comp-config",
"cosmic-config",
"delegate",
"env_logger",
"futures-channel",
"gbm",
@ -1042,6 +1043,17 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c297a1c74b71ae29df00c3e22dd9534821d60eb9af5a0192823fa2acea70c2a"
[[package]]
name = "delegate"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4801d755ab05b6e25cbbf1afc342993aafa00e572409f9ee21633a19e609d9f"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.41",
]
[[package]]
name = "derivative"
version = "2.2.0"

View file

@ -19,6 +19,7 @@ tokio = "1.23.0"
wayland-protocols = "0.31.0"
zbus = { version = "3.7.0", default-features = false, features = ["tokio"] }
once_cell = "1.18.0"
delegate = "0.11.0"
[profile.dev]
# Not usable at opt-level 0, at least with software renderer

View file

@ -27,28 +27,18 @@ pub struct ImageBg<'a, Msg> {
}
impl<'a, Msg> Widget<Msg, cosmic::Renderer> for ImageBg<'a, Msg> {
fn tag(&self) -> tree::Tag {
self.content.as_widget().tag()
}
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 state(&self) -> tree::State {
self.content.as_widget().state()
}
fn children(&self) -> Vec<Tree> {
self.content.as_widget().children()
}
fn diff(&mut self, tree: &mut Tree) {
self.content.as_widget_mut().diff(tree);
}
fn width(&self) -> Length {
self.content.as_widget().width()
}
fn height(&self) -> Length {
self.content.as_widget().height()
to self.content.as_widget_mut() {
fn diff(&mut self, tree: &mut Tree);
}
}
fn layout(