Skip to main content

scribl_widget/
shadow.rs

1use druid::widget::prelude::*;
2use druid::Insets;
3
4/// A widget that just draws a rectangular shadow.
5#[derive(Debug)]
6pub struct Shadow;
7
8impl<T> Widget<T> for Shadow {
9    fn event(&mut self, _: &mut EventCtx, _: &Event, _: &mut T, _: &Env) {}
10    fn lifecycle(&mut self, _: &mut LifeCycleCtx, _: &LifeCycle, _: &T, _: &Env) {}
11    fn update(&mut self, _: &mut UpdateCtx, _: &T, _: &T, _: &Env) {}
12
13    fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints, _: &T, env: &Env) -> Size {
14        let radius = env.get(crate::DROP_SHADOW_RADIUS);
15        ctx.set_paint_insets(Insets::uniform(radius));
16        bc.max()
17    }
18
19    fn paint(&mut self, ctx: &mut PaintCtx, _: &T, env: &Env) {
20        let radius = env.get(crate::DROP_SHADOW_RADIUS);
21        let color = env.get(crate::DROP_SHADOW_COLOR);
22        let rect = ctx.size().to_rect();
23        ctx.blurred_rect(rect, radius, &color);
24    }
25}