egui/epaint/src/shadow.rs
Emil Ernerfeldt 778bcc1ef7
Style tweaks (#450)
* Tweak style

More compact, less round, less noisy

* Button text is now same size as body text
* The rounder corners are now less rounded
* Collapsing headers no longer have a frame around them
* Combo-boxes looks better when opened
* Slightly more muted colors
* Remove extra line spacing after `\n` (i.e. between paragraphs)

* Thinner scrollbars

* Tweak light mode

* Tweak shadows

* Fix broken doc link

* Add style tweak to CHANGELOG
2021-06-12 15:53:56 +02:00

70 lines
1.9 KiB
Rust

use super::*;
/// The color and fuzziness of a fuzzy shape.
/// Can be used for a rectangular shadow with a soft penumbra.
#[derive(Clone, Copy, Debug, Default, PartialEq)]
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
pub struct Shadow {
/// The shadow extends this much outside the rect.
/// The size of the fuzzy penumbra.
pub extrusion: f32,
/// Color of the opaque center of the shadow.
pub color: Color32,
}
impl Shadow {
/// Tooltips, menus, ...
pub fn small_dark() -> Self {
Self {
extrusion: 16.0,
color: Color32::from_black_alpha(96),
}
}
/// Tooltips, menus, ...
pub fn small_light() -> Self {
Self {
extrusion: 16.0,
color: Color32::from_black_alpha(32),
}
}
/// Subtle and nice on dark backgrounds
pub fn big_dark() -> Self {
Self {
extrusion: 32.0,
color: Color32::from_black_alpha(96),
}
}
/// Subtle and nice on white backgrounds
pub fn big_light() -> Self {
Self {
extrusion: 32.0,
color: Color32::from_black_alpha(40),
}
}
pub fn tessellate(&self, rect: emath::Rect, corner_radius: f32) -> Mesh {
// tessellator.clip_rect = clip_rect; // TODO: culling
let Self { extrusion, color } = *self;
use crate::tessellator::*;
let rect = PaintRect {
rect: rect.expand(0.5 * extrusion),
corner_radius: corner_radius + 0.5 * extrusion,
fill: color,
stroke: Default::default(),
};
let mut tessellator = Tessellator::from_options(TessellationOptions {
aa_size: extrusion,
anti_alias: true,
..Default::default()
});
let mut mesh = Mesh::default();
tessellator.tessellate_rect(&rect, &mut mesh);
mesh
}
}