2020-12-29 00:13:14 +00:00
|
|
|
use super::*;
|
|
|
|
|
2021-01-19 23:30:07 +00:00
|
|
|
/// The color and fuzziness of a fuzzy shape.
|
|
|
|
/// Can be used for a rectangular shadow with a soft penumbra.
|
2020-12-29 00:13:14 +00:00
|
|
|
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
2021-09-29 06:45:13 +00:00
|
|
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
2020-12-29 00:13:14 +00:00
|
|
|
pub struct Shadow {
|
2021-01-19 23:30:07 +00:00
|
|
|
/// The shadow extends this much outside the rect.
|
|
|
|
/// The size of the fuzzy penumbra.
|
2020-12-29 00:13:14 +00:00
|
|
|
pub extrusion: f32,
|
2021-01-19 23:30:07 +00:00
|
|
|
|
|
|
|
/// Color of the opaque center of the shadow.
|
2021-01-02 16:02:18 +00:00
|
|
|
pub color: Color32,
|
2020-12-29 00:13:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Shadow {
|
2021-10-13 09:52:34 +00:00
|
|
|
/// Tooltips, menus, …
|
2021-06-12 13:53:56 +00:00
|
|
|
pub fn small_dark() -> Self {
|
2020-12-29 00:13:14 +00:00
|
|
|
Self {
|
2021-06-12 13:53:56 +00:00
|
|
|
extrusion: 16.0,
|
|
|
|
color: Color32::from_black_alpha(96),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-13 09:52:34 +00:00
|
|
|
/// Tooltips, menus, …
|
2021-06-12 13:53:56 +00:00
|
|
|
pub fn small_light() -> Self {
|
|
|
|
Self {
|
|
|
|
extrusion: 16.0,
|
|
|
|
color: Color32::from_black_alpha(32),
|
2020-12-29 00:13:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-03 00:08:23 +00:00
|
|
|
/// Subtle and nice on dark backgrounds
|
|
|
|
pub fn big_dark() -> Self {
|
2020-12-29 00:13:14 +00:00
|
|
|
Self {
|
|
|
|
extrusion: 32.0,
|
2021-01-03 17:03:11 +00:00
|
|
|
color: Color32::from_black_alpha(96),
|
2020-12-29 00:13:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-03 00:08:23 +00:00
|
|
|
/// Subtle and nice on white backgrounds
|
|
|
|
pub fn big_light() -> Self {
|
|
|
|
Self {
|
|
|
|
extrusion: 32.0,
|
|
|
|
color: Color32::from_black_alpha(40),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-05 17:13:46 +00:00
|
|
|
pub fn tessellate(&self, rect: emath::Rect, rounding: impl Into<Rounding>) -> Mesh {
|
2022-05-21 14:53:25 +00:00
|
|
|
// tessellator.clip_rect = clip_rect; // TODO(emilk): culling
|
2020-12-29 00:13:14 +00:00
|
|
|
|
|
|
|
let Self { extrusion, color } = *self;
|
|
|
|
|
2022-02-05 17:13:46 +00:00
|
|
|
let rounding: Rounding = rounding.into();
|
2022-02-05 16:48:55 +00:00
|
|
|
let half_ext = 0.5 * extrusion;
|
|
|
|
|
2022-02-05 17:13:46 +00:00
|
|
|
let ext_rounding = Rounding {
|
|
|
|
nw: rounding.nw + half_ext,
|
|
|
|
ne: rounding.ne + half_ext,
|
|
|
|
sw: rounding.sw + half_ext,
|
|
|
|
se: rounding.se + half_ext,
|
2022-02-05 16:48:55 +00:00
|
|
|
};
|
|
|
|
|
2021-01-10 14:42:46 +00:00
|
|
|
use crate::tessellator::*;
|
2022-02-05 17:13:46 +00:00
|
|
|
let rect = RectShape::filled(rect.expand(half_ext), ext_rounding, color);
|
2022-03-23 10:41:38 +00:00
|
|
|
let pixels_per_point = 1.0; // doesn't matter here
|
2022-04-03 16:14:27 +00:00
|
|
|
let font_tex_size = [1; 2]; // unused size we are not tessellating text.
|
2022-03-23 10:41:38 +00:00
|
|
|
let mut tessellator = Tessellator::new(
|
|
|
|
pixels_per_point,
|
|
|
|
TessellationOptions {
|
|
|
|
feathering: true,
|
|
|
|
feathering_size_in_pixels: extrusion * pixels_per_point,
|
|
|
|
..Default::default()
|
|
|
|
},
|
2022-04-03 16:14:27 +00:00
|
|
|
font_tex_size,
|
2022-05-10 17:31:19 +00:00
|
|
|
vec![],
|
2022-03-23 10:41:38 +00:00
|
|
|
);
|
2021-01-25 20:23:24 +00:00
|
|
|
let mut mesh = Mesh::default();
|
|
|
|
tessellator.tessellate_rect(&rect, &mut mesh);
|
|
|
|
mesh
|
2020-12-29 00:13:14 +00:00
|
|
|
}
|
|
|
|
}
|