From c4adca76c0a1c6b6d37ce0d7860455793121fccd Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Fri, 15 Dec 2023 13:33:29 -0800 Subject: [PATCH] Use `delegate` crate to simplify things a bit. --- Cargo.lock | 12 ++++++++++++ Cargo.toml | 1 + src/widgets/image_bg.rs | 32 +++++++++++--------------------- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a43d477..c2905ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml index f619293..534c9de 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 diff --git a/src/widgets/image_bg.rs b/src/widgets/image_bg.rs index dafd215..bd235fc 100644 --- a/src/widgets/image_bg.rs +++ b/src/widgets/image_bg.rs @@ -27,28 +27,18 @@ pub struct ImageBg<'a, Msg> { } impl<'a, Msg> Widget 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; + fn width(&self) -> Length; + fn height(&self) -> Length; + } - fn state(&self) -> tree::State { - self.content.as_widget().state() - } - - fn children(&self) -> Vec { - 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(