From 997cc9586f90557c2faaddae5d6a16a353340eda Mon Sep 17 00:00:00 2001 From: Jonathan Johnson Date: Sun, 12 May 2024 06:57:41 -0700 Subject: [PATCH] Simplifying drop shadow Also making example regeneration automatic in CI for the guide --- .github/workflows/docs.yml | 4 ++++ guide/guide-examples/src/lib.rs | 2 +- src/widgets/container.rs | 10 ++++------ src/widgets/layers.rs | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 2d340b3..2508e54 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -48,6 +48,10 @@ jobs: run: | cargo install mdbook-variables + - name: Regenerate Example Images + run: | + CAPTURE=1 cargo test -p guide-examples --examples + - name: Build Guide run: | ./mdbook build guide diff --git a/guide/guide-examples/src/lib.rs b/guide/guide-examples/src/lib.rs index 4853fbf..af13229 100644 --- a/guide/guide-examples/src/lib.rs +++ b/guide/guide-examples/src/lib.rs @@ -72,7 +72,7 @@ impl BookExample { name, recorder: interface .contain() - .shadow(ContainerShadow::drop(Px::new(16), Px::new(32))) + .shadow(ContainerShadow::drop(Px::new(16))) .width(Px::new(750)) .build_recorder() .with_alpha() diff --git a/src/widgets/container.rs b/src/widgets/container.rs index bba4236..f8cc5c4 100644 --- a/src/widgets/container.rs +++ b/src/widgets/container.rs @@ -704,16 +704,14 @@ impl ContainerShadow { } } - /// Returns a drop shadow placed `distance` below with a combined - /// blur/spread radius of `blur`. - pub fn drop(distance: Unit, blur: Unit) -> Self + /// Returns a drop shadow placed `distance` below. + pub fn drop(distance: Unit) -> Self where Unit: Zero + Div + Default + Copy, { - let half_blur = blur / 2; Self::new(Point::new(Unit::ZERO, distance)) - .blur_radius(half_blur) - .spread(half_blur) + .blur_radius(distance) + .spread(distance / 2) } /// Sets the shadow color and returns self. diff --git a/src/widgets/layers.rs b/src/widgets/layers.rs index 55d228c..3e809ee 100644 --- a/src/widgets/layers.rs +++ b/src/widgets/layers.rs @@ -870,7 +870,7 @@ impl WrapperWidget for Tooltipped { .clone() .contain() .background_color(background_color) - .shadow(ContainerShadow::drop(Lp::mm(1), Lp::mm(2))), + .shadow(ContainerShadow::drop(Lp::mm(1))), ) .hide_on_unhover() .near(my_id, data.direction)